[gtk+/wip/cosimoc/image-surface: 1/3] GtkRenderBorder: optimize GtkCssImageSurface of same size



commit ec1bc091833e330b0e9ca71d6ec258fa3b7e9e7f
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Nov 20 21:42:43 2015 -0800

    GtkRenderBorder: optimize GtkCssImageSurface of same size
    
    We don't need to draw a surface again if GtkCssImageSurface already
    holds a cairo surface of the right size.

 gtk/gtkcssimagesurface.c |   17 +++++++++++++++++
 gtk/gtkcssimageurl.c     |   13 +++++++++++++
 gtk/gtkrenderborder.c    |    2 --
 3 files changed, 30 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssimagesurface.c b/gtk/gtkcssimagesurface.c
index ac812dd..867c213 100644
--- a/gtk/gtkcssimagesurface.c
+++ b/gtk/gtkcssimagesurface.c
@@ -39,6 +39,22 @@ gtk_css_image_surface_get_height (GtkCssImage *image)
   return cairo_image_surface_get_height (surface->surface);
 }
 
+static cairo_surface_t *
+gtk_css_image_surface_get_surface (GtkCssImage     *image,
+                                   cairo_surface_t *target,
+                                   int              surface_width,
+                                   int              surface_height)
+{
+  GtkCssImageSurface *surface = GTK_CSS_IMAGE_SURFACE (image);
+
+  if (surface_width == cairo_image_surface_get_width (surface->surface) &&
+      surface_height == cairo_image_surface_get_height (surface->surface))
+    return cairo_surface_reference (surface->surface);
+
+  return GTK_CSS_IMAGE_CLASS (_gtk_css_image_surface_parent_class)->get_surface
+    (image, target, surface_width, surface_height);
+}
+
 static void
 gtk_css_image_surface_draw (GtkCssImage *image,
                             cairo_t     *cr,
@@ -112,6 +128,7 @@ _gtk_css_image_surface_class_init (GtkCssImageSurfaceClass *klass)
 
   image_class->get_width = gtk_css_image_surface_get_width;
   image_class->get_height = gtk_css_image_surface_get_height;
+  image_class->get_surface = gtk_css_image_surface_get_surface;
   image_class->draw = gtk_css_image_surface_draw;
   image_class->print = gtk_css_image_surface_print;
 
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c
index 341f8cf..08dc3b0 100644
--- a/gtk/gtkcssimageurl.c
+++ b/gtk/gtkcssimageurl.c
@@ -108,6 +108,18 @@ gtk_css_image_url_get_aspect_ratio (GtkCssImage *image)
   return _gtk_css_image_get_aspect_ratio (gtk_css_image_url_load_image (url));
 }
 
+static cairo_surface_t *
+gtk_css_image_url_get_surface (GtkCssImage *image,
+                               cairo_surface_t *target,
+                               int              surface_width,
+                               int              surface_height)
+{
+  GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
+
+  return _gtk_css_image_get_surface (gtk_css_image_url_load_image (url),
+                                     target, surface_width, surface_height);
+}
+
 static void
 gtk_css_image_url_draw (GtkCssImage        *image,
                         cairo_t            *cr,
@@ -173,6 +185,7 @@ _gtk_css_image_url_class_init (GtkCssImageUrlClass *klass)
   image_class->get_width = gtk_css_image_url_get_width;
   image_class->get_height = gtk_css_image_url_get_height;
   image_class->get_aspect_ratio = gtk_css_image_url_get_aspect_ratio;
+  image_class->get_surface = gtk_css_image_url_get_surface;
   image_class->compute = gtk_css_image_url_compute;
   image_class->draw = gtk_css_image_url_draw;
   image_class->parse = gtk_css_image_url_parse;
diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c
index f533a0c..99ff9d5 100644
--- a/gtk/gtkrenderborder.c
+++ b/gtk/gtkrenderborder.c
@@ -267,8 +267,6 @@ gtk_border_image_render (GtkBorderImage   *image,
                                     width, height,
                                     &source_width, &source_height);
 
-  /* XXX: Optimize for (source_width == width && source_height == height) */
-
   surface = _gtk_css_image_get_surface (image->source,
                                         cairo_get_target (cr),
                                         source_width, source_height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]