Bark Beetle (Scolytinae) Gallery

2005-09-08: Mono.Cairo

I’m cur­rently invest­ig­at­ing Mono.Cairo for some pro­jects I’m involved to. Since there’s no to easy to use Cairo–based can­vas ele­ment avail­able at the moment, I’m about to cre­ate a simple new one. Dur­ing the last two days I got stuck at a memory leak: once I moved some ele­ment on my pretty, pretty, pretty simple can­vas 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 some­where on the Internet.

Today, just some minutes ago, I decided to search some mailing­lists and news­group for this prob­lem et voilà, here’s the solu­tion: http://…/gmane.comp.gnome.mono.summer-of-code/163. Michał Dominik K., the developer of DIVA and a par­ti­cipant of the Sum­mer of Code pro­ject of the Mono effort, pub­lished the solu­tion in the coordin­a­tion list. Thanks! :)

Start­ing with 2.8 the GTK lib­rary nat­ively sup­ports Cairo. The func­tion gdk\_cairo\_create(GdkDrawable *) cre­ates a sur­face with no memory leak­age :). 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));
		}
	}
}
  • Identi.ca

Bookmarks

Meta