2005-09-08: Mono.Cairo
I’m currently investigating Mono.Cairo for some projects I’m involved to. Since there’s no to easy to use Cairo–based canvas element available at the moment, I’m about to create a simple new one. During the last two days I got stuck at a memory leak: once I moved some element on my pretty, pretty, pretty simple canvas field, all my memory got eaten up. I’ve checked every piece of code — it’s not that much, only a few lines so far :) — but it seemed to be an issue with the Cairo-Mono-binding I found somewhere on the Internet.
Today, just some minutes ago, I decided to search some mailinglists and newsgroup for this problem et voilà, here’s the solution: http://…/gmane.comp.gnome.mono.summer-of-code/163. Michał Dominik K., the developer of DIVA and a participant of the Summer of Code project of the Mono effort, published the solution in the coordination list. Thanks! :)
Starting with 2.8 the GTK library natively supports Cairo. The function gdk\_cairo\_create(GdkDrawable *) creates a surface with no memory leakage :). The full source for Gdk.Graphics is shown below. It’s linux-only for now.
using System;
using System.Runtime.InteropServices;
using Cairo;
namespace Gdk
{
public class Graphics
{
private Graphics() {}
[DllImport("libgdk-x11-2.0.so.0")]
internal static extern IntPtr gdk_cairo_create(
IntPtr handle);
public static Cairo.Graphics CreateDrawable(
Gdk.Drawable drawable)
{
return new Cairo.Graphics(
gdk_cairo_create(drawable.Handle));
}
}
}