[gtk/wip/chergert/glproto: 315/493] cleanup handling of opacity nodes




commit fb99489a5079eb4d8759e23600b6aa2857398c9d
Author: Christian Hergert <chergert redhat com>
Date:   Fri Jan 29 15:21:48 2021 -0800

    cleanup handling of opacity nodes

 gsk/next/gskglrenderjob.c | 68 +++++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 32 deletions(-)
---
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index d4054ee73a..f97c2192e2 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -2540,44 +2540,48 @@ gsk_gl_render_job_visit_opacity_node (GskGLRenderJob *job,
 {
   GskRenderNode *child = gsk_opacity_node_get_child (node);
   float opacity = gsk_opacity_node_get_opacity (node);
+  float prev_alpha = job->alpha;
+  float new_alpha = job->alpha * opacity;
 
-  if (gsk_render_node_get_node_type (child) == GSK_CONTAINER_NODE)
+  if (new_alpha >= ((float)0x00ff / (float)0xffff))
     {
-      GskGLRenderOffscreen offscreen = {0};
-
-      /* The semantics of an opacity node mandate that when, e.g., two
-       * color nodes overlap, there may not be any blending between them.
-       */
+      if (gsk_render_node_get_node_type (child) == GSK_CONTAINER_NODE)
+        {
+          GskGLRenderOffscreen offscreen = {0};
 
-      offscreen.bounds = &child->bounds;
-      offscreen.force_offscreen = TRUE;
-      offscreen.reset_clip = TRUE;
+          offscreen.bounds = &child->bounds;
+          offscreen.force_offscreen = TRUE;
+          offscreen.reset_clip = TRUE;
 
-      gsk_gl_render_job_visit_node_with_offscreen (job, child, &offscreen);
+          /* The semantics of an opacity node mandate that when, e.g., two
+           * color nodes overlap, there may not be any blending between them.
+           */
+          if (!gsk_gl_render_job_visit_node_with_offscreen (job, child, &offscreen))
+            return;
 
-      g_assert (offscreen.texture_id);
+          g_assert (offscreen.texture_id);
+          g_assert (job->alpha == prev_alpha);
 
-      gsk_gl_program_begin_draw (job->driver->blit,
-                                 &job->viewport,
-                                 &job->projection,
-                                 gsk_gl_render_job_get_modelview_matrix (job),
-                                 gsk_gl_render_job_get_clip (job),
-                                 job->alpha * opacity);
-      gsk_gl_program_set_uniform_texture (job->driver->blit,
-                                          UNIFORM_SHARED_SOURCE,
-                                          GL_TEXTURE_2D,
-                                          GL_TEXTURE0,
-                                          offscreen.texture_id);
-      gsk_gl_render_job_load_vertices_from_offscreen (job, &node->bounds, &offscreen);
-      gsk_gl_program_end_draw (job->driver->blit);
-    }
-  else
-    {
-      float prev_alpha = job->alpha;
-
-      job->alpha = job->alpha * opacity;
-      gsk_gl_render_job_visit_node (job, child);
-      job->alpha = prev_alpha;
+          gsk_gl_program_begin_draw (job->driver->blit,
+                                     &job->viewport,
+                                     &job->projection,
+                                     gsk_gl_render_job_get_modelview_matrix (job),
+                                     gsk_gl_render_job_get_clip (job),
+                                     new_alpha);
+          gsk_gl_program_set_uniform_texture (job->driver->blit,
+                                              UNIFORM_SHARED_SOURCE,
+                                              GL_TEXTURE_2D,
+                                              GL_TEXTURE0,
+                                              offscreen.texture_id);
+          gsk_gl_render_job_load_vertices_from_offscreen (job, &node->bounds, &offscreen);
+          gsk_gl_program_end_draw (job->driver->blit);
+        }
+      else
+        {
+          job->alpha = new_alpha;
+          gsk_gl_render_job_visit_node (job, child);
+          job->alpha = prev_alpha;
+        }
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]