diff --git a/src/backends/native/meta-drm-buffer.c b/src/backends/native/meta-drm-buffer.c index a109b4ea2..30bbfb59a 100644 --- a/src/backends/native/meta-drm-buffer.c +++ b/src/backends/native/meta-drm-buffer.c @@ -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" diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index 40ed15a65..721ce63ae 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -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 { diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 7b64ff3f4..5ffbafb58 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -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 diff --git a/src/common/meta-cogl-drm-formats.c b/src/common/meta-cogl-drm-formats.c index 225d6b537..dee5c5134 100644 --- a/src/common/meta-cogl-drm-formats.c +++ b/src/common/meta-cogl-drm-formats.c @@ -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) { diff --git a/src/common/meta-cogl-drm-formats.h b/src/common/meta-cogl-drm-formats.h index dbbc88294..d64bbc241 100644 --- a/src/common/meta-cogl-drm-formats.h +++ b/src/common/meta-cogl-drm-formats.h @@ -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; diff --git a/src/common/meta-drm-format-helpers.c b/src/common/meta-drm-format-helpers.c new file mode 100644 index 000000000..0fc28dc7a --- /dev/null +++ b/src/common/meta-drm-format-helpers.c @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 Georges Basile Stavracas Neto + * 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 . + * + */ + +#include "config.h" + +#include "common/meta-drm-format-helpers.h" + +#include +#include + +/** + * 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; +} diff --git a/src/common/meta-drm-format-helpers.h b/src/common/meta-drm-format-helpers.h new file mode 100644 index 000000000..53834350f --- /dev/null +++ b/src/common/meta-drm-format-helpers.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2020 Georges Basile Stavracas Neto + * 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 . + * + */ + +#pragma once + +#include + +typedef struct _MetaDrmFormatBuf +{ + char s[5]; +} MetaDrmFormatBuf; + +const char * meta_drm_format_to_string (MetaDrmFormatBuf *tmp, + uint32_t drm_format); diff --git a/src/meson.build b/src/meson.build index 90e2be0af..05df3bfd2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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 diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 9d6faf479..3f64758a5 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -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" diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index d23597b7f..5e4ee671c 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -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"