[Sugar-devel] [PATCH sugar-toolkit] icon: use GDK for pixbuf-to-cairo conversion

Daniel Drake dsd at laptop.org
Tue Mar 6 16:08:33 EST 2012


We currently use some strange code inside hippo to paint a pixbuf onto
a cairo surface. This can be more effectively done within GDK.

This solves a Sugar crash-on-startup on Fedora 17, where this hippo
code is crashing, and uses the same underlying mechanism as
sugar-toolkit-gtk3.

Also use cairo.Context.set_source_rgb() for setting the background
colour, which avoids the requirement to encapsulate the cairo context
at an early stage (which would make the rest of this patch a little
more complicated).

Signed-off-by: Daniel Drake <dsd at laptop.org>
---
 src/sugar/graphics/icon.py |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/sugar/graphics/icon.py b/src/sugar/graphics/icon.py
index 62a79f6..3f540d7 100644
--- a/src/sugar/graphics/icon.py
+++ b/src/sugar/graphics/icon.py
@@ -182,9 +182,9 @@ class _IconBuffer(object):
 
             if not sensitive:
                 pixbuf = self._get_insensitive_pixbuf(pixbuf, widget)
-            surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
-            context.set_source_surface(surface, 0, 0)
-            context.paint()
+            gdkcontext = gtk.gdk.CairoContext(context)
+            gdkcontext.set_source_pixbuf(pixbuf, 0, 0)
+            gdkcontext.paint()
 
     def _get_size(self, icon_width, icon_height, padding):
         if self.width is not None and self.height is not None:
@@ -280,8 +280,9 @@ class _IconBuffer(object):
             surface = cairo.ImageSurface(cairo.FORMAT_RGB24, int(width),
                                          int(height))
             context = cairo.Context(surface)
-            context = gtk.gdk.CairoContext(context)
-            context.set_source_color(self.background_color)
+            context.set_source_rgb(self.background_color.red,
+                                   self.background_color.blue,
+                                   self.background_color.green)
             context.paint()
 
         context.scale(float(width) / (icon_width + padding * 2),
@@ -295,16 +296,15 @@ class _IconBuffer(object):
             else:
                 pixbuf = handle.get_pixbuf()
                 pixbuf = self._get_insensitive_pixbuf(pixbuf, widget)
-
-                pixbuf_surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
-                context.set_source_surface(pixbuf_surface, 0, 0)
-                context.paint()
+                gdkcontext = gtk.gdk.CairoContext(context)
+                gdkcontext.set_source_pixbuf(pixbuf, 0, 0)
+                gdkcontext.paint()
         else:
             if not sensitive:
                 pixbuf = self._get_insensitive_pixbuf(pixbuf, widget)
-            pixbuf_surface = hippo.cairo_surface_from_gdk_pixbuf(pixbuf)
-            context.set_source_surface(pixbuf_surface, 0, 0)
-            context.paint()
+            gdkcontext = gtk.gdk.CairoContext(context)
+            gdkcontext.set_source_pixbuf(pixbuf, 0, 0)
+            gdkcontext.paint()
 
         if self.badge_name:
             context.restore()
-- 
1.7.7.6



More information about the Sugar-devel mailing list