backend/native: Move DrmFormatBuf to cogl-drm-formats

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3480>
This commit is contained in:
Bilal Elmoussaoui 2024-01-03 13:36:42 +01:00
parent 786a9d9072
commit cebde5c2d1
6 changed files with 43 additions and 45 deletions

View File

@ -28,6 +28,7 @@
#include "backends/native/meta-device-pool.h"
#include "backends/native/meta-kms-utils.h"
#include "common/meta-cogl-drm-formats.h"
#include "meta-private-enum-types.h"

View File

@ -20,7 +20,6 @@
#include "backends/native/meta-kms-utils.h"
#include <drm_fourcc.h>
#include <glib.h>
float
@ -61,36 +60,4 @@ meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode)
return value;
}
/**
* meta_drm_format_to_string:
* @tmp: temporary buffer
* @drm_format: DRM fourcc pixel format
*
* Returns a pointer to a string naming the given pixel format,
* usually a pointer to the temporary buffer but not always.
* Invalid formats may return nonsense names.
*
* When calling this, allocate one MetaDrmFormatBuf on the stack to
* be used as the temporary buffer.
*/
const char *
meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format)
{
int i;
if (drm_format == DRM_FORMAT_INVALID)
return "INVALID";
G_STATIC_ASSERT (sizeof (tmp->s) == 5);
for (i = 0; i < 4; i++)
{
char c = (drm_format >> (i * 8)) & 0xff;
tmp->s[i] = g_ascii_isgraph (c) ? c : '.';
}
tmp->s[i] = 0;
return tmp->s;
}

View File

@ -23,16 +23,8 @@
#include "core/util-private.h"
typedef struct _MetaDrmFormatBuf
{
char s[5];
} MetaDrmFormatBuf;
META_EXPORT_TEST
float meta_calculate_drm_mode_refresh_rate (const drmModeModeInfo *drm_mode);
META_EXPORT_TEST
int64_t meta_calculate_drm_mode_vblank_duration_us (const drmModeModeInfo *drm_mode);
const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format);

View File

@ -24,6 +24,40 @@
#include "common/meta-cogl-drm-formats.h"
/**
* meta_drm_format_to_string:
* @tmp: temporary buffer
* @drm_format: DRM fourcc pixel format
*
* Returns a pointer to a string naming the given pixel format,
* usually a pointer to the temporary buffer but not always.
* Invalid formats may return nonsense names.
*
* When calling this, allocate one MetaDrmFormatBuf on the stack to
* be used as the temporary buffer.
*/
const char *
meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format)
{
int i;
if (drm_format == DRM_FORMAT_INVALID)
return "INVALID";
G_STATIC_ASSERT (sizeof (tmp->s) == 5);
for (i = 0; i < 4; i++)
{
char c = (drm_format >> (i * 8)) & 0xff;
tmp->s[i] = g_ascii_isgraph (c) ? c : '.';
}
tmp->s[i] = 0;
return tmp->s;
}
const MetaFormatInfo *
meta_format_info_from_drm_format (uint32_t drm_format)
{

View File

@ -29,6 +29,14 @@
G_BEGIN_DECLS
typedef struct _MetaDrmFormatBuf
{
char s[5];
} MetaDrmFormatBuf;
const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format);
typedef struct _MetaFormatInfo
{
uint32_t drm_format;

View File

@ -359,9 +359,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
MetaMultiTextureFormat multi_format;
CoglPixelFormat cogl_format;
const MetaFormatInfo *format_info;
#ifdef HAVE_NATIVE_BACKEND
MetaDrmFormatBuf format_buf;
#endif
if (buffer->dma_buf.texture)
return TRUE;
@ -378,7 +376,6 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
cogl_format = format_info->cogl_format;
multi_format = format_info->multi_texture_format;
#ifdef HAVE_NATIVE_BACKEND
meta_topic (META_DEBUG_WAYLAND,
"[dma-buf] wl_buffer@%u DRM format %s "
"-> MetaMultiTextureFormat %s / CoglPixelFormat %s",
@ -386,7 +383,6 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer,
meta_drm_format_to_string (&format_buf, dma_buf->drm_format),
meta_multi_texture_format_to_string (multi_format),
cogl_pixel_format_to_string (cogl_format));
#endif
if (multi_format == META_MULTI_TEXTURE_FORMAT_SIMPLE)
{