2023-07-20 19:09:27 +00:00
|
|
|
/* Copyright 2023 Red Hat, Inc.
|
|
|
|
*
|
2023-07-21 11:05:25 +00:00
|
|
|
* GTK is free software; you can redistribute it and/or modify it
|
2023-07-20 19:09:27 +00:00
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
2023-07-21 11:05:25 +00:00
|
|
|
* GTK is distributed in the hope that it will be useful,
|
2023-07-20 19:09:27 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2023-07-21 11:05:25 +00:00
|
|
|
* License along with GTK; see the file COPYING. If not,
|
2023-07-20 19:09:27 +00:00
|
|
|
* see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Matthias Clasen
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include "gtk-rendernode-tool.h"
|
|
|
|
|
2023-10-29 15:48:16 +00:00
|
|
|
#define N_NODE_TYPES (GSK_SUBSURFACE_NODE + 1)
|
2023-07-20 19:09:27 +00:00
|
|
|
static void
|
|
|
|
count_nodes (GskRenderNode *node,
|
|
|
|
unsigned int *counts,
|
|
|
|
unsigned int *depth)
|
|
|
|
{
|
|
|
|
unsigned int d, dd;
|
|
|
|
|
|
|
|
counts[gsk_render_node_get_node_type (node)] += 1;
|
2023-08-27 19:02:03 +00:00
|
|
|
g_assert (gsk_render_node_get_node_type (node) < N_NODE_TYPES);
|
2023-07-20 19:09:27 +00:00
|
|
|
d = 0;
|
|
|
|
|
|
|
|
switch (gsk_render_node_get_node_type (node))
|
|
|
|
{
|
|
|
|
case GSK_CONTAINER_NODE:
|
|
|
|
for (unsigned int i = 0; i < gsk_container_node_get_n_children (node); i++)
|
|
|
|
{
|
|
|
|
count_nodes (gsk_container_node_get_child (node, i), counts, &dd);
|
|
|
|
d = MAX (d, dd);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CAIRO_NODE:
|
|
|
|
case GSK_COLOR_NODE:
|
|
|
|
case GSK_LINEAR_GRADIENT_NODE:
|
|
|
|
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
|
|
|
|
case GSK_RADIAL_GRADIENT_NODE:
|
|
|
|
case GSK_REPEATING_RADIAL_GRADIENT_NODE:
|
|
|
|
case GSK_CONIC_GRADIENT_NODE:
|
|
|
|
case GSK_BORDER_NODE:
|
|
|
|
case GSK_TEXTURE_NODE:
|
|
|
|
case GSK_INSET_SHADOW_NODE:
|
|
|
|
case GSK_OUTSET_SHADOW_NODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TRANSFORM_NODE:
|
|
|
|
count_nodes (gsk_transform_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_OPACITY_NODE:
|
|
|
|
count_nodes (gsk_opacity_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_COLOR_MATRIX_NODE:
|
|
|
|
count_nodes (gsk_color_matrix_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_REPEAT_NODE:
|
|
|
|
count_nodes (gsk_repeat_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CLIP_NODE:
|
|
|
|
count_nodes (gsk_clip_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_ROUNDED_CLIP_NODE:
|
|
|
|
count_nodes (gsk_rounded_clip_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_SHADOW_NODE:
|
|
|
|
count_nodes (gsk_shadow_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_BLEND_NODE:
|
|
|
|
count_nodes (gsk_blend_node_get_bottom_child (node), counts, &d);
|
|
|
|
count_nodes (gsk_blend_node_get_top_child (node), counts, &dd);
|
|
|
|
d = MAX (d, dd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_CROSS_FADE_NODE:
|
|
|
|
count_nodes (gsk_cross_fade_node_get_start_child (node), counts, &d);
|
|
|
|
count_nodes (gsk_cross_fade_node_get_end_child (node), counts, &dd);
|
|
|
|
d = MAX (d, dd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TEXT_NODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_BLUR_NODE:
|
|
|
|
count_nodes (gsk_blur_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_DEBUG_NODE:
|
|
|
|
count_nodes (gsk_debug_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_GL_SHADER_NODE:
|
2024-07-04 16:12:16 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2023-07-20 19:09:27 +00:00
|
|
|
for (unsigned int i = 0; i < gsk_gl_shader_node_get_n_children (node); i++)
|
|
|
|
{
|
|
|
|
count_nodes (gsk_gl_shader_node_get_child (node, i), counts, &dd);
|
|
|
|
d = MAX (d, dd);
|
|
|
|
}
|
2024-07-04 16:12:16 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2023-07-20 19:09:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_TEXTURE_SCALE_NODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GSK_MASK_NODE:
|
|
|
|
count_nodes (gsk_mask_node_get_source (node), counts, &d);
|
|
|
|
count_nodes (gsk_mask_node_get_mask (node), counts, &dd);
|
|
|
|
d = MAX (d, dd);
|
|
|
|
break;
|
|
|
|
|
2020-11-10 23:44:32 +00:00
|
|
|
case GSK_FILL_NODE:
|
|
|
|
count_nodes (gsk_fill_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
2020-11-11 06:36:04 +00:00
|
|
|
case GSK_STROKE_NODE:
|
|
|
|
count_nodes (gsk_stroke_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
2023-10-29 15:48:16 +00:00
|
|
|
case GSK_SUBSURFACE_NODE:
|
|
|
|
count_nodes (gsk_subsurface_node_get_child (node), counts, &d);
|
|
|
|
break;
|
|
|
|
|
2023-07-20 19:09:27 +00:00
|
|
|
case GSK_NOT_A_RENDER_NODE:
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
*depth = d + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_node_name (GskRenderNodeType type)
|
|
|
|
{
|
|
|
|
GEnumClass *class;
|
|
|
|
GEnumValue *value;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
class = g_type_class_ref (GSK_TYPE_RENDER_NODE_TYPE);
|
|
|
|
value = g_enum_get_value (class, type);
|
|
|
|
name = value->value_nick;
|
|
|
|
g_type_class_unref (class);
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
file_info (const char *filename)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
2023-08-27 19:02:03 +00:00
|
|
|
unsigned int counts[N_NODE_TYPES] = { 0, };
|
2023-07-20 19:09:27 +00:00
|
|
|
unsigned int total = 0;
|
|
|
|
unsigned int namelen = 0;
|
|
|
|
unsigned int depth = 0;
|
2024-07-07 16:01:31 +00:00
|
|
|
graphene_rect_t bounds, opaque;
|
2023-07-20 19:09:27 +00:00
|
|
|
|
|
|
|
node = load_node_file (filename);
|
|
|
|
|
|
|
|
count_nodes (node, counts, &depth);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < G_N_ELEMENTS (counts); i++)
|
|
|
|
{
|
|
|
|
total += counts[i];
|
|
|
|
if (counts[i] > 0)
|
|
|
|
namelen = MAX (namelen, strlen (get_node_name (i)));
|
|
|
|
}
|
|
|
|
|
2024-07-26 00:04:35 +00:00
|
|
|
g_print ("%s %u\n", _("Number of nodes:"), total);
|
2023-07-20 19:09:27 +00:00
|
|
|
for (unsigned int i = 0; i < G_N_ELEMENTS (counts); i++)
|
|
|
|
{
|
|
|
|
if (counts[i] > 0)
|
|
|
|
g_print (" %*s: %u\n", namelen, get_node_name (i), counts[i]);
|
|
|
|
}
|
|
|
|
|
2024-07-26 00:04:35 +00:00
|
|
|
g_print ("%s %u\n", _("Depth:"), depth);
|
2023-07-20 19:09:27 +00:00
|
|
|
|
|
|
|
gsk_render_node_get_bounds (node, &bounds);
|
2024-07-26 00:04:35 +00:00
|
|
|
g_print ("%s %g x %g\n", _("Bounds:"), bounds.size.width, bounds.size.height);
|
|
|
|
g_print ("%s %g %g\n", _("Origin:"), bounds.origin.x, bounds.origin.y);
|
2024-07-07 16:01:31 +00:00
|
|
|
if (gsk_render_node_get_opaque_rect (node, &opaque))
|
|
|
|
{
|
2024-07-26 00:04:35 +00:00
|
|
|
g_print ("%s %g %g, %g x %g (%.0f%%)\n",
|
|
|
|
_("Opaque part:"),
|
2024-07-07 16:01:31 +00:00
|
|
|
opaque.origin.x, opaque.origin.y,
|
|
|
|
opaque.size.width, opaque.size.height,
|
|
|
|
100 * (opaque.size.width * opaque.size.height) / (bounds.size.width * bounds.size.height));
|
|
|
|
}
|
|
|
|
else
|
2024-07-26 00:04:35 +00:00
|
|
|
g_print ("%s none\n", _("Opaque part:"));
|
2023-07-20 19:09:27 +00:00
|
|
|
|
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
do_info (int *argc,
|
|
|
|
const char ***argv)
|
|
|
|
{
|
|
|
|
GOptionContext *context;
|
|
|
|
char **filenames = NULL;
|
|
|
|
const GOptionEntry entries[] = {
|
|
|
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
|
|
|
|
{ NULL, }
|
|
|
|
};
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_set_prgname ("gtk4-rendernode-tool info");
|
|
|
|
context = g_option_context_new (NULL);
|
|
|
|
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
|
|
|
|
g_option_context_add_main_entries (context, entries, NULL);
|
|
|
|
g_option_context_set_summary (context, _("Provide information about the render node."));
|
|
|
|
|
|
|
|
if (!g_option_context_parse (context, argc, (char ***)argv, &error))
|
|
|
|
{
|
|
|
|
g_printerr ("%s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_option_context_free (context);
|
|
|
|
|
|
|
|
if (filenames == NULL)
|
|
|
|
{
|
|
|
|
g_printerr (_("No .node file specified\n"));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strv_length (filenames) > 1)
|
|
|
|
{
|
|
|
|
g_printerr (_("Can only accept a single .node file\n"));
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
file_info (filenames[0]);
|
|
|
|
|
|
|
|
g_strfreev (filenames);
|
|
|
|
}
|