gtk-css-engine r116 - in trunk: . libccd/ccd



Author: robsta
Date: Fri Sep 19 09:30:26 2008
New Revision: 116
URL: http://svn.gnome.org/viewvc/gtk-css-engine?rev=116&view=rev

Log:
* libccd/ccd/ccd-background.c:
* libccd/ccd/ccd-image.c:
* libccd/ccd/ccd-image.h:
Use a cairo pattern for the internal representation of an image instead
of a surface.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/libccd/ccd/ccd-background.c
   trunk/libccd/ccd/ccd-image.c
   trunk/libccd/ccd/ccd-image.h

Modified: trunk/libccd/ccd/ccd-background.c
==============================================================================
--- trunk/libccd/ccd/ccd-background.c	(original)
+++ trunk/libccd/ccd/ccd-background.c	Fri Sep 19 09:30:26 2008
@@ -341,6 +341,8 @@
 }
 #endif
 
+#if 0
+
 /*
  * TODO: find out whether liberal use of cairo_create()/cairo_destroy()
  * causes performance problems.
@@ -410,6 +412,8 @@
 	return pattern;
 }
 
+#endif
+
 /**
  * ccd_background_fill:
  *
@@ -425,8 +429,9 @@
 		     int32_t				 width,
 		     int32_t				 height)
 {
-	double dx;
-	double dy;
+	cairo_status_t	status;
+	double		dx;
+	double		dy;
 
 	cairo_save (cr);
 
@@ -440,20 +445,21 @@
 
 	if (bg_image && bg_image->spec != CCD_PROPERTY_SPEC_UNSET) {
 
-		cairo_pattern_t *pattern;
-
-		dx = (double) width / 
-		     cairo_image_surface_get_width (bg_image->image.surface);
-		dy = (double) height /
-		     cairo_image_surface_get_height (bg_image->image.surface);
+		cairo_translate (cr, x, y);
+		dx = (double) width / bg_image->image.width;
+		dy = (double) height / bg_image->image.height;
 		cairo_scale (cr, dx, dy);
 
-		cairo_set_source_surface (cr, bg_image->image.surface,
-					  x / dx, y / dy);
+		cairo_pattern_set_extend (bg_image->image.pattern,
+					  CAIRO_EXTEND_PAD);
 
-		pattern = cairo_get_source (cr);
-		cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD);
+		cairo_set_source (cr, bg_image->image.pattern);
 		cairo_fill_preserve (cr);
+
+		status = cairo_status (cr);
+		if (status != CAIRO_STATUS_SUCCESS) {
+			g_warning (cairo_status_to_string (status));
+		}
 	}
 
 	cairo_restore (cr);

Modified: trunk/libccd/ccd/ccd-image.c
==============================================================================
--- trunk/libccd/ccd/ccd-image.c	(original)
+++ trunk/libccd/ccd/ccd-image.c	Fri Sep 19 09:30:26 2008
@@ -39,9 +39,9 @@
 		self->uri = NULL;
 	}
 
-	if (self->surface) {
-		cairo_surface_destroy (self->surface);
-		self->surface = NULL;
+	if (self->pattern) {
+		cairo_pattern_destroy (self->pattern);
+		self->pattern = NULL;
 	}
 }
 
@@ -56,6 +56,7 @@
 	GError			*error;
 	RsvgDimensionData	 dimensions;
 	cairo_t			*cr;
+	cairo_surface_t		*surface;
 	cairo_status_t		 status;
 
 	error = NULL;
@@ -68,20 +69,20 @@
 	}
 
 	rsvg_handle_get_dimensions (handle, &dimensions);
-	self->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 
-						    dimensions.width,
-						    dimensions.height);
-
-	status = cairo_surface_status(self->surface);
+	self->width = dimensions.width;
+	self->height = dimensions.height;
+	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 
+					      self->width, self->height);
+	cr = cairo_create (surface);
+	rsvg_handle_render_cairo_sub (handle, cr, id);
+	status = cairo_status (cr);
 	if (status != CAIRO_STATUS_SUCCESS) {
 		g_warning (cairo_status_to_string (status));
-		cairo_surface_destroy (self->surface);
-		self->surface = NULL;
-		return false;
 	}
 
-	cr = cairo_create (self->surface);
-	rsvg_handle_render_cairo_sub (handle, cr, id);
+	self->pattern = cairo_pattern_create_for_surface (surface);
+	cairo_pattern_reference (self->pattern);
+	cairo_surface_destroy (surface), surface = NULL;
 	cairo_destroy (cr), cr = NULL;
 
 	g_object_unref (G_OBJECT (handle)), handle = NULL;
@@ -89,11 +90,37 @@
 	return true;
 }
 
-#endif
+#endif /*  CCD_WITH_RSVG */
+
+static bool
+load_png (ccd_image_t	*self,
+	  char const	*path)
+{
+	cairo_surface_t	*surface;
+	cairo_status_t	 status;
+
+	surface = cairo_image_surface_create_from_png (path);
+	status = cairo_surface_status (surface);
+	if (status != CAIRO_STATUS_SUCCESS) {
+		g_warning (cairo_status_to_string (status));
+		cairo_surface_destroy (surface);
+		return false;
+	}
+
+	self->width = cairo_image_surface_get_width (surface);
+	self->height = cairo_image_surface_get_height (surface);
+
+	self->pattern = cairo_pattern_create_for_surface (surface);
+	cairo_pattern_reference (self->pattern);
+	cairo_surface_destroy (surface), surface = NULL;
+
+	return true;
+}
 
 static bool
 load_image (ccd_image_t *self)
 {
+	cairo_status_t	 status;
 	bool		 matched;
 	char const	*path;
 	char const	*fragment;
@@ -110,24 +137,30 @@
 #endif
 
 	matched = false;
+
 #if CCD_WITH_RSVG
 	if (!matched &&
 	    g_str_has_suffix (path, ".svg")) {
-		matched = true;
-		load_svg (self, path, fragment);
+		matched = load_svg (self, path, fragment);
 	}
 #endif
 
 	if (!matched) {
-		self->surface = cairo_image_surface_create_from_png (path);
-
+		if (fragment)
+			g_warning ("`%s' ignoring fragment", self->uri);
+		matched = load_png (self, path);
 	}
 
 #if CCD_WITH_SOUP
 	soup_uri_free (uri), uri = NULL;
 #endif
 
-	return (bool) self->surface;
+	status = self->pattern ? cairo_pattern_status (self->pattern) : CAIRO_STATUS_SUCCESS;
+	if (status != CAIRO_STATUS_SUCCESS) {
+		g_warning (cairo_status_to_string (status));
+	}
+
+	return matched && self->pattern;
 }
 
 ccd_property_spec_t

Modified: trunk/libccd/ccd/ccd-image.h
==============================================================================
--- trunk/libccd/ccd/ccd-image.h	(original)
+++ trunk/libccd/ccd/ccd-image.h	Fri Sep 19 09:30:26 2008
@@ -30,7 +30,9 @@
 
 typedef struct {
 	char		*uri;
-	cairo_surface_t *surface;
+	cairo_pattern_t *pattern;
+	double		 width;
+	double		 height;
 } ccd_image_t;
 
 ccd_property_spec_t ccd_image_parse (ccd_image_t *self, CRTerm const **value);



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