From aaa68954c34a31fb95b717f2fed6736037e0d644 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 15 Jul 2021 13:14:13 -0400 Subject: [PATCH 1/3] snapshot: Handle transparent opacity nodes correctly Eliding totally transparent content from the node tree is not 100% correct, since filters can make things visible, so we need to at least preserve the bounds. We can do that by creating a transparent color node. --- gtk/gtksnapshot.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index b0b1222c66..ad5533982a 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -30,6 +30,8 @@ #include "gtkstylecontextprivate.h" #include "gsktransformprivate.h" +#include "gdk/gdkrgbaprivate.h" + #include "gsk/gskrendernodeprivate.h" #include "gsk/gskroundedrectprivate.h" @@ -461,8 +463,12 @@ gtk_snapshot_collect_opacity (GtkSnapshot *snapshot, } else if (state->data.opacity.opacity == 0.0) { + GdkRGBA color = GDK_RGBA ("00000000"); + graphene_rect_t bounds; + + gsk_render_node_get_bounds (node, &bounds); + opacity_node = gsk_color_node_new (&color, &bounds); gsk_render_node_unref (node); - opacity_node = NULL; } else { From fd48afb77d27c6d0402f7938e73b4315cb8842c3 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 15 Jul 2021 13:16:37 -0400 Subject: [PATCH 2/3] ngl: Do nothing for transparent color nodes No need to send commands to the GPU to render transparency. --- gsk/ngl/gsknglrenderjob.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c index b876e6e248..8785766612 100644 --- a/gsk/ngl/gsknglrenderjob.c +++ b/gsk/ngl/gsknglrenderjob.c @@ -1373,11 +1373,16 @@ static inline void gsk_ngl_render_job_visit_color_node (GskNglRenderJob *job, const GskRenderNode *node) { + const GdkRGBA *rgba; guint16 color[4]; GskNglProgram *program; GskNglCommandBatch *batch; - rgba_to_half (gsk_color_node_get_color (node), color); + rgba = gsk_color_node_get_color (node); + if (gdk_rgba_is_clear (rgba)) + return; + + rgba_to_half (rgba, color); /* Avoid switching away from the coloring program for * rendering a solid color. From c799452973ff17cfcc918c681895f80246e1086b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 15 Jul 2021 13:17:17 -0400 Subject: [PATCH 3/3] ngl: Do nothing for transparent text nodes Like the previous commit - a transparent text node will not produce any visible pixels, so bail out early. --- gsk/ngl/gsknglrenderjob.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gsk/ngl/gsknglrenderjob.c b/gsk/ngl/gsknglrenderjob.c index 8785766612..3f36d506ab 100644 --- a/gsk/ngl/gsknglrenderjob.c +++ b/gsk/ngl/gsknglrenderjob.c @@ -2850,7 +2850,12 @@ gsk_ngl_render_job_visit_text_node (GskNglRenderJob *job, * We tell the shader by setting the color to vec4(-1). */ if (force_color || !gsk_text_node_has_color_glyphs (node)) - rgba_to_half (color, c); + { + if (gdk_rgba_is_clear (color)) + return; + + rgba_to_half (color, c); + } lookup.font = (PangoFont *)font; lookup.scale = (guint) (text_scale * 1024);