Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a Linux Framebuffer in Mono (Mono.Cairo / GTK#)?

I'm starting to write a small application for Linux under the Mono framework, the application will essentially be a small kiosk front-end with very minimal user interaction. This is to replace a previous version of the same application which was 100% text / console based.

As this will run on a Raspberry Pi, I want to avoid running X and have my application talk to the Framebuffer directly. I'm set on using the Mono framework and C# as my development language since I know C# very well. Portability is not an issue in this instance.

I'm having some trouble finding appropriate libraries and bindings to let me access the Framebuffer from Mono however. The GTK# libraries all bind explicitly to the X11 interface, and in any case, there don't appear to be pre-built GtkFB libraries in Debian Wheezy for the ARM Soft-Float (armel) architecture.

The Mono.Cairo library exposes a DirectFBSurface type, however the constructor for that surface takes two IntPtr arguments and is not documented so I don't know what should be passed into the constructor to properly initialise the Framebuffer as a Cairo Surface.

Has anyone worked with Mono and C# to talk to the Linux Framebuffer, and if so, can you provide basic examples to initialise and start drawing onto the FB, or point to online documentation to assist?

Update 1

I thought I'd try instantiating the DirectFBSurface with null for both constructor parameters, with the following code:

public static void Main(string[] args)
{
    // ...
    DirectFBSurface surface = new DirectFBSurface(((IntPtr)null), ((IntPtr)null));
    // ...
}

I expected this to generate an exception indicating that null parameter values were not permitted, however it instead looks as if the DirectFBSurface is either not implemented in Mono.Cairo or is not compiled into the library shipped with Debian Wheezy (armel):

Unhandled Exception: System.EntryPointNotFoundException: cairo_directfb_surface_create
  at (wrapper managed-to-native) Cairo.NativeMethods:cairo_directfb_surface_create (intptr,intptr)
  at Cairo.DirectFBSurface..ctor (IntPtr dfb, IntPtr dfb_surface) [0x00000] in <filename unknown>:0
  at Info.Insch.SandBox.TestCairo.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

So it appears that the Mono.Cairo approach probably won't work for my needs, and as noted above, GTK# Framebuffer library doesn't seem to be part of Debian Wheezy for armel. Is there another set of libraries which I could use to access the Linux Framebuffer from Mono?

like image 530
Mike Insch Avatar asked Aug 27 '12 01:08

Mike Insch


1 Answers

The EntryPointNotFoundException you get, means that the symbol cairo_directfb_surface_create with (IntPtr, IntPtr) as arguments was not found in your libcairo.so.2 library from debian. This can likely be the case, if directfb was not enabled at compile time in cairo. You can check for directfb support in cairo by doing:

readelf -Ws /usr/lib/libcairo.so.2 | grep directfb

If the result (output) is empty, you lack directfb support. In this case you must recompile cairo with --enable-directfb argument passed to the configure script.

I've tested on an openSUSE 12.1 and Fedora 17 box, and both do not seem to ship directfb enabled cairo by default. I don't know about debian though, you will have to test yourself.

like image 76
Dynalon Avatar answered Nov 06 '22 12:11

Dynalon