inspector: Show more color node details

Show the color state, and create textures with the full color
information.
This commit is contained in:
Matthias Clasen
2024-08-01 21:20:47 -04:00
parent d6a6cfe6c5
commit 96cd47d0a0

View File

@@ -56,6 +56,7 @@
#include <gdk/gdksurfaceprivate.h>
#include <gdk/gdktextureprivate.h>
#include <gdk/gdkrgbaprivate.h>
#include <gdk/gdkcolorstateprivate.h>
#include "gtk/gtkdebug.h"
#include "gtk/gtkbuiltiniconprivate.h"
#include "gtk/gtkrendernodepaintableprivate.h"
@@ -506,7 +507,7 @@ node_name (GskRenderNode *node)
return g_strdup (gsk_debug_node_get_message (node));
case GSK_COLOR_NODE:
return gdk_rgba_to_string (gsk_color_node_get_color (node));
return gdk_color_to_string (gsk_color_node_get_color2 (node));
case GSK_TEXTURE_NODE:
{
@@ -793,38 +794,51 @@ recording_selected (GtkSingleSelection *selection,
}
static GdkTexture *
get_color_texture (const GdkRGBA *color)
get_color2_texture (const GdkColor *color)
{
GdkMemoryTextureBuilder *builder;
GdkTexture *texture;
guchar pixel[4];
gsize stride;
guchar *data;
GBytes *bytes;
int width = 30;
int height = 30;
int i;
pixel[0] = round (color->red * 255);
pixel[1] = round (color->green * 255);
pixel[2] = round (color->blue * 255);
pixel[3] = round (color->alpha * 255);
stride = width * 4 * sizeof (float);
data = g_malloc (stride * height);
for (int i = 0; i < width * height; i++)
memcpy (data + 4 * sizeof (float) * i, color->values, 4 * sizeof (float));
data = g_malloc (4 * width * height);
for (i = 0; i < width * height; i++)
{
memcpy (data + 4 * i, pixel, 4);
}
bytes = g_bytes_new_take (data, stride * height);
builder = gdk_memory_texture_builder_new ();
gdk_memory_texture_builder_set_bytes (builder, bytes);
gdk_memory_texture_builder_set_stride (builder, stride);
gdk_memory_texture_builder_set_width (builder, 30);
gdk_memory_texture_builder_set_height (builder, 30);
gdk_memory_texture_builder_set_format (builder, GDK_MEMORY_R32G32B32A32_FLOAT);
gdk_memory_texture_builder_set_color_state (builder, color->color_state);
texture = gdk_memory_texture_builder_build (builder);
bytes = g_bytes_new_take (data, 4 * width * height);
texture = gdk_memory_texture_new (width,
height,
GDK_MEMORY_R8G8B8A8,
bytes,
width * 4);
g_bytes_unref (bytes);
return texture;
}
static GdkTexture *
get_color_texture (const GdkRGBA *rgba)
{
GdkColor color;
GdkTexture *texture;
gdk_color_init_from_rgba (&color, rgba);
texture = get_color2_texture (&color);
gdk_color_finish (&color);
return texture;
}
static GdkTexture *
get_linear_gradient_texture (gsize n_stops, const GskColorStop *stops)
{
@@ -907,6 +921,21 @@ add_color_row (GListStore *store,
g_object_unref (texture);
}
static void
add_color2_row (GListStore *store,
const char *name,
const GdkColor *color)
{
char *text;
GdkTexture *texture;
text = gdk_color_to_string (color);
texture = get_color2_texture (color);
list_store_add_object_property (store, name, text, texture);
g_free (text);
g_object_unref (texture);
}
static void
add_int_row (GListStore *store,
const char *name,
@@ -1067,7 +1096,7 @@ populate_render_node_properties (GListStore *store,
break;
case GSK_COLOR_NODE:
add_color_row (store, "Color", gsk_color_node_get_color (node));
add_color2_row (store, "Color", gsk_color_node_get_color2 (node));
break;
case GSK_LINEAR_GRADIENT_NODE: