[gtk+/wip/otte/shader: 42/51] gskslfunction: Split regular and builtin constructors
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/shader: 42/51] gskslfunction: Split regular and builtin constructors
- Date: Sat, 30 Sep 2017 18:08:23 +0000 (UTC)
commit 0463ee90d791b284c57e1e451d7de8ba7c356491
Author: Benjamin Otte <otte redhat com>
Date: Fri Sep 29 19:33:59 2017 +0200
gskslfunction: Split regular and builtin constructors
Their behavior is just too different.
gsk/gskslfunction.c | 152 +++++++++++++++++++++++++++++++++++----------------
1 files changed, 104 insertions(+), 48 deletions(-)
---
diff --git a/gsk/gskslfunction.c b/gsk/gskslfunction.c
index 217576c..8d5f0eb 100644
--- a/gsk/gskslfunction.c
+++ b/gsk/gskslfunction.c
@@ -46,43 +46,43 @@ gsk_sl_function_alloc (const GskSlFunctionClass *klass,
/* BUILTIN CONSTRUCTOR */
-typedef struct _GskSlFunctionConstructor GskSlFunctionConstructor;
+typedef struct _GskSlFunctionBuiltinConstructor GskSlFunctionBuiltinConstructor;
-struct _GskSlFunctionConstructor {
+struct _GskSlFunctionBuiltinConstructor {
GskSlFunction parent;
GskSlType *type;
};
static void
-gsk_sl_function_constructor_free (GskSlFunction *function)
+gsk_sl_function_builtin_constructor_free (GskSlFunction *function)
{
- GskSlFunctionConstructor *constructor = (GskSlFunctionConstructor *) function;
+ GskSlFunctionBuiltinConstructor *builtin_constructor = (GskSlFunctionBuiltinConstructor *) function;
- gsk_sl_type_unref (constructor->type);
+ gsk_sl_type_unref (builtin_constructor->type);
- g_slice_free (GskSlFunctionConstructor, constructor);
+ g_slice_free (GskSlFunctionBuiltinConstructor, builtin_constructor);
}
static GskSlType *
-gsk_sl_function_constructor_get_return_type (const GskSlFunction *function)
+gsk_sl_function_builtin_constructor_get_return_type (const GskSlFunction *function)
{
- const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
+ const GskSlFunctionBuiltinConstructor *builtin_constructor = (const GskSlFunctionBuiltinConstructor *)
function;
- return constructor->type;
+ return builtin_constructor->type;
}
static const char *
-gsk_sl_function_constructor_get_name (const GskSlFunction *function)
+gsk_sl_function_builtin_constructor_get_name (const GskSlFunction *function)
{
- const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
+ const GskSlFunctionBuiltinConstructor *builtin_constructor = (const GskSlFunctionBuiltinConstructor *)
function;
- return gsk_sl_type_get_name (constructor->type);
+ return gsk_sl_type_get_name (builtin_constructor->type);
}
static void
-gsk_sl_function_constructor_print (const GskSlFunction *function,
- GString *string)
+gsk_sl_function_builtin_constructor_print (const GskSlFunction *function,
+ GString *string)
{
}
@@ -100,25 +100,25 @@ gsk_sl_function_builtin_get_args_by_type (const GskSlType *type)
}
static gboolean
-gsk_sl_function_constructor_matches_builtin (const GskSlFunction *function,
+gsk_sl_function_builtin_constructor_matches (const GskSlFunction *function,
GskSlType **arguments,
gsize n_arguments,
GError **error)
{
- const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
+ const GskSlFunctionBuiltinConstructor *builtin_constructor = (const GskSlFunctionBuiltinConstructor *)
function;
guint needed, provided;
gsize i;
if (n_arguments == 1 && gsk_sl_type_is_scalar (arguments[0]))
return TRUE;
- needed = gsk_sl_function_builtin_get_args_by_type (constructor->type);
+ needed = gsk_sl_function_builtin_get_args_by_type (builtin_constructor->type);
for (i = 0; i < n_arguments; i++)
{
if (needed == 0)
{
- g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Too many arguments given to constructor,
only the first %"G_GSIZE_FORMAT" are necessary.", i);
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Too many arguments given to
builtin_constructor, only the first %"G_GSIZE_FORMAT" are necessary.", i);
return FALSE;
}
@@ -127,7 +127,7 @@ gsk_sl_function_constructor_matches_builtin (const GskSlFunction *function,
{
g_set_error (error,
G_FILE_ERROR, G_FILE_ERROR_FAILED,
- "Invalid type %s for constructor in argument %"G_GSIZE_FORMAT,
+ "Invalid type %s for builtin_constructor in argument %"G_GSIZE_FORMAT,
gsk_sl_type_get_name (arguments[i]), i + 1);
return FALSE;
}
@@ -138,11 +138,69 @@ gsk_sl_function_constructor_matches_builtin (const GskSlFunction *function,
return TRUE;
}
+static guint32
+gsk_sl_function_builtin_constructor_write_spv (const GskSlFunction *function,
+ GskSpvWriter *writer)
+{
+ return 0;
+}
+
+static const GskSlFunctionClass GSK_SL_FUNCTION_BUILTIN_CONSTRUCTOR = {
+ gsk_sl_function_builtin_constructor_free,
+ gsk_sl_function_builtin_constructor_get_return_type,
+ gsk_sl_function_builtin_constructor_get_name,
+ gsk_sl_function_builtin_constructor_print,
+ gsk_sl_function_builtin_constructor_matches,
+ gsk_sl_function_builtin_constructor_write_spv,
+};
+
+/* CONSTRUCTOR */
+
+typedef struct _GskSlFunctionConstructor GskSlFunctionConstructor;
+
+struct _GskSlFunctionConstructor {
+ GskSlFunction parent;
+
+ GskSlType *type;
+};
+
+static void
+gsk_sl_function_constructor_free (GskSlFunction *function)
+{
+ GskSlFunctionConstructor *constructor = (GskSlFunctionConstructor *) function;
+
+ gsk_sl_type_unref (constructor->type);
+
+ g_slice_free (GskSlFunctionConstructor, constructor);
+}
+
+static GskSlType *
+gsk_sl_function_constructor_get_return_type (const GskSlFunction *function)
+{
+ const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
+
+ return constructor->type;
+}
+
+static const char *
+gsk_sl_function_constructor_get_name (const GskSlFunction *function)
+{
+ const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
+
+ return gsk_sl_type_get_name (constructor->type);
+}
+
+static void
+gsk_sl_function_constructor_print (const GskSlFunction *function,
+ GString *string)
+{
+}
+
static gboolean
-gsk_sl_function_constructor_matches_struct (const GskSlFunction *function,
- GskSlType **arguments,
- gsize n_arguments,
- GError **error)
+gsk_sl_function_constructor_matches (const GskSlFunction *function,
+ GskSlType **arguments,
+ gsize n_arguments,
+ GError **error)
{
const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
guint i;
@@ -175,27 +233,6 @@ gsk_sl_function_constructor_matches_struct (const GskSlFunction *function,
return TRUE;
}
-static gboolean
-gsk_sl_function_constructor_matches (const GskSlFunction *function,
- GskSlType **arguments,
- gsize n_arguments,
- GError **error)
-{
- const GskSlFunctionConstructor *constructor = (const GskSlFunctionConstructor *) function;
-
- if (gsk_sl_type_is_scalar (constructor->type) ||
- gsk_sl_type_is_vector (constructor->type) ||
- gsk_sl_type_is_matrix (constructor->type))
- return gsk_sl_function_constructor_matches_builtin (function, arguments, n_arguments, error);
- else if (gsk_sl_type_is_struct (constructor->type))
- return gsk_sl_function_constructor_matches_struct (function, arguments, n_arguments, error);
- else
- {
- g_assert_not_reached ();
- }
-
-}
-
static guint32
gsk_sl_function_constructor_write_spv (const GskSlFunction *function,
GskSpvWriter *writer)
@@ -394,13 +431,32 @@ static const GskSlFunctionClass GSK_SL_FUNCTION_DECLARED = {
GskSlFunction *
gsk_sl_function_new_constructor (GskSlType *type)
{
- GskSlFunctionConstructor *constructor;
+ if (gsk_sl_type_is_scalar (type) ||
+ gsk_sl_type_is_vector (type) ||
+ gsk_sl_type_is_matrix (type))
+ {
+ GskSlFunctionBuiltinConstructor *constructor;
+
+ constructor = gsk_sl_function_new (GskSlFunctionBuiltinConstructor,
&GSK_SL_FUNCTION_BUILTIN_CONSTRUCTOR);
+ constructor->type = gsk_sl_type_ref (type);
- constructor = gsk_sl_function_new (GskSlFunctionConstructor, &GSK_SL_FUNCTION_CONSTRUCTOR);
+ return &constructor->parent;
+ }
+ else if (gsk_sl_type_is_struct (type))
+ {
+ GskSlFunctionConstructor *constructor;
- constructor->type = gsk_sl_type_ref (type);
+ constructor = gsk_sl_function_new (GskSlFunctionConstructor, &GSK_SL_FUNCTION_CONSTRUCTOR);
+ constructor->type = gsk_sl_type_ref (type);
- return &constructor->parent;
+ return &constructor->parent;
+ }
+ else
+ {
+ g_assert_not_reached ();
+
+ return NULL;
+ }
}
GskSlFunction *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]