common/drm-formats: Rename to MetaFormatInfo and simplify API
Every format kind has it's own function to search for a MetaFormatInfo from which contains all the information. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3280>
This commit is contained in:
parent
f4ce16bbd1
commit
6f1edfc776
@ -266,6 +266,7 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
|
|||||||
gboolean result;
|
gboolean result;
|
||||||
int dmabuf_fd = -1;
|
int dmabuf_fd = -1;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
dmabuf_fd = gbm_bo_get_fd (buffer_gbm->bo);
|
dmabuf_fd = gbm_bo_get_fd (buffer_gbm->bo);
|
||||||
if (dmabuf_fd == -1)
|
if (dmabuf_fd == -1)
|
||||||
@ -277,10 +278,10 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
|
|||||||
}
|
}
|
||||||
|
|
||||||
drm_format = gbm_bo_get_format (buffer_gbm->bo);
|
drm_format = gbm_bo_get_format (buffer_gbm->bo);
|
||||||
result = meta_cogl_pixel_format_from_drm_format (drm_format,
|
|
||||||
&cogl_format,
|
format_info = meta_format_info_from_drm_format (drm_format);
|
||||||
NULL);
|
g_assert (format_info);
|
||||||
g_assert (result);
|
cogl_format = format_info->cogl_format;
|
||||||
|
|
||||||
width = gbm_bo_get_width (buffer_gbm->bo);
|
width = gbm_bo_get_width (buffer_gbm->bo);
|
||||||
height = gbm_bo_get_height (buffer_gbm->bo);
|
height = gbm_bo_get_height (buffer_gbm->bo);
|
||||||
|
@ -719,8 +719,7 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
|
|||||||
CoglFramebuffer *dmabuf_fb;
|
CoglFramebuffer *dmabuf_fb;
|
||||||
int dmabuf_fd;
|
int dmabuf_fd;
|
||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
CoglPixelFormat cogl_format;
|
const MetaFormatInfo *format_info;
|
||||||
int ret;
|
|
||||||
|
|
||||||
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu,
|
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferPrimaryGpu,
|
||||||
"copy_shared_framebuffer_primary_gpu()");
|
"copy_shared_framebuffer_primary_gpu()");
|
||||||
@ -746,8 +745,8 @@ copy_shared_framebuffer_primary_gpu (CoglOnscreen *onscre
|
|||||||
g_assert (cogl_framebuffer_get_width (framebuffer) == width);
|
g_assert (cogl_framebuffer_get_width (framebuffer) == width);
|
||||||
g_assert (cogl_framebuffer_get_height (framebuffer) == height);
|
g_assert (cogl_framebuffer_get_height (framebuffer) == height);
|
||||||
|
|
||||||
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
|
format_info = meta_format_info_from_drm_format (drm_format);
|
||||||
g_assert (ret);
|
g_assert (format_info);
|
||||||
|
|
||||||
dmabuf_fd = meta_drm_buffer_dumb_ensure_dmabuf_fd (buffer_dumb, &error);
|
dmabuf_fd = meta_drm_buffer_dumb_ensure_dmabuf_fd (buffer_dumb, &error);
|
||||||
if (!dmabuf_fd)
|
if (!dmabuf_fd)
|
||||||
@ -831,7 +830,7 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
|
|||||||
void *buffer_data;
|
void *buffer_data;
|
||||||
CoglBitmap *dumb_bitmap;
|
CoglBitmap *dumb_bitmap;
|
||||||
CoglPixelFormat cogl_format;
|
CoglPixelFormat cogl_format;
|
||||||
gboolean ret;
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferCpu,
|
COGL_TRACE_BEGIN_SCOPED (CopySharedFramebufferCpu,
|
||||||
"copy_shared_framebuffer_cpu()");
|
"copy_shared_framebuffer_cpu()");
|
||||||
@ -848,8 +847,9 @@ copy_shared_framebuffer_cpu (CoglOnscreen *onscreen,
|
|||||||
g_assert (cogl_framebuffer_get_width (framebuffer) == width);
|
g_assert (cogl_framebuffer_get_width (framebuffer) == width);
|
||||||
g_assert (cogl_framebuffer_get_height (framebuffer) == height);
|
g_assert (cogl_framebuffer_get_height (framebuffer) == height);
|
||||||
|
|
||||||
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
|
format_info = meta_format_info_from_drm_format (drm_format);
|
||||||
g_assert (ret);
|
g_assert (format_info);
|
||||||
|
cogl_format = format_info->cogl_format;
|
||||||
|
|
||||||
dumb_bitmap = cogl_bitmap_new_for_data (cogl_context,
|
dumb_bitmap = cogl_bitmap_new_for_data (cogl_context,
|
||||||
width,
|
width,
|
||||||
@ -2116,9 +2116,7 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
|
|||||||
/* Check if any of our preferred formats are supported. */
|
/* Check if any of our preferred formats are supported. */
|
||||||
for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++)
|
for (k = 0; k < G_N_ELEMENTS (preferred_formats); k++)
|
||||||
{
|
{
|
||||||
g_assert (meta_cogl_pixel_format_from_drm_format (preferred_formats[k],
|
g_assert (meta_format_info_from_drm_format (preferred_formats[k]));
|
||||||
NULL,
|
|
||||||
NULL));
|
|
||||||
|
|
||||||
for (i = 0; i < formats->len; i++)
|
for (i = 0; i < formats->len; i++)
|
||||||
{
|
{
|
||||||
@ -2138,7 +2136,7 @@ pick_secondary_gpu_framebuffer_format_for_cpu (CoglOnscreen *onscreen)
|
|||||||
{
|
{
|
||||||
drm_format = g_array_index (formats, uint32_t, i);
|
drm_format = g_array_index (formats, uint32_t, i);
|
||||||
|
|
||||||
if (meta_cogl_pixel_format_from_drm_format (drm_format, NULL, NULL))
|
if (meta_format_info_from_drm_format (drm_format))
|
||||||
return drm_format;
|
return drm_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,10 +615,11 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
|
|||||||
CoglEglImageFlags flags;
|
CoglEglImageFlags flags;
|
||||||
CoglTexture *cogl_tex;
|
CoglTexture *cogl_tex;
|
||||||
CoglOffscreen *cogl_fbo;
|
CoglOffscreen *cogl_fbo;
|
||||||
int ret;
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
ret = meta_cogl_pixel_format_from_drm_format (drm_format, &cogl_format, NULL);
|
format_info = meta_format_info_from_drm_format (drm_format);
|
||||||
g_assert (ret);
|
g_assert (format_info);
|
||||||
|
cogl_format = format_info->cogl_format;
|
||||||
|
|
||||||
strides[0] = stride;
|
strides[0] = stride;
|
||||||
offsets[0] = offset;
|
offsets[0] = offset;
|
||||||
@ -930,8 +931,10 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
|
|||||||
uint32_t drm_format;
|
uint32_t drm_format;
|
||||||
CoglFramebuffer *dmabuf_fb;
|
CoglFramebuffer *dmabuf_fb;
|
||||||
CoglDmaBufHandle *dmabuf_handle;
|
CoglDmaBufHandle *dmabuf_handle;
|
||||||
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
if (!meta_drm_format_from_cogl_pixel_format (format, &drm_format))
|
format_info = meta_format_info_from_cogl_format (format);
|
||||||
|
if (!format_info)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
|
||||||
"Native renderer doesn't support creating DMA buffer with format %s",
|
"Native renderer doesn't support creating DMA buffer with format %s",
|
||||||
@ -939,6 +942,7 @@ meta_renderer_native_create_dma_buf (CoglRenderer *cogl_renderer,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drm_format = format_info->drm_format;
|
||||||
render_device = renderer_gpu_data->render_device;
|
render_device = renderer_gpu_data->render_device;
|
||||||
flags = META_DRM_BUFFER_FLAG_NONE;
|
flags = META_DRM_BUFFER_FLAG_NONE;
|
||||||
buffer = meta_render_device_allocate_dma_buf (render_device,
|
buffer = meta_render_device_allocate_dma_buf (render_device,
|
||||||
|
@ -24,50 +24,32 @@
|
|||||||
|
|
||||||
#include "common/meta-cogl-drm-formats.h"
|
#include "common/meta-cogl-drm-formats.h"
|
||||||
|
|
||||||
gboolean
|
const MetaFormatInfo *
|
||||||
meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
meta_format_info_from_drm_format (uint32_t drm_format)
|
||||||
CoglPixelFormat *out_format,
|
|
||||||
MetaMultiTextureFormat *out_multi_texture_format)
|
|
||||||
{
|
{
|
||||||
const size_t n = G_N_ELEMENTS (meta_cogl_drm_format_map);
|
const size_t n = G_N_ELEMENTS (meta_format_info);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
if (meta_cogl_drm_format_map[i].drm_format == drm_format)
|
if (meta_format_info[i].drm_format == drm_format)
|
||||||
break;
|
return &meta_format_info[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == n)
|
return NULL;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (out_format)
|
|
||||||
*out_format = meta_cogl_drm_format_map[i].cogl_format;
|
|
||||||
|
|
||||||
if (out_multi_texture_format)
|
|
||||||
*out_multi_texture_format = meta_cogl_drm_format_map[i].multi_texture_format;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
const MetaFormatInfo *
|
||||||
meta_drm_format_from_cogl_pixel_format (CoglPixelFormat cogl_format,
|
meta_format_info_from_cogl_format (CoglPixelFormat cogl_format)
|
||||||
uint32_t *out_drm_format)
|
|
||||||
{
|
{
|
||||||
const size_t n = G_N_ELEMENTS (meta_cogl_drm_format_map);
|
const size_t n = G_N_ELEMENTS (meta_format_info);
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
if (meta_cogl_drm_format_map[i].cogl_format == cogl_format)
|
if (meta_format_info[i].cogl_format == cogl_format)
|
||||||
break;
|
return &meta_format_info[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == n)
|
return NULL;
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (out_drm_format)
|
|
||||||
*out_drm_format = meta_cogl_drm_format_map[i].drm_format;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
@ -29,14 +29,14 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _CoglDrmFormatMap
|
typedef struct _MetaFormatInfo
|
||||||
{
|
{
|
||||||
uint32_t drm_format;
|
uint32_t drm_format;
|
||||||
CoglPixelFormat cogl_format;
|
CoglPixelFormat cogl_format;
|
||||||
MetaMultiTextureFormat multi_texture_format;
|
MetaMultiTextureFormat multi_texture_format;
|
||||||
} CoglDrmFormatMap;
|
} MetaFormatInfo;
|
||||||
|
|
||||||
static const CoglDrmFormatMap meta_cogl_drm_format_map[] = {
|
static const MetaFormatInfo meta_format_info[] = {
|
||||||
/* DRM formats are defined as little-endian, not machine endian. */
|
/* DRM formats are defined as little-endian, not machine endian. */
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||||
{ DRM_FORMAT_R8, COGL_PIXEL_FORMAT_R_8, META_MULTI_TEXTURE_FORMAT_INVALID },
|
{ DRM_FORMAT_R8, COGL_PIXEL_FORMAT_R_8, META_MULTI_TEXTURE_FORMAT_INVALID },
|
||||||
@ -78,11 +78,8 @@ static const CoglDrmFormatMap meta_cogl_drm_format_map[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
gboolean meta_cogl_pixel_format_from_drm_format (uint32_t drm_format,
|
const MetaFormatInfo *meta_format_info_from_drm_format (uint32_t drm_format);
|
||||||
CoglPixelFormat *out_format,
|
|
||||||
MetaMultiTextureFormat *out_multi_texture_format);
|
|
||||||
|
|
||||||
gboolean meta_drm_format_from_cogl_pixel_format (CoglPixelFormat cogl_format,
|
const MetaFormatInfo *meta_format_info_from_cogl_format (CoglPixelFormat cogl_format);
|
||||||
uint32_t *out_drm_format);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@ -356,6 +356,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
MetaWaylandDmaBufBuffer *dma_buf = buffer->dma_buf.dma_buf;
|
MetaWaylandDmaBufBuffer *dma_buf = buffer->dma_buf.dma_buf;
|
||||||
MetaMultiTextureFormat multi_format;
|
MetaMultiTextureFormat multi_format;
|
||||||
CoglPixelFormat cogl_format;
|
CoglPixelFormat cogl_format;
|
||||||
|
const MetaFormatInfo *format_info;
|
||||||
#ifdef HAVE_NATIVE_BACKEND
|
#ifdef HAVE_NATIVE_BACKEND
|
||||||
MetaDrmFormatBuf format_buf;
|
MetaDrmFormatBuf format_buf;
|
||||||
#endif
|
#endif
|
||||||
@ -363,9 +364,8 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
if (buffer->dma_buf.texture)
|
if (buffer->dma_buf.texture)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
if (!meta_cogl_pixel_format_from_drm_format (dma_buf->drm_format,
|
format_info = meta_format_info_from_drm_format (dma_buf->drm_format);
|
||||||
&cogl_format,
|
if (!format_info)
|
||||||
&multi_format))
|
|
||||||
{
|
{
|
||||||
g_set_error (error, G_IO_ERROR,
|
g_set_error (error, G_IO_ERROR,
|
||||||
G_IO_ERROR_FAILED,
|
G_IO_ERROR_FAILED,
|
||||||
@ -373,6 +373,9 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cogl_format = format_info->cogl_format;
|
||||||
|
multi_format = format_info->multi_texture_format;
|
||||||
|
|
||||||
#ifdef HAVE_NATIVE_BACKEND
|
#ifdef HAVE_NATIVE_BACKEND
|
||||||
meta_topic (META_DEBUG_WAYLAND,
|
meta_topic (META_DEBUG_WAYLAND,
|
||||||
"[dma-buf] wl_buffer@%u DRM format %s "
|
"[dma-buf] wl_buffer@%u DRM format %s "
|
||||||
@ -456,17 +459,12 @@ 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, j;
|
int plane_index;
|
||||||
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
for (j = 0; j < G_N_ELEMENTS (meta_cogl_drm_format_map); j++)
|
format_info = meta_format_info_from_cogl_format (subformats[i]);
|
||||||
{
|
g_return_val_if_fail (format_info != NULL, FALSE);
|
||||||
if (meta_cogl_drm_format_map[j].cogl_format == subformats[i])
|
drm_format = format_info->drm_format;
|
||||||
{
|
|
||||||
drm_format = meta_cogl_drm_format_map[j].drm_format;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_return_val_if_fail (drm_format != 0, FALSE);
|
|
||||||
|
|
||||||
plane_index = plane_indices[i];
|
plane_index = plane_indices[i];
|
||||||
|
|
||||||
@ -1638,7 +1636,8 @@ init_formats (MetaWaylandDmaBufManager *dma_buf_manager,
|
|||||||
MetaEgl *egl = meta_backend_get_egl (backend);
|
MetaEgl *egl = meta_backend_get_egl (backend);
|
||||||
EGLint num_formats;
|
EGLint num_formats;
|
||||||
g_autofree EGLint *driver_formats = NULL;
|
g_autofree EGLint *driver_formats = NULL;
|
||||||
int i, j;
|
int i;
|
||||||
|
const MetaFormatInfo *format_info;
|
||||||
|
|
||||||
dma_buf_manager->formats = g_array_new (FALSE, FALSE,
|
dma_buf_manager->formats = g_array_new (FALSE, FALSE,
|
||||||
sizeof (MetaWaylandDmaBufFormat));
|
sizeof (MetaWaylandDmaBufFormat));
|
||||||
@ -1659,15 +1658,12 @@ init_formats (MetaWaylandDmaBufManager *dma_buf_manager,
|
|||||||
driver_formats, &num_formats, error))
|
driver_formats, &num_formats, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (meta_cogl_drm_format_map); i++)
|
for (i = 0; i < num_formats; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < num_formats; j++)
|
format_info = meta_format_info_from_drm_format (driver_formats[i]);
|
||||||
{
|
if (format_info && format_info->multi_texture_format !=
|
||||||
if ((meta_cogl_drm_format_map[i].drm_format == driver_formats[j]) &&
|
META_MULTI_TEXTURE_FORMAT_INVALID)
|
||||||
(meta_cogl_drm_format_map[i].multi_texture_format !=
|
add_format (dma_buf_manager, egl_display, driver_formats[i]);
|
||||||
META_MULTI_TEXTURE_FORMAT_INVALID))
|
|
||||||
add_format (dma_buf_manager, egl_display, driver_formats[j]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dma_buf_manager->formats->len == 0)
|
if (dma_buf_manager->formats->len == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user