Commit b41c54b3 authored by Bruno Coudoin's avatar Bruno Coudoin

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.

svn path=/branches/gcomprixogoo/; revision=3609
parent 86823784
2008-11-10 Bruno coudoin <bruno.coudoin@free.fr>
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.
* src/gcompris/config.c: (set_locale_flag):
* src/gcompris/gameutil.c: (gc_util_button_text):
* src/gcompris/gcompris.c: (_set_svg_background):
* src/goocanvas/src/goocanvassvg.c: (_init_surface),
(goo_canvas_svg_init), (goo_canvas_svg_new),
(goo_canvas_svg_paint), (goo_canvas_svg_finalize),
(goo_canvas_svg_set_common_property):
* src/goocanvas/src/goocanvassvg.h:
* src/magic_hat_minus-activity/magic_hat.c: (item_event):
* src/paratrooper-activity/paratrooper.c: (next_state):
* src/reversecount-activity/reversecount.c: (item_event):
* src/watercycle-activity/watercycle.py:
2008-11-09 Bruno coudoin <bruno.coudoin@free.fr>
API cleanup, now our svg item has the same API signature
......
......@@ -584,7 +584,7 @@ set_locale_flag(gchar *locale)
(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 @@ set_locale_flag(gchar *locale)
{
/* No flags */
g_object_set (item_locale_flag,
"rsvg-handle", rsvg_handle_new(),
"svg-handle", rsvg_handle_new(),
NULL);
}
......
......@@ -681,7 +681,6 @@ gc_util_button_text(GooCanvasItem *rootitem,
x,
y,
NULL);
gdk_pixbuf_unref(pixmap);
g_signal_connect(item,
"button_press_event",
(GtkSignalFunc) process, data);
......@@ -702,4 +701,5 @@ gc_util_button_text(GooCanvasItem *rootitem,
"button_press_event",
process, data);
gc_item_focus_init(item_text, item);
gdk_pixbuf_unref(pixmap);
}
......@@ -489,7 +489,7 @@ _set_svg_background(GooCanvasItem *parent, gchar *file)
if(backgroundsvgimg)
g_object_set(backgroundsvgimg,
"rsvg-handle", rsvg_handle,
"svg-handle", rsvg_handle,
NULL);
else
backgroundsvgimg = goo_canvas_svg_new (parent,
......
......@@ -46,6 +46,31 @@ goo_canvas_svg_install_common_properties (GObjectClass *gobject_class)
}
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 @@ goo_canvas_svg_init (GooCanvasSvg *canvas_svg)
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 @@ goo_canvas_svg_new (GooCanvasItem *parent,
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 @@ goo_canvas_svg_new (GooCanvasItem *parent,
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 @@ goo_canvas_svg_paint (GooCanvasItemSimple *simple,
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 @@ goo_canvas_svg_finalize (GObject *object)
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))
......
......@@ -33,6 +33,8 @@ struct _GooCanvasSvg
RsvgHandle *svg_handle;
gdouble width, height;
gchar *id;
cairo_t *cr;
cairo_pattern_t *pattern;
};
struct _GooCanvasSvgClass
......
......@@ -625,7 +625,7 @@ static gboolean item_event (GooCanvasItem *item,
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 @@ static gboolean item_event (GooCanvasItem *item,
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);
}
......
......@@ -581,7 +581,7 @@ void next_state()
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 @@ void next_state()
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);
......
......@@ -780,7 +780,7 @@ item_event (GooCanvasItem *item,
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);
......
......@@ -24,9 +24,10 @@ import gcompris.skin
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 @@ class Gcompris_watercycle:
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 @@ class Gcompris_watercycle:
# 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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment