mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-17 23:50:16 +00:00
colorscale: Cache hue texture
Otherwise we regenerate a new one on every snapshot() call.
This commit is contained in:
parent
6466e53bfc
commit
059d9376da
@ -36,6 +36,7 @@ typedef struct
|
||||
{
|
||||
GdkRGBA color;
|
||||
GtkColorScaleType type;
|
||||
GdkTexture *hue_texture;
|
||||
} GtkColorScalePrivate;
|
||||
|
||||
enum
|
||||
@ -63,7 +64,14 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
|
||||
if (width <= 1 || height <= 1)
|
||||
return;
|
||||
|
||||
if (priv->hue_texture &&
|
||||
(width != gdk_texture_get_width (priv->hue_texture) ||
|
||||
height != gdk_texture_get_height (priv->hue_texture)))
|
||||
g_clear_object (&priv->hue_texture);
|
||||
|
||||
if (priv->type == GTK_COLOR_SCALE_HUE)
|
||||
{
|
||||
if (!priv->hue_texture)
|
||||
{
|
||||
GdkTexture *texture;
|
||||
gint stride;
|
||||
@ -101,7 +109,14 @@ gtk_color_scale_snapshot_trough (GtkColorScale *scale,
|
||||
gtk_snapshot_append_texture (snapshot,
|
||||
texture,
|
||||
&GRAPHENE_RECT_INIT(0, 0, width, height));
|
||||
g_object_unref (texture);
|
||||
priv->hue_texture = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_snapshot_append_texture (snapshot,
|
||||
priv->hue_texture,
|
||||
&GRAPHENE_RECT_INIT(0, 0, width, height));
|
||||
}
|
||||
}
|
||||
else if (priv->type == GTK_COLOR_SCALE_ALPHA)
|
||||
{
|
||||
@ -242,11 +257,22 @@ hold_action (GtkGestureLongPress *gesture,
|
||||
g_signal_emit_by_name (scale, "popup-menu", &handled);
|
||||
}
|
||||
|
||||
static void
|
||||
scale_finalize (GObject *object)
|
||||
{
|
||||
GtkColorScalePrivate *priv = gtk_color_scale_get_instance_private (GTK_COLOR_SCALE (object));
|
||||
|
||||
g_clear_object (&priv->hue_texture);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_scale_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_color_scale_class_init (GtkColorScaleClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
object_class->finalize = scale_finalize;
|
||||
object_class->get_property = scale_get_property;
|
||||
object_class->set_property = scale_set_property;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user