gcompris r3609 - in branches/gcomprixogoo: . src/gcompris src/goocanvas/src src/magic_hat_minus-activity src/paratrooper-activity src/reversecount-activity src/watercycle-activity
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3609 - in branches/gcomprixogoo: . src/gcompris src/goocanvas/src src/magic_hat_minus-activity src/paratrooper-activity src/reversecount-activity src/watercycle-activity
- Date: Mon, 10 Nov 2008 00:06:30 +0000 (UTC)
Author: bcoudoin
Date: Mon Nov 10 00:06:30 2008
New Revision: 3609
URL: http://svn.gnome.org/viewvc/gcompris?rev=3609&view=rev
Log:
Performance improvement of the goocanvas svg item. Now the
rsvg rendering is only done once in a sairo surface and copyed
again to the cairo target when needed.
Modified:
branches/gcomprixogoo/ChangeLog
branches/gcomprixogoo/src/gcompris/config.c
branches/gcomprixogoo/src/gcompris/gameutil.c
branches/gcomprixogoo/src/gcompris/gcompris.c
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
branches/gcomprixogoo/src/magic_hat_minus-activity/magic_hat.c
branches/gcomprixogoo/src/paratrooper-activity/paratrooper.c
branches/gcomprixogoo/src/reversecount-activity/reversecount.c
branches/gcomprixogoo/src/watercycle-activity/watercycle.py
Modified: branches/gcomprixogoo/src/gcompris/config.c
==============================================================================
--- branches/gcomprixogoo/src/gcompris/config.c (original)
+++ branches/gcomprixogoo/src/gcompris/config.c Mon Nov 10 00:06:30 2008
@@ -584,7 +584,7 @@
(y_flag_start + 40) / xratio);
g_object_set (item_locale_flag,
- "rsvg-handle", svg_handle,
+ "svg-handle", svg_handle,
NULL);
g_object_unref(svg_handle);
@@ -594,7 +594,7 @@
{
/* No flags */
g_object_set (item_locale_flag,
- "rsvg-handle", rsvg_handle_new(),
+ "svg-handle", rsvg_handle_new(),
NULL);
}
Modified: branches/gcomprixogoo/src/gcompris/gameutil.c
==============================================================================
--- branches/gcomprixogoo/src/gcompris/gameutil.c (original)
+++ branches/gcomprixogoo/src/gcompris/gameutil.c Mon Nov 10 00:06:30 2008
@@ -681,7 +681,6 @@
x,
y,
NULL);
- gdk_pixbuf_unref(pixmap);
g_signal_connect(item,
"button_press_event",
(GtkSignalFunc) process, data);
@@ -702,4 +701,5 @@
"button_press_event",
process, data);
gc_item_focus_init(item_text, item);
+ gdk_pixbuf_unref(pixmap);
}
Modified: branches/gcomprixogoo/src/gcompris/gcompris.c
==============================================================================
--- branches/gcomprixogoo/src/gcompris/gcompris.c (original)
+++ branches/gcomprixogoo/src/gcompris/gcompris.c Mon Nov 10 00:06:30 2008
@@ -489,7 +489,7 @@
if(backgroundsvgimg)
g_object_set(backgroundsvgimg,
- "rsvg-handle", rsvg_handle,
+ "svg-handle", rsvg_handle,
NULL);
else
backgroundsvgimg = goo_canvas_svg_new (parent,
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.c Mon Nov 10 00:06:30 2008
@@ -46,6 +46,31 @@
}
+static void _init_surface(GooCanvasSvg *canvas_svg)
+{
+ RsvgDimensionData dimension_data;
+ rsvg_handle_get_dimensions (canvas_svg->svg_handle, &dimension_data);
+ canvas_svg->width = dimension_data.width;
+ canvas_svg->height = dimension_data.height;
+
+ if (canvas_svg->pattern)
+ cairo_pattern_destroy(canvas_svg->pattern);
+ canvas_svg->pattern = NULL;
+
+ if (canvas_svg->cr)
+ cairo_destroy(canvas_svg->cr);
+ canvas_svg->cr = NULL;
+
+ cairo_surface_t* cst =
+ cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ canvas_svg->width,
+ canvas_svg->height);
+ canvas_svg->cr = cairo_create (cst);
+ rsvg_handle_render_cairo (canvas_svg->svg_handle, canvas_svg->cr);
+ canvas_svg->pattern = cairo_pattern_create_for_surface (cst);
+ cairo_surface_destroy(cst);
+}
+
/* The standard object initialization function. */
static void
goo_canvas_svg_init (GooCanvasSvg *canvas_svg)
@@ -53,6 +78,9 @@
canvas_svg->width = 0.0;
canvas_svg->height = 0.0;
canvas_svg->id = NULL;
+ canvas_svg->cr = NULL;
+ canvas_svg->pattern = NULL;
+
}
@@ -68,19 +96,13 @@
GooCanvasSvg *canvas_svg;
const char *first_property;
va_list var_args;
- RsvgDimensionData dimension_data;
item = g_object_new (GOO_TYPE_CANVAS_SVG, NULL);
canvas_svg = (GooCanvasSvg*) item;
canvas_svg->svg_handle = svg_handle;
if(svg_handle)
- {
- g_object_ref (svg_handle);
- rsvg_handle_get_dimensions (svg_handle, &dimension_data);
- canvas_svg->width = dimension_data.width;
- canvas_svg->height = dimension_data.height;
- }
+ _init_surface(canvas_svg);
va_start (var_args, svg_handle);
first_property = va_arg (var_args, char*);
@@ -104,7 +126,7 @@
storing them in simple->bounds. */
static void
goo_canvas_svg_update (GooCanvasItemSimple *simple,
- cairo_t *cr)
+ cairo_t *cr)
{
GooCanvasSvg *canvas_svg = (GooCanvasSvg*) simple;
@@ -126,8 +148,11 @@
GooCanvasSvg *canvas_svg = (GooCanvasSvg*) simple;
if(canvas_svg->svg_handle)
- rsvg_handle_render_cairo_sub (canvas_svg->svg_handle, cr,
- canvas_svg->id);
+ {
+ cairo_set_source (cr, canvas_svg->pattern);
+ cairo_paint (cr);
+ }
+ //rsvg_handle_render_cairo_sub (canvas_svg->svg_handle, cr, canvas_svg->id);
}
@@ -145,31 +170,34 @@
g_free(canvas_svg->id);
canvas_svg->id = NULL;
+ if (canvas_svg->pattern)
+ cairo_pattern_destroy(canvas_svg->pattern);
+ canvas_svg->pattern = NULL;
+
+ if (canvas_svg->cr)
+ cairo_destroy(canvas_svg->cr);
+ canvas_svg->cr = NULL;
+
+
G_OBJECT_CLASS (goo_canvas_svg_parent_class)->finalize (object);
}
static void
goo_canvas_svg_set_common_property (GObject *object,
- GooCanvasSvg *canvas_svg,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ GooCanvasSvg *canvas_svg,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
RsvgHandle *svg_handle;
- RsvgDimensionData dimension_data;
switch (prop_id)
{
case PROP_SVGHANDLE:
svg_handle = g_value_get_object (value);
- if(canvas_svg->svg_handle)
- g_object_unref (canvas_svg->svg_handle);
- g_object_ref (svg_handle);
canvas_svg->svg_handle = svg_handle;
- rsvg_handle_get_dimensions (svg_handle, &dimension_data);
- canvas_svg->width = dimension_data.width;
- canvas_svg->height = dimension_data.height;
+ _init_surface(canvas_svg);
break;
case PROP_SVG_ID:
if (!g_value_get_string (value))
Modified: branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h
==============================================================================
--- branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h (original)
+++ branches/gcomprixogoo/src/goocanvas/src/goocanvassvg.h Mon Nov 10 00:06:30 2008
@@ -33,6 +33,8 @@
RsvgHandle *svg_handle;
gdouble width, height;
gchar *id;
+ cairo_t *cr;
+ cairo_pattern_t *pattern;
};
struct _GooCanvasSvgClass
Modified: branches/gcomprixogoo/src/magic_hat_minus-activity/magic_hat.c
==============================================================================
--- branches/gcomprixogoo/src/magic_hat_minus-activity/magic_hat.c (original)
+++ branches/gcomprixogoo/src/magic_hat_minus-activity/magic_hat.c Mon Nov 10 00:06:30 2008
@@ -625,7 +625,7 @@
pixmap = gc_rsvg_load("magic_hat/star-clear.svgz");
- g_object_set(item, "rsvg-handle", pixmap, NULL);
+ g_object_set(item, "svg-handle", pixmap, NULL);
g_object_unref(pixmap);
@@ -650,7 +650,7 @@
pixmap = gc_rsvg_load("magic_hat/star3.svgz");
break;
}
- g_object_set(item, "rsvg-handle", pixmap, NULL);
+ g_object_set(item, "svg-handle", pixmap, NULL);
g_object_unref(pixmap);
}
Modified: branches/gcomprixogoo/src/paratrooper-activity/paratrooper.c
==============================================================================
--- branches/gcomprixogoo/src/paratrooper-activity/paratrooper.c (original)
+++ branches/gcomprixogoo/src/paratrooper-activity/paratrooper.c Mon Nov 10 00:06:30 2008
@@ -581,7 +581,7 @@
svg_handle = gc_rsvg_load("paratrooper/minitux.svgz");
g_object_set (paratrooperItem.paratrooper,
- "rsvg-handle", svg_handle,
+ "svg-handle", svg_handle,
NULL);
g_object_unref(svg_handle);
gc_item_focus_init(paratrooperItem.paratrooper, NULL);
@@ -612,7 +612,7 @@
svg_handle = gc_rsvg_load("paratrooper/parachute.svgz");
g_object_set (paratrooperItem.paratrooper,
- "rsvg-handle", svg_handle,
+ "svg-handle", svg_handle,
NULL);
gc_item_focus_remove(paratrooperItem.paratrooper, NULL);
Modified: branches/gcomprixogoo/src/reversecount-activity/reversecount.c
==============================================================================
--- branches/gcomprixogoo/src/reversecount-activity/reversecount.c (original)
+++ branches/gcomprixogoo/src/reversecount-activity/reversecount.c Mon Nov 10 00:06:30 2008
@@ -780,7 +780,7 @@
rsvg_handle = gc_rsvg_load(str);
g_object_set (item,
- "rsvg-handle", rsvg_handle,
+ "svg-handle", rsvg_handle,
NULL);
gc_item_focus_init(item, NULL);
g_object_unref(rsvg_handle);
Modified: branches/gcomprixogoo/src/watercycle-activity/watercycle.py
==============================================================================
--- branches/gcomprixogoo/src/watercycle-activity/watercycle.py (original)
+++ branches/gcomprixogoo/src/watercycle-activity/watercycle.py Mon Nov 10 00:06:30 2008
@@ -24,9 +24,10 @@
import gcompris.sound
import gtk
import gtk.gdk
+import rsvg
class Gcompris_watercycle:
- """The Cycle Water activity"""
+ """The Water Cycle activity"""
def __init__(self, gcomprisBoard):
@@ -53,8 +54,6 @@
gcompris.bar_set(0)
gcompris.bar_location(gcompris.BOARD_WIDTH - 140, -1, 0.7)
- gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(),
- "watercycle/background.png")
gcompris.bar_set_level(self.gcomprisBoard)
gcompris.sound.play_ogg("sounds/Harbor1.wav", "sounds/Harbor3.wav")
@@ -63,6 +62,12 @@
# only have to kill it. The canvas deletes all the items it contains automaticaly.
self.rootitem = goocanvas.Group(parent = self.gcomprisBoard.canvas.get_root_item())
+ svghandle = gcompris.utils.load_svg("watercycle/watercycle.svgz")
+ goocanvas.Svg(
+ parent = self.rootitem,
+ svg_handle = svghandle
+ )
+
# Take care, the items are stacked on each other in the order you add them.
# If you need, you can reorder them later with raise and lower functions.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]