From 63a558950b1ff4b3d5dd8d0416dd831ddf8fc9bb Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Tue, 2 Jan 2024 14:18:04 +0100 Subject: [PATCH] cogl: Generate a GType for PixelFormat So that CoglTexture uses the proper pspec type for it format property Part-of: --- cogl/cogl/cogl-enum-types.c.in | 40 ++++++++++++++++++++++++++++++++++ cogl/cogl/cogl-enum-types.h.in | 27 +++++++++++++++++++++++ cogl/cogl/cogl-texture.c | 7 +++--- cogl/cogl/cogl.h | 1 + cogl/cogl/meson.build | 20 ++++++++++++++++- 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 cogl/cogl/cogl-enum-types.c.in create mode 100644 cogl/cogl/cogl-enum-types.h.in diff --git a/cogl/cogl/cogl-enum-types.c.in b/cogl/cogl/cogl-enum-types.c.in new file mode 100644 index 000000000..91a5833a2 --- /dev/null +++ b/cogl/cogl/cogl-enum-types.c.in @@ -0,0 +1,40 @@ +/*** BEGIN file-header ***/ +#include "config.h" +#include "cogl/cogl-enum-types.h" +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@filename@" */ +#include "@filename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type (void) +{ + static size_t g_enum_type_id = 0; + + if (g_once_init_enter (&g_enum_type_id)) + { + static const G@Type@Value values[] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + GType id; + + id = g_@type@_register_static (g_intern_static_string ("@EnumName@"), values); + + g_once_init_leave (&g_enum_type_id, id); + } + + return g_enum_type_id; +} +/*** END value-tail ***/ diff --git a/cogl/cogl/cogl-enum-types.h.in b/cogl/cogl/cogl-enum-types.h.in new file mode 100644 index 000000000..6fae5a205 --- /dev/null +++ b/cogl/cogl/cogl-enum-types.h.in @@ -0,0 +1,27 @@ +/*** BEGIN file-header ***/ +#pragma once + +#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION) +#error "Only can be included directly." +#endif + +#include "cogl/cogl-types.h" + +G_BEGIN_DECLS + +/*** END file-header ***/ + +/*** BEGIN file-production ***/ +/* enumerations from "@basename@" */ +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +COGL_EXPORT GType @enum_name@_get_type (void) G_GNUC_CONST; +#define COGL_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) + +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ +G_END_DECLS + +/*** END file-tail ***/ diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index 8d3da97ab..32d72a38d 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -40,6 +40,7 @@ #include "cogl/cogl-bitmap.h" #include "cogl/cogl-bitmap-private.h" #include "cogl/cogl-buffer-private.h" +#include "cogl/cogl-enum-types.h" #include "cogl/cogl-pixel-buffer-private.h" #include "cogl/cogl-private.h" #include "cogl/cogl-texture-private.h" @@ -135,7 +136,7 @@ cogl_texture_set_property (GObject *gobject, break; case PROP_FORMAT: - _cogl_texture_set_internal_format (texture, g_value_get_uint (value)); + _cogl_texture_set_internal_format (texture, g_value_get_enum (value)); /* Although we want to initialize texture::components according * to the source format, we always want the internal layout to * be considered premultiplied by default. @@ -188,8 +189,8 @@ cogl_texture_class_init (CoglTextureClass *klass) G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); obj_props[PROP_FORMAT] = - g_param_spec_uint ("format", NULL, NULL, - COGL_PIXEL_FORMAT_ANY, G_MAXINT, + g_param_spec_enum ("format", NULL, NULL, + COGL_TYPE_PIXEL_FORMAT, COGL_PIXEL_FORMAT_ANY, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); diff --git a/cogl/cogl/cogl.h b/cogl/cogl/cogl.h index 55010b628..f9ca2c5e6 100644 --- a/cogl/cogl/cogl.h +++ b/cogl/cogl/cogl.h @@ -85,6 +85,7 @@ #include "cogl/cogl-atlas-texture.h" #include "cogl/cogl-meta-texture.h" #include "cogl/cogl-primitive-texture.h" +#include "cogl/cogl-enum-types.h" #include "cogl/cogl-index-buffer.h" #include "cogl/cogl-attribute-buffer.h" #include "cogl/cogl-indices.h" diff --git a/cogl/cogl/meson.build b/cogl/cogl/meson.build index ddfd40173..68b1b4f89 100644 --- a/cogl/cogl/meson.build +++ b/cogl/cogl/meson.build @@ -18,7 +18,6 @@ cogl_headers = [ 'cogl-pipeline-layer-state.h', 'cogl-pipeline-state.h', 'cogl-pipeline.h', - 'cogl-pixel-format.h', 'cogl-snippet.h', 'cogl-texture-2d-sliced.h', 'cogl-texture-2d.h', @@ -356,7 +355,26 @@ if have_egl_xlib ] endif +cogl_enum_headers = [ + 'cogl-pixel-format.h', +] + +cogl_headers += [ + cogl_enum_headers, +] + +cogl_enums = gnome.mkenums('cogl-enums', + sources: cogl_enum_headers, + c_template: 'cogl-enum-types.c.in', + h_template: 'cogl-enum-types.h.in', + install_dir: cogl_cogl_includedir, + install_header: true, +) + +cogl_sources += [cogl_enums[0]] + cogl_introspected_headers = [ + cogl_enums[1], cogl_headers, cogl_deprecated_headers, ]