From ee3367697d7175c5b2631e9290d5b1011c9b52b0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 30 Aug 2023 23:35:05 +0200 Subject: [PATCH] gpu: Move pattern code into its own file Now we can extend the pattern creation easily - and we can add new patterns quickly later. Plus, we need to keep this file in sync with pattern.glsl and it's neat when those 2 files reference only each other. --- gsk/gpu/gskgpunodeprocessor.c | 18 ++--- gsk/gpu/gskgpupattern.c | 138 +++++++++++++++++++++++++++++++++ gsk/gpu/gskgpupatternprivate.h | 18 +++++ gsk/meson.build | 1 + 4 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 gsk/gpu/gskgpupattern.c create mode 100644 gsk/gpu/gskgpupatternprivate.h diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index 9da841ec9c..bc2f9b9c95 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -6,9 +6,10 @@ #include "gskgpuframeprivate.h" #include "gskgpuglobalsopprivate.h" #include "gskgpuimageprivate.h" -#include "gskgpuuberopprivate.h" +#include "gskgpupatternprivate.h" #include "gskgpuscissoropprivate.h" #include "gskgputextureopprivate.h" +#include "gskgpuuberopprivate.h" #include "gskgpuuploadopprivate.h" #include "gskdebugprivate.h" @@ -580,19 +581,16 @@ gsk_gpu_node_processor_add_color_node (GskGpuNodeProcessor *self, GskRenderNode *node) { GskGpuBufferWriter writer; - const GdkRGBA *rgba; guint32 pattern_id; gsk_gpu_frame_write_buffer_memory (self->frame, &writer); - rgba = gsk_color_node_get_color (node); -#define GSK_GPU_PATTERN_COLOR 0 - - gsk_gpu_buffer_writer_append_uint (&writer, GSK_GPU_PATTERN_COLOR); - gsk_gpu_buffer_writer_append_float (&writer, rgba->red); - gsk_gpu_buffer_writer_append_float (&writer, rgba->green); - gsk_gpu_buffer_writer_append_float (&writer, rgba->blue); - gsk_gpu_buffer_writer_append_float (&writer, rgba->alpha); + if (!gsk_gpu_pattern_create_for_node (&writer, node)) + { + g_assert_not_reached (); + gsk_gpu_buffer_writer_abort (&writer); + return; + } pattern_id = gsk_gpu_buffer_writer_commit (&writer) / sizeof (float); diff --git a/gsk/gpu/gskgpupattern.c b/gsk/gpu/gskgpupattern.c new file mode 100644 index 0000000000..e1dc87b1c2 --- /dev/null +++ b/gsk/gpu/gskgpupattern.c @@ -0,0 +1,138 @@ +#include "config.h" + +#include "gskgpupatternprivate.h" + +#include "gskrendernode.h" + +static gboolean +gsk_gpu_pattern_create_for_color_node (GskGpuBufferWriter *writer, + GskRenderNode *node) +{ + const GdkRGBA *rgba; + + rgba = gsk_color_node_get_color (node); + + gsk_gpu_buffer_writer_append_uint (writer, GSK_GPU_PATTERN_COLOR); + gsk_gpu_buffer_writer_append_float (writer, rgba->red); + gsk_gpu_buffer_writer_append_float (writer, rgba->green); + gsk_gpu_buffer_writer_append_float (writer, rgba->blue); + gsk_gpu_buffer_writer_append_float (writer, rgba->alpha); + + return TRUE; +} + +static const struct +{ + gboolean (* create_for_node) (GskGpuBufferWriter *writer, + GskRenderNode *node); +} nodes_vtable[] = { + [GSK_NOT_A_RENDER_NODE] = { + NULL, + }, + [GSK_CONTAINER_NODE] = { + NULL, + }, + [GSK_CAIRO_NODE] = { + NULL, + }, + [GSK_COLOR_NODE] = { + gsk_gpu_pattern_create_for_color_node, + }, + [GSK_LINEAR_GRADIENT_NODE] = { + NULL, + }, + [GSK_REPEATING_LINEAR_GRADIENT_NODE] = { + NULL, + }, + [GSK_RADIAL_GRADIENT_NODE] = { + NULL, + }, + [GSK_REPEATING_RADIAL_GRADIENT_NODE] = { + NULL, + }, + [GSK_CONIC_GRADIENT_NODE] = { + NULL, + }, + [GSK_BORDER_NODE] = { + NULL, + }, + [GSK_TEXTURE_NODE] = { + NULL, + }, + [GSK_INSET_SHADOW_NODE] = { + NULL, + }, + [GSK_OUTSET_SHADOW_NODE] = { + NULL, + }, + [GSK_TRANSFORM_NODE] = { + NULL, + }, + [GSK_OPACITY_NODE] = { + NULL, + }, + [GSK_COLOR_MATRIX_NODE] = { + NULL, + }, + [GSK_REPEAT_NODE] = { + NULL, + }, + [GSK_CLIP_NODE] = { + NULL, + }, + [GSK_ROUNDED_CLIP_NODE] = { + NULL, + }, + [GSK_SHADOW_NODE] = { + NULL, + }, + [GSK_BLEND_NODE] = { + NULL, + }, + [GSK_CROSS_FADE_NODE] = { + NULL, + }, + [GSK_TEXT_NODE] = { + NULL, + }, + [GSK_BLUR_NODE] = { + NULL, + }, + [GSK_DEBUG_NODE] = { + NULL, + }, + [GSK_GL_SHADER_NODE] = { + NULL, + }, + [GSK_TEXTURE_SCALE_NODE] = { + NULL, + }, + [GSK_MASK_NODE] = { + NULL, + }, + [GSK_FILL_NODE] = { + NULL, + }, + [GSK_STROKE_NODE] = { + NULL, + }, +}; + +gboolean +gsk_gpu_pattern_create_for_node (GskGpuBufferWriter *writer, + GskRenderNode *node) +{ + GskRenderNodeType node_type; + + node_type = gsk_render_node_get_node_type (node); + if (node_type >= G_N_ELEMENTS (nodes_vtable)) + { + g_critical ("unkonwn node type %u for %s", node_type, g_type_name_from_instance ((GTypeInstance *) node)); + return FALSE; + } + + if (nodes_vtable[node_type].create_for_node == NULL) + return FALSE; + + return nodes_vtable[node_type].create_for_node (writer, node); +} diff --git a/gsk/gpu/gskgpupatternprivate.h b/gsk/gpu/gskgpupatternprivate.h new file mode 100644 index 0000000000..39993dfe03 --- /dev/null +++ b/gsk/gpu/gskgpupatternprivate.h @@ -0,0 +1,18 @@ +#pragma once + +#include "gskgpubufferwriterprivate.h" + +#include "gsktypes.h" + +G_BEGIN_DECLS + +typedef enum { + GSK_GPU_PATTERN_COLOR, +} GskGpuPatternType; + +gboolean gsk_gpu_pattern_create_for_node (GskGpuBufferWriter *writer, + GskRenderNode *node); + + +G_END_DECLS + diff --git a/gsk/meson.build b/gsk/meson.build index fd8e7b7394..413d6916ec 100644 --- a/gsk/meson.build +++ b/gsk/meson.build @@ -82,6 +82,7 @@ gsk_private_sources = files([ 'gpu/gskgpuimage.c', 'gpu/gskgpunodeprocessor.c', 'gpu/gskgpuop.c', + 'gpu/gskgpupattern.c', 'gpu/gskgpuprint.c', 'gpu/gskgpurenderer.c', 'gpu/gskgpurenderpassop.c',