forked from AuroraMiddleware/gtk
cssimage: Get rid of draw vfunc
All remaining users of that vfunc now implement snapshot using cairo render nodes (win32 and radial). Also, GtkCssImageClass.snapshot is now NULL, so if a subclass doesn't implement it, it will now crash. Previously it would try to call the draw vfunc.
This commit is contained in:
parent
1b8a768279
commit
95ddb57562
@ -96,45 +96,6 @@ gtk_css_image_real_transition (GtkCssImage *start,
|
||||
return _gtk_css_image_cross_fade_new (start, end, progress);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_image_real_draw (GtkCssImage *image,
|
||||
cairo_t *cr,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
GtkSnapshot snapshot;
|
||||
GskRenderNode *node;
|
||||
cairo_region_t *clip;
|
||||
|
||||
clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { 0, 0, width, height });
|
||||
gtk_snapshot_init (&snapshot, NULL, FALSE, clip, "Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
||||
gtk_css_image_snapshot (image, &snapshot, width, height);
|
||||
node = gtk_snapshot_finish (&snapshot);
|
||||
|
||||
if (node != NULL)
|
||||
{
|
||||
gsk_render_node_draw (node, cr);
|
||||
gsk_render_node_unref (node);
|
||||
}
|
||||
|
||||
cairo_region_destroy (clip);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_image_real_snapshot (GtkCssImage *image,
|
||||
GtkSnapshot *snapshot,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
"Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
||||
_gtk_css_image_draw (image, cr, width, height);
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
_gtk_css_image_class_init (GtkCssImageClass *klass)
|
||||
{
|
||||
@ -144,8 +105,6 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
|
||||
klass->compute = gtk_css_image_real_compute;
|
||||
klass->equal = gtk_css_image_real_equal;
|
||||
klass->transition = gtk_css_image_real_transition;
|
||||
klass->draw = gtk_css_image_real_draw;
|
||||
klass->snapshot = gtk_css_image_real_snapshot;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -260,7 +219,9 @@ _gtk_css_image_draw (GtkCssImage *image,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
GtkCssImageClass *klass;
|
||||
GtkSnapshot snapshot;
|
||||
GskRenderNode *node;
|
||||
cairo_region_t *clip;
|
||||
|
||||
g_return_if_fail (GTK_IS_CSS_IMAGE (image));
|
||||
g_return_if_fail (cr != NULL);
|
||||
@ -269,9 +230,18 @@ _gtk_css_image_draw (GtkCssImage *image,
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
klass = GTK_CSS_IMAGE_GET_CLASS (image);
|
||||
clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) { 0, 0, width, height });
|
||||
gtk_snapshot_init (&snapshot, NULL, FALSE, clip, "Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
||||
gtk_css_image_snapshot (image, &snapshot, width, height);
|
||||
node = gtk_snapshot_finish (&snapshot);
|
||||
|
||||
klass->draw (image, cr, width, height);
|
||||
if (node != NULL)
|
||||
{
|
||||
gsk_render_node_draw (node, cr);
|
||||
gsk_render_node_unref (node);
|
||||
}
|
||||
|
||||
cairo_region_destroy (clip);
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
@ -444,8 +444,8 @@ gtk_css_image_builtin_draw_spinner (GtkCssImage *image,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_image_builtin_real_draw (GtkCssImage *image,
|
||||
cairo_t *cr,
|
||||
gtk_css_image_builtin_real_snapshot (GtkCssImage *image,
|
||||
GtkSnapshot *snapshot,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
@ -516,7 +516,7 @@ gtk_css_image_builtin_class_init (GtkCssImageBuiltinClass *klass)
|
||||
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
image_class->draw = gtk_css_image_builtin_real_draw;
|
||||
image_class->snapshot = gtk_css_image_builtin_real_snapshot;
|
||||
image_class->parse = gtk_css_image_builtin_parse;
|
||||
image_class->print = gtk_css_image_builtin_print;
|
||||
image_class->compute = gtk_css_image_builtin_compute;
|
||||
|
@ -71,10 +71,6 @@ struct _GtkCssImageClass
|
||||
double progress);
|
||||
|
||||
/* draw to 0,0 with the given width and height */
|
||||
void (* draw) (GtkCssImage *image,
|
||||
cairo_t *cr,
|
||||
double width,
|
||||
double height);
|
||||
void (* snapshot) (GtkCssImage *image,
|
||||
GtkSnapshot *snapshot,
|
||||
double width,
|
||||
|
@ -74,8 +74,8 @@ gtk_css_image_radial_get_start_end (GtkCssImageRadial *radial,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_css_image_radial_draw (GtkCssImage *image,
|
||||
cairo_t *cr,
|
||||
gtk_css_image_radial_snapshot (GtkCssImage *image,
|
||||
GtkSnapshot *snapshot,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
@ -88,6 +88,11 @@ gtk_css_image_radial_draw (GtkCssImage *image,
|
||||
double r1, r2, r3, r4, r;
|
||||
double offset;
|
||||
int i, last;
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
"Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
||||
|
||||
x = _gtk_css_position_value_get_x (radial->position, width);
|
||||
y = _gtk_css_position_value_get_y (radial->position, height);
|
||||
@ -225,6 +230,8 @@ gtk_css_image_radial_draw (GtkCssImage *image,
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_pattern_destroy (pattern);
|
||||
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -667,7 +674,7 @@ _gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
|
||||
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
image_class->draw = gtk_css_image_radial_draw;
|
||||
image_class->snapshot = gtk_css_image_radial_snapshot;
|
||||
image_class->parse = gtk_css_image_radial_parse;
|
||||
image_class->print = gtk_css_image_radial_print;
|
||||
image_class->compute = gtk_css_image_radial_compute;
|
||||
|
@ -26,14 +26,19 @@
|
||||
G_DEFINE_TYPE (GtkCssImageWin32, _gtk_css_image_win32, GTK_TYPE_CSS_IMAGE)
|
||||
|
||||
static void
|
||||
gtk_css_image_win32_draw (GtkCssImage *image,
|
||||
cairo_t *cr,
|
||||
gtk_css_image_win32_snapshot (GtkCssImage *image,
|
||||
GtkSnapshot *snapshot,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
|
||||
cairo_surface_t *surface;
|
||||
int dx, dy;
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gtk_snapshot_append_cairo (snapshot,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
||||
"Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
||||
|
||||
surface = gtk_win32_theme_create_surface (wimage->theme, wimage->part, wimage->state, wimage->margins,
|
||||
width, height, &dx, &dy);
|
||||
@ -63,6 +68,8 @@ gtk_css_image_win32_draw (GtkCssImage *image,
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -242,7 +249,7 @@ _gtk_css_image_win32_class_init (GtkCssImageWin32Class *klass)
|
||||
|
||||
object_class->finalize = gtk_css_image_win32_finalize;
|
||||
|
||||
image_class->draw = gtk_css_image_win32_draw;
|
||||
image_class->snapshot = gtk_css_image_win32_snapshot;
|
||||
image_class->parse = gtk_css_image_win32_parse;
|
||||
image_class->print = gtk_css_image_win32_print;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user