[gtk+/wip/otte/shader: 1/26] gskslvariable: Add API to query if access chain usage is possible



commit 8b6be6979c9ea147a2c8a9c9f26b3cc94af76bcd
Author: Benjamin Otte <otte redhat com>
Date:   Mon Oct 16 22:30:56 2017 +0200

    gskslvariable: Add API to query if access chain usage is possible
    
    This is necessary so access chain creation can fail early when a
    reference expression is asked to create one.

 gsk/gskslvariable.c               |   35 +++++++++++++++++++++++++++++++++++
 gsk/gskslvariableprivate.h        |    1 +
 gsk/gskspvwriter.c                |    3 +++
 testsuite/gsk/test-render-nodes.c |   20 ++++++++++++++++++++
 4 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/gsk/gskslvariable.c b/gsk/gskslvariable.c
index 084d63b..44697ca 100644
--- a/gsk/gskslvariable.c
+++ b/gsk/gskslvariable.c
@@ -45,6 +45,7 @@ struct _GskSlVariableClass
 
   void                  (* free)                                (GskSlVariable          *variable);
 
+  gboolean              (* is_direct_access_spv)                (const GskSlVariable    *variable);
   guint32               (* write_spv)                           (const GskSlVariable    *variable,
                                                                  GskSpvWriter           *writer);
   guint32               (* load_spv)                            (GskSlVariable          *variable,
@@ -80,6 +81,12 @@ gsk_sl_variable_free (GskSlVariable *variable)
 
 /* STANDARD */
 
+static gboolean
+gsk_sl_variable_standard_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return TRUE;
+}
+
 static guint32
 gsk_sl_variable_standard_write_spv (const GskSlVariable *variable,
                                     GskSpvWriter        *writer)
@@ -135,6 +142,7 @@ gsk_sl_variable_standard_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_STANDARD = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_standard_is_direct_access_spv,
   gsk_sl_variable_standard_write_spv,
   gsk_sl_variable_standard_load_spv,
   gsk_sl_variable_standard_store_spv,
@@ -142,6 +150,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_STANDARD = {
 
 /* CONSTANT */
 
+static gboolean
+gsk_sl_variable_constant_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return FALSE;
+}
+
 static guint32
 gsk_sl_variable_constant_write_spv (const GskSlVariable *variable,
                                     GskSpvWriter        *writer)
@@ -167,6 +181,7 @@ gsk_sl_variable_constant_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_CONSTANT = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_constant_is_direct_access_spv,
   gsk_sl_variable_constant_write_spv,
   gsk_sl_variable_constant_load_spv,
   gsk_sl_variable_constant_store_spv,
@@ -174,6 +189,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_CONSTANT = {
 
 /* PARAMETER */
 
+static gboolean
+gsk_sl_variable_parameter_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return TRUE;
+}
+
 static guint32
 gsk_sl_variable_parameter_write_spv (const GskSlVariable *variable,
                                      GskSpvWriter        *writer)
@@ -216,6 +237,7 @@ gsk_sl_variable_parameter_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_PARAMETER = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_parameter_is_direct_access_spv,
   gsk_sl_variable_parameter_write_spv,
   gsk_sl_variable_parameter_load_spv,
   gsk_sl_variable_parameter_store_spv,
@@ -223,6 +245,12 @@ static const GskSlVariableClass GSK_SL_VARIABLE_PARAMETER = {
 
 /* CONST_PARAMETER */
 
+static gboolean
+gsk_sl_variable_const_parameter_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return FALSE;
+}
+
 static guint32
 gsk_sl_variable_const_parameter_write_spv (const GskSlVariable *variable,
                                            GskSpvWriter        *writer)
@@ -256,6 +284,7 @@ gsk_sl_variable_const_parameter_store_spv (GskSlVariable *variable,
 static const GskSlVariableClass GSK_SL_VARIABLE_CONST_PARAMETER = {
   sizeof (GskSlVariable),
   gsk_sl_variable_free,
+  gsk_sl_variable_const_parameter_is_direct_access_spv,
   gsk_sl_variable_const_parameter_write_spv,
   gsk_sl_variable_const_parameter_load_spv,
   gsk_sl_variable_const_parameter_store_spv,
@@ -405,6 +434,12 @@ gsk_sl_variable_is_constant (const GskSlVariable *variable)
   return gsk_sl_qualifier_is_constant (&variable->qualifier);
 }
 
+gboolean
+gsk_sl_variable_is_direct_access_spv (const GskSlVariable *variable)
+{
+  return variable->class->is_direct_access_spv (variable);
+}
+
 guint32
 gsk_sl_variable_write_spv (const GskSlVariable *variable,
                            GskSpvWriter        *writer)
diff --git a/gsk/gskslvariableprivate.h b/gsk/gskslvariableprivate.h
index d414ad6..2df9759 100644
--- a/gsk/gskslvariableprivate.h
+++ b/gsk/gskslvariableprivate.h
@@ -42,6 +42,7 @@ const char *            gsk_sl_variable_get_name                (const GskSlVari
 const GskSlValue *      gsk_sl_variable_get_initial_value       (const GskSlVariable    *variable);
 gboolean                gsk_sl_variable_is_constant             (const GskSlVariable    *variable);
 
+gboolean                gsk_sl_variable_is_direct_access_spv    (const GskSlVariable    *variable);
 guint32                 gsk_sl_variable_write_spv               (const GskSlVariable    *variable,
                                                                  GskSpvWriter           *writer);
 guint32                 gsk_sl_variable_load_spv                (GskSlVariable          *variable,
diff --git a/gsk/gskspvwriter.c b/gsk/gskspvwriter.c
index 625d1eb..57e5b38 100644
--- a/gsk/gskspvwriter.c
+++ b/gsk/gskspvwriter.c
@@ -754,6 +754,9 @@ gsk_spv_access_chain_new (GskSpvWriter  *writer,
 {
   GskSpvAccessChain *chain;
 
+  if (!gsk_sl_variable_is_direct_access_spv (variable))
+    return NULL;
+
   chain = g_slice_new0 (GskSpvAccessChain);
 
   chain->writer = gsk_spv_writer_ref (writer);
diff --git a/testsuite/gsk/test-render-nodes.c b/testsuite/gsk/test-render-nodes.c
index 0bae5f1..3f239c7 100644
--- a/testsuite/gsk/test-render-nodes.c
+++ b/testsuite/gsk/test-render-nodes.c
@@ -346,6 +346,25 @@ cross_fade (void)
 }
 
 static GskRenderNode *
+rounded_rect (void)
+{
+  GskRenderNode *color;
+  GskRenderNode *rounded;
+
+  color = gsk_color_node_new (&(GdkRGBA) { 1, 1, 0, 1 }, 
+                               &GRAPHENE_RECT_INIT (0, 0, 200, 200));
+  rounded = gsk_rounded_clip_node_new (color,
+                                       &(GskRoundedRect) {
+                                           GRAPHENE_RECT_INIT (50, 50, 100, 100),
+                                           { { 10, 10 }, { 10, 10 }, { 10, 10 }, { 10, 10 } }
+                                       });
+
+  gsk_render_node_unref (color);
+
+  return rounded;
+}
+
+static GskRenderNode *
 cross_fades (void)
 {
   GskRenderNode *child1;
@@ -423,6 +442,7 @@ static const struct {
   { "blendmodes.node", blendmodes },
   { "cross-fades.node", cross_fades },
   { "transform.node", transform },
+  { "rounded-rect.node", rounded_rect },
 };
 
 /*** test setup ***/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]