[gtk+/wip/cosimoc/image-surface: 2/3] GtkCssImage: add a class method to return a surface
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/cosimoc/image-surface: 2/3] GtkCssImage: add a class method to return a surface
- Date: Sat, 21 Nov 2015 05:45:17 +0000 (UTC)
commit 5e69a9dfb199bd66bb2a32cc84d272a967559acc
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Nov 20 21:26:00 2015 -0800
GtkCssImage: add a class method to return a surface
This will be useful in a later commit when we will avoid recreating a
surface in some cases.
gtk/gtkcssimage.c | 76 ++++++++++++++++++++++++++++------------------
gtk/gtkcssimageprivate.h | 6 ++++
2 files changed, 52 insertions(+), 30 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 918a6ec..4a18ac1 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -60,6 +60,36 @@ gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
return 0;
}
+static cairo_surface_t *
+gtk_css_image_real_get_surface (GtkCssImage *image,
+ cairo_surface_t *target,
+ int surface_width,
+ int surface_height)
+{
+ cairo_surface_t *result;
+ cairo_t *cr;
+
+ g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
+ g_return_val_if_fail (surface_width > 0, NULL);
+ g_return_val_if_fail (surface_height > 0, NULL);
+
+ if (target)
+ result = cairo_surface_create_similar (target,
+ CAIRO_CONTENT_COLOR_ALPHA,
+ surface_width,
+ surface_height);
+ else
+ result = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ surface_width,
+ surface_height);
+
+ cr = cairo_create (result);
+ _gtk_css_image_draw (image, cr, surface_width, surface_height);
+ cairo_destroy (cr);
+
+ return result;
+}
+
static GtkCssImage *
gtk_css_image_real_compute (GtkCssImage *image,
guint property_id,
@@ -99,6 +129,7 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->get_width = gtk_css_image_real_get_width;
klass->get_height = gtk_css_image_real_get_height;
klass->get_aspect_ratio = gtk_css_image_real_get_aspect_ratio;
+ klass->get_surface = gtk_css_image_real_get_surface;
klass->compute = gtk_css_image_real_compute;
klass->equal = gtk_css_image_real_equal;
klass->transition = gtk_css_image_real_transition;
@@ -145,6 +176,21 @@ _gtk_css_image_get_aspect_ratio (GtkCssImage *image)
return klass->get_aspect_ratio (image);
}
+cairo_surface_t *
+_gtk_css_image_get_surface (GtkCssImage *image,
+ cairo_surface_t *target,
+ int surface_width,
+ int surface_height)
+{
+ GtkCssImageClass *klass;
+
+ g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
+
+ klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+ return klass->get_surface (image, target, surface_width, surface_height);
+}
+
GtkCssImage *
_gtk_css_image_compute (GtkCssImage *image,
guint property_id,
@@ -377,36 +423,6 @@ _gtk_css_image_get_concrete_size (GtkCssImage *image,
}
}
-cairo_surface_t *
-_gtk_css_image_get_surface (GtkCssImage *image,
- cairo_surface_t *target,
- int surface_width,
- int surface_height)
-{
- cairo_surface_t *result;
- cairo_t *cr;
-
- g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
- g_return_val_if_fail (surface_width > 0, NULL);
- g_return_val_if_fail (surface_height > 0, NULL);
-
- if (target)
- result = cairo_surface_create_similar (target,
- CAIRO_CONTENT_COLOR_ALPHA,
- surface_width,
- surface_height);
- else
- result = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
- surface_width,
- surface_height);
-
- cr = cairo_create (result);
- _gtk_css_image_draw (image, cr, surface_width, surface_height);
- cairo_destroy (cr);
-
- return result;
-}
-
static GType
gtk_css_image_get_parser_type (GtkCssParser *parser)
{
diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h
index 912d0d7..9373398 100644
--- a/gtk/gtkcssimageprivate.h
+++ b/gtk/gtkcssimageprivate.h
@@ -54,6 +54,12 @@ struct _GtkCssImageClass
/* aspect ratio (width / height) of image or 0 if it has no aspect ratio (optional) */
double (* get_aspect_ratio) (GtkCssImage *image);
+ /* returns a surface for specified width and height */
+ cairo_surface_t * (* get_surface) (GtkCssImage *image,
+ cairo_surface_t *target,
+ int surface_width,
+ int surface_height);
+
/* create "computed value" in CSS terms, returns a new reference */
GtkCssImage *(* compute) (GtkCssImage *image,
guint property_id,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]