gl renderer: Look at shadow color in the outset shadow cache
authorTimm Bäder <mail@baedert.org>
Sat, 11 Jan 2020 10:26:27 +0000 (11:26 +0100)
committerTimm Bäder <mail@baedert.org>
Sat, 18 Jan 2020 07:49:51 +0000 (08:49 +0100)
It would probably be better to not do this and always render the outline
in plain white, then later recolor it but do this for no, just for
correctness.

gsk/gl/gskglrenderer.c
gsk/gl/gskglshadowcache.c
gsk/gl/gskglshadowcacheprivate.h

index fc136956546dc19bb01e8eff0ef80ffc6c8927a4..91de970cac6ea8a8ce942ad382903fec73d8b91d 100644 (file)
@@ -1652,6 +1652,7 @@ render_outset_shadow_node (GskGLRenderer   *self,
 {
   const float scale = ops_get_scale (builder);
   const GskRoundedRect *outline = gsk_outset_shadow_node_peek_outline (node);
+  const GdkRGBA *color = gsk_outset_shadow_node_peek_color (node);
   const float blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
   const float blur_extra = blur_radius * 3; /* 3 Because we use that in the shader as well */
   const float spread = gsk_outset_shadow_node_get_spread (node);
@@ -1696,6 +1697,7 @@ render_outset_shadow_node (GskGLRenderer   *self,
   cached_tid = gsk_gl_shadow_cache_get_texture_id (&self->shadow_cache,
                                                    self->gl_driver,
                                                    &scaled_outline,
+                                                   color,
                                                    blur_radius);
 
   if (cached_tid == 0)
@@ -1727,7 +1729,7 @@ render_outset_shadow_node (GskGLRenderer   *self,
       /* Draw outline */
       ops_set_program (builder, &self->color_program);
       ops_push_clip (builder, &scaled_outline);
-      ops_set_color (builder, gsk_outset_shadow_node_peek_color (node));
+      ops_set_color (builder, color);
       ops_draw (builder, (GskQuadVertex[GL_N_VERTICES]) {
         { { 0,                            }, { 0, 1 }, },
         { { 0,             texture_height }, { 0, 0 }, },
@@ -1754,6 +1756,7 @@ render_outset_shadow_node (GskGLRenderer   *self,
       gsk_gl_driver_mark_texture_permanent (self->gl_driver, blurred_texture_id);
       gsk_gl_shadow_cache_commit (&self->shadow_cache,
                                   &scaled_outline,
+                                  color,
                                   blur_radius,
                                   blurred_texture_id);
     }
index 537989b8051b6965379d3f157ef0e40615b4e750..57ef600403fb66f49fffff2b08fe9f057773ad60 100644 (file)
@@ -7,12 +7,14 @@ typedef struct
 {
   GskRoundedRect outline;
   float blur_radius;
+  GdkRGBA color;
 } CacheKey;
 
 typedef struct
 {
   GskRoundedRect outline;
   float blur_radius;
+  GdkRGBA color;
 
   int texture_id;
   int unused_frames;
@@ -25,12 +27,13 @@ key_equal (const void *x,
   const CacheKey *a = x;
   const CacheKey *b = y;
 
-  return graphene_size_equal (&a->outline.corner[0], &b->outline.corner[0]) &&
+  return a->blur_radius == b->blur_radius &&
+         graphene_size_equal (&a->outline.corner[0], &b->outline.corner[0]) &&
          graphene_size_equal (&a->outline.corner[1], &b->outline.corner[1]) &&
          graphene_size_equal (&a->outline.corner[2], &b->outline.corner[2]) &&
          graphene_size_equal (&a->outline.corner[3], &b->outline.corner[3]) &&
          graphene_rect_equal (&a->outline.bounds, &b->outline.bounds) &&
-         a->blur_radius == b->blur_radius;
+         gdk_rgba_equal (&a->color, &b->color);
 }
 
 void
@@ -88,6 +91,7 @@ int
 gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache     *self,
                                     GskGLDriver          *gl_driver,
                                     const GskRoundedRect *shadow_rect,
+                                    const GdkRGBA        *color,
                                     float                 blur_radius)
 {
   CacheItem *item= NULL;
@@ -101,8 +105,8 @@ gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache     *self,
     {
       CacheItem *k = &g_array_index (self->textures, CacheItem, i);
 
-      if (key_equal (&(CacheKey){*shadow_rect, blur_radius},
-                     &(CacheKey){k->outline, k->blur_radius}))
+      if (key_equal (&(CacheKey){*shadow_rect, blur_radius, *color},
+                     &(CacheKey){k->outline, k->blur_radius, k->color}))
         {
           item = k;
           break;
@@ -122,6 +126,7 @@ gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache     *self,
 void
 gsk_gl_shadow_cache_commit (GskGLShadowCache     *self,
                             const GskRoundedRect *shadow_rect,
+                            const GdkRGBA        *color,
                             float                 blur_radius,
                             int                   texture_id)
 {
@@ -135,6 +140,7 @@ gsk_gl_shadow_cache_commit (GskGLShadowCache     *self,
   item = &g_array_index (self->textures, CacheItem, self->textures->len - 1);
 
   item->outline = *shadow_rect;
+  item->color = *color;
   item->blur_radius = blur_radius;
   item->unused_frames = 0;
   item->texture_id = texture_id;
index 6623f1623595ec3c7c3be6379177b912b43d5259..d4b03cc2a9e1dd281f25db50eb8a102b7972e908 100644 (file)
@@ -21,9 +21,11 @@ void gsk_gl_shadow_cache_begin_frame    (GskGLShadowCache     *self,
 int  gsk_gl_shadow_cache_get_texture_id (GskGLShadowCache     *self,
                                          GskGLDriver          *gl_driver,
                                          const GskRoundedRect *shadow_rect,
+                                         const GdkRGBA        *color,
                                          float                 blur_radius);
 void gsk_gl_shadow_cache_commit         (GskGLShadowCache     *self,
                                          const GskRoundedRect *shadow_rect,
+                                         const GdkRGBA        *color,
                                          float                 blur_radius,
                                          int                   texture_id);