I am writing an Operating System in C# (from scratch). I have successfully ported gcc, newlib stuff. so I decided to try cairo. I compiled pixman-0.30.2, libpng-1.5.13, zlib-1.2.8, freetype-2.4.9, cairo-1.12.18 host target i386-atomos (elf-32 bit).
Then I went for writing glue library, which looks like this:
Code: Select all
internal unsafe static class NativeMethods
{
const string LIBRARY = "libcairo.a";
/* Note: Because Arguments are pushed from left to right by the current compiler
* we have to make it reverse for successful function calling
*/
/// <summary>
/// cairo_public cairo_surface_t *
/// cairo_image_surface_create(cairo_format_t format,
/// int width,
/// int height);
/// </summary>
[NoException]
[Plug("cairo_image_surface_create")]
[DllImport(LIBRARY, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint cairo_image_surface_create(int height, int width, ColorFormat format);
/// <summary>
/// cairo_public cairo_t *
/// cairo_create(cairo_surface_t* target);
/// </summary>
[NoException]
[Plug("cairo_create")]
[DllImport(LIBRARY, CallingConvention = CallingConvention.Cdecl)]
internal static extern uint cairo_create(uint target);
}
Code: Select all
i386-atomos-ld %ATOMIX_ISO_DIR%\Kernel.o Local\lib\libcairo.a Local\lib\libpixman-1.a Local\lib\libpng15.a Local\lib\libz.a Local\i386-atomos\lib\libm.a Local\lib\gcc\i386-atomos\5.3.0\libgcc.a Local\lib\libfreetype.a Local\i386-atomos\lib\libc.a -T %ATOMIX_KERNEL_LINKER% -o %ATOMIX_ISO_DIR%\Kernel.bin
Code: Select all
internal static void CairoTest()
{
int stride = NativeMethods.cairo_format_stride_for_width(1280, ColorFormat.ARGB32);
uint surface = NativeMethods.cairo_image_surface_create_for_data(stride, 1280, 768, ColorFormat.ARGB32, VBE.SecondaryBuffer);
uint cr = NativeMethods.cairo_create(surface);
NativeMethods.cairo_set_source_rgba(1.0, 1.0, 1.0, 1.0, cr);
NativeMethods.cairo_rectangle(100, 100, 0, 0, cr);
NativeMethods.cairo_paint(cr);
NativeMethods.cairo_destroy(cr);
var data = NativeMethods.cairo_image_surface_get_data(surface);
Debug.Write("Location: %d\n", data);
Debug.Write("Pixel Color: %d\n", Memory.Read32(data));
VBE.Update();
}
Thanks!