mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 22:30:22 +00:00
stylecontext: add gtk_render_icon_surface
This draws an icon from a cairo_surface. We want to use this more rather than render_icon as this means we can skip the pixbuf to surface conversion (including allocation and alpha premultiplication) at render time, plus we can use create_similar_image which may allow faster rendering.
This commit is contained in:
parent
1d0bb3e010
commit
91a268f00e
@ -4512,6 +4512,42 @@ gtk_render_icon (GtkStyleContext *context,
|
|||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_render_icon_surface:
|
||||||
|
* @context: a #GtkStyleContext
|
||||||
|
* @cr: a #cairo_t
|
||||||
|
* @surface: a #cairo_surface_t containing the icon to draw
|
||||||
|
* @x: X position for the @icon
|
||||||
|
* @y: Y position for the @incon
|
||||||
|
*
|
||||||
|
* Renders the icon in @surface at the specified @x and @y coordinates.
|
||||||
|
*
|
||||||
|
* Since: 3.10
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
gtk_render_icon_surface (GtkStyleContext *context,
|
||||||
|
cairo_t *cr,
|
||||||
|
cairo_surface_t *surface,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y)
|
||||||
|
{
|
||||||
|
GtkThemingEngineClass *engine_class;
|
||||||
|
GtkThemingEngine *engine;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
||||||
|
g_return_if_fail (cr != NULL);
|
||||||
|
|
||||||
|
engine = _gtk_css_engine_value_get_engine (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ENGINE));
|
||||||
|
engine_class = GTK_THEMING_ENGINE_GET_CLASS (engine);
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
|
||||||
|
_gtk_theming_engine_set_context (engine, context);
|
||||||
|
engine_class->render_icon_surface (engine, cr, surface, x, y);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_insertion_cursor (GtkStyleContext *context,
|
draw_insertion_cursor (GtkStyleContext *context,
|
||||||
cairo_t *cr,
|
cairo_t *cr,
|
||||||
|
@ -1090,6 +1090,12 @@ void gtk_render_icon (GtkStyleContext *context,
|
|||||||
GdkPixbuf *pixbuf,
|
GdkPixbuf *pixbuf,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
|
GDK_AVAILABLE_IN_3_10
|
||||||
|
void gtk_render_icon_surface (GtkStyleContext *context,
|
||||||
|
cairo_t *cr,
|
||||||
|
cairo_surface_t *surface,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
GDK_AVAILABLE_IN_3_4
|
GDK_AVAILABLE_IN_3_4
|
||||||
void gtk_render_insertion_cursor
|
void gtk_render_insertion_cursor
|
||||||
(GtkStyleContext *context,
|
(GtkStyleContext *context,
|
||||||
|
@ -182,6 +182,11 @@ static void gtk_theming_engine_render_icon (GtkThemingEngine *engine,
|
|||||||
GdkPixbuf *pixbuf,
|
GdkPixbuf *pixbuf,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
|
static void gtk_theming_engine_render_icon_surface (GtkThemingEngine *engine,
|
||||||
|
cairo_t *cr,
|
||||||
|
cairo_surface_t *surface,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
|
G_DEFINE_TYPE (GtkThemingEngine, gtk_theming_engine, G_TYPE_OBJECT)
|
||||||
|
|
||||||
@ -239,6 +244,7 @@ gtk_theming_engine_class_init (GtkThemingEngineClass *klass)
|
|||||||
klass->render_handle = gtk_theming_engine_render_handle;
|
klass->render_handle = gtk_theming_engine_render_handle;
|
||||||
klass->render_activity = gtk_theming_engine_render_activity;
|
klass->render_activity = gtk_theming_engine_render_activity;
|
||||||
klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
|
klass->render_icon_pixbuf = gtk_theming_engine_render_icon_pixbuf;
|
||||||
|
klass->render_icon_surface = gtk_theming_engine_render_icon_surface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkThemingEngine:name:
|
* GtkThemingEngine:name:
|
||||||
@ -2791,3 +2797,21 @@ gtk_theming_engine_render_icon (GtkThemingEngine *engine,
|
|||||||
cairo_restore (cr);
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_theming_engine_render_icon_surface (GtkThemingEngine *engine,
|
||||||
|
cairo_t *cr,
|
||||||
|
cairo_surface_t *surface,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y)
|
||||||
|
{
|
||||||
|
cairo_save (cr);
|
||||||
|
|
||||||
|
cairo_set_source_surface (cr, surface, x, y);
|
||||||
|
|
||||||
|
_gtk_css_shadows_value_paint_icon (_gtk_theming_engine_peek_property (engine, GTK_CSS_PROPERTY_ICON_SHADOW), cr);
|
||||||
|
|
||||||
|
cairo_paint (cr);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ struct _GtkThemingEngine
|
|||||||
* or #GtkProgressBar.
|
* or #GtkProgressBar.
|
||||||
* @render_icon_pixbuf: Renders an icon as a #GdkPixbuf.
|
* @render_icon_pixbuf: Renders an icon as a #GdkPixbuf.
|
||||||
* @render_icon: Renders an icon given as a #GdkPixbuf.
|
* @render_icon: Renders an icon given as a #GdkPixbuf.
|
||||||
|
* @render_icon_surface: Renders an icon given as a #cairo_surface_t.
|
||||||
*
|
*
|
||||||
* Base class for theming engines.
|
* Base class for theming engines.
|
||||||
*/
|
*/
|
||||||
@ -174,9 +175,14 @@ struct _GtkThemingEngineClass
|
|||||||
GdkPixbuf *pixbuf,
|
GdkPixbuf *pixbuf,
|
||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y);
|
gdouble y);
|
||||||
|
void (* render_icon_surface) (GtkThemingEngine *engine,
|
||||||
|
cairo_t *cr,
|
||||||
|
cairo_surface_t *surface,
|
||||||
|
gdouble x,
|
||||||
|
gdouble y);
|
||||||
|
|
||||||
/*< private >*/
|
/*< private >*/
|
||||||
gpointer padding[15];
|
gpointer padding[14];
|
||||||
};
|
};
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
|
Loading…
Reference in New Issue
Block a user