hsv: keep the color wheel pixels alive with the surface

Taken from Ardour's YTK.
This commit is contained in:
Daemonratte 2026-10-18 11:15:25 +02:00
commit 876be6d47b

View file

@ -873,6 +873,8 @@ gtk_hsv_motion (GtkWidget *widget,
/* Redrawing */
/* Paints the hue ring */
static const cairo_user_data_key_t pixels_key;
static void
paint_ring (GtkHSV *hsv,
cairo_t *cr,
@ -953,6 +955,9 @@ paint_ring (GtkHSV *hsv,
source = cairo_image_surface_create_for_data ((unsigned char *)buf,
CAIRO_FORMAT_RGB24,
width, height, stride);
/* the pixels live as long as the surface: cairo may still use them
* after the drawing here, as cairo-quartz does (Ardour found it) */
cairo_surface_set_user_data (source, &pixels_key, buf, g_free);
/* Now draw the value marker onto the source image, so that it
* will get properly clipped at the edges of the ring
@ -992,8 +997,6 @@ paint_ring (GtkHSV *hsv,
cairo_stroke (cr);
cairo_restore (cr);
g_free (buf);
}
/* Converts an HSV triplet to an integer RGB triplet */
@ -1165,6 +1168,9 @@ paint_triangle (GtkHSV *hsv,
source = cairo_image_surface_create_for_data ((unsigned char *)buf,
CAIRO_FORMAT_RGB24,
width, height, stride);
/* the pixels live as long as the surface: cairo may still use them
* after the drawing here, as cairo-quartz does (Ardour found it) */
cairo_surface_set_user_data (source, &pixels_key, buf, g_free);
/* Draw a triangle with the image as a source */
@ -1177,8 +1183,6 @@ paint_triangle (GtkHSV *hsv,
cairo_close_path (cr);
cairo_fill (cr);
g_free (buf);
/* Draw value marker */
xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5);