https://bugs.kde.org/show_bug.cgi?id=468203

--- Comment #21 from Fushan Wen <qydwhotm...@gmail.com> ---
For anyone interested, I think this is still a bug in GTK3(Wayland only) and
GTK4. See `gtk_css_image_surface_draw` for example, image_width and
image_height are hardcoded values (For GTK3 it's 18 on Wayland, 50 on X11),
which means when the size of a background image exceeds 18x18 on Wayland, it
will be blurry.


```
static void
gtk_css_image_surface_draw (GtkCssImage *image,
                            cairo_t     *cr,
                            double       width,
                            double       height)
{
  GtkCssImageSurface *surface = GTK_CSS_IMAGE_SURFACE (image);
  int image_width, image_height;

  image_width = cairo_image_surface_get_width (surface->surface);
  image_height = cairo_image_surface_get_height (surface->surface);

  if (image_width == 0 || image_height == 0 || width <= 0 || height <= 0)
    return;

  /* Update cache image if size is different */
  if (surface->cache == NULL   ||
      ABS (width - surface->width) > 0.001 ||
      ABS (height - surface->height) > 0.001)
    {
      double xscale, yscale;
      cairo_t *cache;

      /* We need the device scale (HiDPI mode) to calculate the proper size in
       * pixels for the image surface and set the cache device scale
       */
      cairo_surface_get_device_scale (cairo_get_target (cr), &xscale, &yscale);

      /* Save original size to preserve precision */
      surface->width = width;
      surface->height = height;

      /* Destroy old cache if any */
      g_clear_pointer (&surface->cache, cairo_surface_destroy);

      /* Image big enough to contain scaled image with subpixel precision */
      surface->cache = cairo_surface_create_similar_image (surface->surface,
                                                           CAIRO_FORMAT_ARGB32,
                                                           ceil (width*xscale),
                                                           ceil
(height*yscale));
      cairo_surface_set_device_scale (surface->cache, xscale, yscale);
      cache = cairo_create (surface->cache);
      cairo_rectangle (cache, 0, 0, width, height);
      cairo_scale (cache, width / image_width, height / image_height);
      cairo_set_source_surface (cache, surface->surface, 0, 0);
      cairo_fill (cache);

      cairo_destroy (cache);
    }

  cairo_rectangle (cr, 0, 0, width, height);
  cairo_set_source_surface (cr, surface->cache ? surface->cache :
surface->surface, 0, 0);
  cairo_fill (cr);
}
```

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to