Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2012-10-04 10:59:06 (GMT)
committer Gary Martin <gary@garycmartin.com>2012-10-04 13:17:10 (GMT)
commit9fa9fca2618ba5c5fae61c135ffd6c4814e44b5b (patch)
tree78751f813fa60f0b8c764cec4b15078ad0601207
parent347f73479f2dc4fc507cf914cfb5805a17130d6c (diff)
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 <gonzalo@laptop.org>
-rwxr-xr-xclock.py26
1 files changed, 19 insertions, 7 deletions
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.