1
0
Fork 0

common/cogl-drm-formats: Split out format to string helper

It means it can be included in places that assume cogl and everything it
involves shouldn't be included, e.g. meta-renderer-native-gles3.c.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3304>
This commit is contained in:
Jonas Ådahl 2024-04-11 12:00:18 +02:00 committed by Marge Bot
parent f91851154e
commit 0b91d22848
10 changed files with 95 additions and 43 deletions

View file

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

View file

@ -51,6 +51,7 @@
#include "backends/native/meta-renderer-native-private.h"
#include "cogl/cogl.h"
#include "common/meta-cogl-drm-formats.h"
#include "common/meta-drm-format-helpers.h"
typedef enum _MetaSharedFramebufferImportStatus
{

View file

@ -67,6 +67,7 @@
#include "backends/native/meta-renderer-view-native.h"
#include "cogl/cogl.h"
#include "common/meta-cogl-drm-formats.h"
#include "common/meta-drm-format-helpers.h"
#include "core/boxes-private.h"
#ifdef HAVE_EGL_DEVICE

View file

@ -24,40 +24,6 @@
#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,14 +29,6 @@
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

@ -0,0 +1,58 @@
/*
* Copyright (C) 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
* Copyright (C) 2023 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include "common/meta-drm-format-helpers.h"
#include <drm_fourcc.h>
#include <glib.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;
}

View file

@ -0,0 +1,30 @@
/*
* Copyright (C) 2020 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
* Copyright (C) 2023 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <stdint.h>
typedef struct _MetaDrmFormatBuf
{
char s[5];
} MetaDrmFormatBuf;
const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp,
uint32_t drm_format);

View file

@ -873,6 +873,8 @@ if have_wayland or have_native_backend
mutter_sources += [
'common/meta-cogl-drm-formats.c',
'common/meta-cogl-drm-formats.h',
'common/meta-drm-format-helpers.c',
'common/meta-drm-format-helpers.h',
]
endif

View file

@ -58,6 +58,7 @@
#include "wayland/meta-wayland-dma-buf.h"
#include "wayland/meta-wayland-private.h"
#include "common/meta-cogl-drm-formats.h"
#include "common/meta-drm-format-helpers.h"
#include "compositor/meta-multi-texture-format-private.h"
#include "wayland/meta-drm-timeline.h"
#include "wayland/meta-wayland-linux-drm-syncobj.h"

View file

@ -51,6 +51,7 @@
#include "cogl/cogl-egl.h"
#include "cogl/cogl.h"
#include "common/meta-cogl-drm-formats.h"
#include "common/meta-drm-format-helpers.h"
#include "compositor/meta-multi-texture-format-private.h"
#include "meta/meta-backend.h"
#include "wayland/meta-wayland-buffer.h"