From 9fa9fca2618ba5c5fae61c135ffd6c4814e44b5b Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Thu, 04 Oct 2012 10:59:06 +0000 Subject: Cache the background in the nice clock Render the svg only one time in a internal surface to improve performance Signed-off-by: Gonzalo Odiard --- (limited to 'clock.py') diff --git a/clock.py b/clock.py index 3e66185..bb793cb 100755 --- a/clock.py +++ b/clock.py @@ -525,6 +525,9 @@ class ClockFace(gtk.DrawingArea): # Black self._COLOR_BLACK = "#000000" + # cache backgrounds + self._nice_background_cache = None + # gtk.Widget signals self.connect("expose-event", self._expose_cb) self.connect("size-allocate", self._size_allocate_cb) @@ -737,13 +740,22 @@ class ClockFace(gtk.DrawingArea): """ # We transform the background SVG cr = self.window.cairo_create() - scale_x = self._radius * 2.0 / self._svg_handle.props.width - scale_y = self._radius * 2.0 / self._svg_handle.props.height - matrix = cairo.Matrix(xx=scale_x, yy=scale_y, - x0=self._center_x - self._radius, - y0=self._center_y - self._radius) - cr.transform(matrix) - self._svg_handle.render_cairo(cr) + + if self._nice_background_cache == None: + self._nice_background_cache = cr.get_target().create_similar( + cairo.CONTENT_COLOR_ALPHA, self._radius * 2, + self._radius * 2) + cache_ctx = cairo.Context(self._nice_background_cache) + scale_x = self._radius * 2.0 / self._svg_handle.props.width + scale_y = self._radius * 2.0 / self._svg_handle.props.height + matrix = cairo.Matrix(xx=scale_x, yy=scale_y) + cache_ctx.transform(matrix) + self._svg_handle.render_cairo(cache_ctx) + + cr.translate(self._center_x - self._radius, + self._center_y - self._radius) + cr.set_source_surface(self._nice_background_cache) + cr.paint() def _draw_nice_clock(self): """Draw the nice clock. -- cgit v0.9.1