From 49f9d2108dbde96d2d5555f737db0183e4002a8a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 24 Apr 2018 00:41:48 +0200 Subject: [PATCH] gsk: Add GskDebugNode --- docs/reference/gsk/gsk4-sections.txt | 3 + gsk/gl/gskglrenderer.c | 6 + gsk/gskbroadwayrenderer.c | 5 + gsk/gskenums.h | 3 +- gsk/gskrendernode.h | 8 ++ gsk/gskrendernodeimpl.c | 171 +++++++++++++++++++++++++ gsk/vulkan/gskvulkanrenderpass.c | 4 + gtk/inspector/gtktreemodelrendernode.c | 4 + gtk/inspector/recorder.c | 6 + 9 files changed, 209 insertions(+), 1 deletion(-) diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt index 25fc3cdfd5..7c41a2a239 100644 --- a/docs/reference/gsk/gsk4-sections.txt +++ b/docs/reference/gsk/gsk4-sections.txt @@ -108,6 +108,9 @@ gsk_text_node_get_y gsk_blur_node_new gsk_blur_node_get_child gsk_blur_node_get_radius +gsk_debug_node_new +gsk_debug_node_get_child +gsk_debug_node_get_message GSK_IS_RENDER_NODE GSK_RENDER_NODE diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index c7b8a7910f..177ac4b611 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -2077,6 +2077,12 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self, } break; + case GSK_DEBUG_NODE: + gsk_gl_renderer_add_render_ops (self, + gsk_debug_node_get_child (node), + builder); + break; + case GSK_COLOR_NODE: render_color_node (self, node, builder, vertex_data); break; diff --git a/gsk/gskbroadwayrenderer.c b/gsk/gskbroadwayrenderer.c index ec8b1bdd47..1a0268a096 100644 --- a/gsk/gskbroadwayrenderer.c +++ b/gsk/gskbroadwayrenderer.c @@ -619,6 +619,11 @@ gsk_broadway_renderer_add_node (GskRenderer *self, } return; + case GSK_DEBUG_NODE: + gsk_broadway_renderer_add_node (self, nodes, node_textures, + gsk_debug_node_get_child (node), offset_x, offset_y); + return; + case GSK_COLOR_MATRIX_NODE: case GSK_TEXT_NODE: case GSK_REPEATING_LINEAR_GRADIENT_NODE: diff --git a/gsk/gskenums.h b/gsk/gskenums.h index 11def6bd8e..b605509047 100644 --- a/gsk/gskenums.h +++ b/gsk/gskenums.h @@ -73,7 +73,8 @@ typedef enum { GSK_CROSS_FADE_NODE, GSK_TEXT_NODE, GSK_BLUR_NODE, - GSK_OFFSET_NODE + GSK_OFFSET_NODE, + GSK_DEBUG_NODE } GskRenderNodeType; /** diff --git a/gsk/gskrendernode.h b/gsk/gskrendernode.h index 24e49b6385..b79381c251 100644 --- a/gsk/gskrendernode.h +++ b/gsk/gskrendernode.h @@ -89,6 +89,14 @@ GDK_AVAILABLE_IN_ALL GskRenderNode * gsk_render_node_deserialize (GBytes *bytes, GError **error); +GDK_AVAILABLE_IN_ALL +GskRenderNode * gsk_debug_node_new (GskRenderNode *child, + char *message); +GDK_AVAILABLE_IN_ALL +GskRenderNode * gsk_debug_node_get_child (GskRenderNode *node); +GDK_AVAILABLE_IN_ALL +const char * gsk_debug_node_get_message (GskRenderNode *node); + GDK_AVAILABLE_IN_ALL GskRenderNode * gsk_color_node_new (const GdkRGBA *rgba, const graphene_rect_t *bounds); diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index 36c99376ba..190eb5beba 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -2752,6 +2752,177 @@ gsk_offset_node_get_y_offset (GskRenderNode *node) return self->y_offset; } +/*** GSK_DEBUG_NODE ***/ + +typedef struct _GskDebugNode GskDebugNode; + +struct _GskDebugNode +{ + GskRenderNode render_node; + + GskRenderNode *child; + char *message; +}; + +static void +gsk_debug_node_finalize (GskRenderNode *node) +{ + GskDebugNode *self = (GskDebugNode *) node; + + gsk_render_node_unref (self->child); + g_free (self->message); +} + +static void +gsk_debug_node_draw (GskRenderNode *node, + cairo_t *cr) +{ + GskDebugNode *self = (GskDebugNode *) node; + + gsk_render_node_draw (self->child, cr); +} + +static gboolean +gsk_debug_node_can_diff (GskRenderNode *node1, + GskRenderNode *node2) +{ + GskDebugNode *self1 = (GskDebugNode *) node1; + GskDebugNode *self2 = (GskDebugNode *) node2; + + return gsk_render_node_can_diff (self1->child, self2->child); +} + +static void +gsk_debug_node_diff (GskRenderNode *node1, + GskRenderNode *node2, + cairo_region_t *region) +{ + GskDebugNode *self1 = (GskDebugNode *) node1; + GskDebugNode *self2 = (GskDebugNode *) node2; + + gsk_render_node_diff (self1->child, self2->child, region); +} + +#define GSK_DEBUG_NODE_VARIANT_TYPE "(uvs)" + +static GVariant * +gsk_debug_node_serialize (GskRenderNode *node) +{ + GskDebugNode *self = (GskDebugNode *) node; + + return g_variant_new (GSK_DEBUG_NODE_VARIANT_TYPE, + (guint32) gsk_render_node_get_node_type (self->child), + gsk_render_node_serialize_node (self->child), + self->message); +} + +static GskRenderNode * +gsk_debug_node_deserialize (GVariant *variant, + GError **error) +{ + guint32 child_type; + GVariant *child_variant; + char *message; + GskRenderNode *result, *child; + + if (!check_variant_type (variant, GSK_DEBUG_NODE_VARIANT_TYPE, error)) + return NULL; + + g_variant_get (variant, GSK_DEBUG_NODE_VARIANT_TYPE, + &child_type, &child_variant, + &message); + + child = gsk_render_node_deserialize_node (child_type, child_variant, error); + g_variant_unref (child_variant); + + if (child == NULL) + return NULL; + + result = gsk_debug_node_new (child, message); + + gsk_render_node_unref (child); + + return result; +} + +static const GskRenderNodeClass GSK_DEBUG_NODE_CLASS = { + GSK_DEBUG_NODE, + sizeof (GskDebugNode), + "GskDebugNode", + gsk_debug_node_finalize, + gsk_debug_node_draw, + gsk_debug_node_can_diff, + gsk_debug_node_diff, + gsk_debug_node_serialize, + gsk_debug_node_deserialize +}; + +/** + * gsk_debug_node_new: + * @child: The child to add debug info for + * @message: (transfer full): The debug message + * + * Creates a #GskRenderNode that will add debug information about + * the given @child. + * + * Adding this node has no visual effect. + * + * Returns: A new #GskRenderNode + */ +GskRenderNode * +gsk_debug_node_new (GskRenderNode *child, + char *message) +{ + GskDebugNode *self; + + g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL); + + self = (GskDebugNode *) gsk_render_node_new (&GSK_DEBUG_NODE_CLASS, 0); + + self->child = gsk_render_node_ref (child); + self->message = message; + + graphene_rect_init_from_rect (&self->render_node.bounds, &child->bounds); + + return &self->render_node; +} + +/** + * gsk_debug_node_get_child: + * @node: a debug @GskRenderNode + * + * Gets the child node that is getting debug by the given @node. + * + * Returns: (transfer none): The child that is getting debug + **/ +GskRenderNode * +gsk_debug_node_get_child (GskRenderNode *node) +{ + GskDebugNode *self = (GskDebugNode *) node; + + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_DEBUG_NODE), NULL); + + return self->child; +} + +/** + * gsk_debug_node_get_message: + * @node: a debug #GskRenderNode + * + * Gets the debug message that was set on this node + * + * Returns: (transfer none): The debug message + **/ +const char * +gsk_debug_node_get_message (GskRenderNode *node) +{ + GskDebugNode *self = (GskDebugNode *) node; + + g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_DEBUG_NODE), "You run broken code!"); + + return self->message; +} + /*** GSK_OPACITY_NODE ***/ typedef struct _GskOpacityNode GskOpacityNode; diff --git a/gsk/vulkan/gskvulkanrenderpass.c b/gsk/vulkan/gskvulkanrenderpass.c index 9bc38f3006..48e3b2c959 100644 --- a/gsk/vulkan/gskvulkanrenderpass.c +++ b/gsk/vulkan/gskvulkanrenderpass.c @@ -545,6 +545,10 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self, } return; + case GSK_DEBUG_NODE: + gsk_vulkan_render_pass_add_node (self, render, constants, gsk_debug_node_get_child (node)); + return; + case GSK_OFFSET_NODE: case GSK_TRANSFORM_NODE: { diff --git a/gtk/inspector/gtktreemodelrendernode.c b/gtk/inspector/gtktreemodelrendernode.c index 9a52e1c9b2..0203d8b866 100644 --- a/gtk/inspector/gtktreemodelrendernode.c +++ b/gtk/inspector/gtktreemodelrendernode.c @@ -600,6 +600,10 @@ append_node (GtkTreeModelRenderNode *nodemodel, } } break; + + case GSK_DEBUG_NODE: + append_node (nodemodel, gsk_debug_node_get_child (node), priv->nodes->len - 1); + break; } } diff --git a/gtk/inspector/recorder.c b/gtk/inspector/recorder.c index 67cdb49b36..e471bf2126 100644 --- a/gtk/inspector/recorder.c +++ b/gtk/inspector/recorder.c @@ -151,6 +151,8 @@ node_type_name (GskRenderNodeType type) return "Unknown"; case GSK_CONTAINER_NODE: return "Container"; + case GSK_DEBUG_NODE: + return "Debug"; case GSK_CAIRO_NODE: return "Cairo"; case GSK_COLOR_NODE: @@ -626,6 +628,10 @@ populate_render_node_properties (GtkListStore *store, g_free (tmp); break; + case GSK_DEBUG_NODE: + add_text_row (store, "Message", gsk_debug_node_get_message (node)); + break; + case GSK_SHADOW_NODE: { int i;