Page 1 of 1

Cairo not working!

Posted: Sat Dec 24, 2016 5:02 am
by amaneureka
Hi everyone!

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);
}
^ I resolve cairo (symbols) and other libraries at link time.

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
My test cairo program:

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();
}
But it draws nothing :/ And no error. I tested this code with some random buffer address (instead of VBE.SecondaryBuffer I passed 0xAABB) no pagefault or something. Any idea why it is not working?


Thanks!

Re: Cairo not working!

Posted: Sat Dec 24, 2016 5:54 am
by klange
One of Cairo's dependencies - pixman - has some init hooks that use the "constructor" attribute. Are you sure you're running those correctly?

Re: Cairo not working!

Posted: Sat Dec 24, 2016 6:39 am
by amaneureka
klange wrote:One of Cairo's dependencies - pixman - has some init hooks that use the "constructor" attribute. Are you sure you're running those correctly?
Hmm "pixman_constructor", I am not even running it. not really sure how to do that.

Is it something like I have to call ".init" section generated by gcc?

Re: Cairo not working!

Posted: Sat Dec 24, 2016 6:48 am
by klange
amaneureka wrote:Hmm "pixman_constructor", I am not even running it. not really sure how to do that.

Is it something like I have to call ".init" section generated by gcc?
We actually have an article on the matter on the wiki.

Re: Cairo not working!

Posted: Sat Dec 24, 2016 10:21 am
by amaneureka
klange wrote:
amaneureka wrote:Hmm "pixman_constructor", I am not even running it. not really sure how to do that.

Is it something like I have to call ".init" section generated by gcc?
We actually have an article on the matter on the wiki.

Thank you so much! :)

It is working now
Image