From: jpbruyere Date: Tue, 6 Jun 2017 10:47:32 +0000 (+0200) Subject: use internal calls for libcrow X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=8ed70c66911b483cccfa0a7b0c26dd80a061966b;p=jp%2Fcrow.git use internal calls for libcrow --- diff --git a/.gitignore b/.gitignore index 477bac00..6e57eec4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ Win_x86 Crow.userprefs Debug packages +*.o *.nupkg /GOLib.suo /tmp diff --git a/MDEmbedTest/MDEmbedTest.cproj b/MDEmbedTest/MDEmbedTest.cproj index 3c209afc..43502bcd 100644 --- a/MDEmbedTest/MDEmbedTest.cproj +++ b/MDEmbedTest/MDEmbedTest.cproj @@ -24,7 +24,7 @@ - + diff --git a/MDEmbedTest/Makefile b/MDEmbedTest/Makefile index 631fa272..53da377d 100644 --- a/MDEmbedTest/Makefile +++ b/MDEmbedTest/Makefile @@ -2,12 +2,13 @@ export PKG_CONFIG_PATH = /opt/mono/lib/pkgconfig CC = gcc CFLAGS = -Wall -Wextra -O2 -g -DDEBUG -LDFLAGS = +LDFLAGS = -L/devel/crow/build/Debug TARGET = mdembed SOURCES = main.c OBJECTS = $(SOURCES:.c=.o) +CFLAGS += -lcrow CFLAGS += `pkg-config --cflags --libs mono-2` CFLAGS += `pkg-config --cflags --libs cairo` CFLAGS += `pkg-config --cflags --libs gl` @@ -28,4 +29,4 @@ clean: .PHONY: run run: - -./${TARGET} test.exe \ No newline at end of file + -./${TARGET} ../build/Debug/testDrm.exe diff --git a/MDEmbedTest/libcrow.so b/MDEmbedTest/libcrow.so new file mode 100755 index 00000000..ff874cc4 Binary files /dev/null and b/MDEmbedTest/libcrow.so differ diff --git a/MDEmbedTest/main.c b/MDEmbedTest/main.c index 45a01cd3..a6f06783 100644 --- a/MDEmbedTest/main.c +++ b/MDEmbedTest/main.c @@ -3,6 +3,7 @@ #include #include #include +#include "../../libcrow/libcrow.h" /* * Very simple mono embedding example. @@ -26,16 +27,16 @@ static void main_function (MonoDomain *domain, const char *file, int argc, char* assembly = mono_domain_assembly_open (domain, file); if (!assembly) exit (2); - a2 = mono_domain_assembly_open (domain, "test2.exe"); - if (!a2) - exit (2); + //a2 = mono_domain_assembly_open (domain, "../build/Debug/testDrm.exe"); + //if (!a2) + // exit (2); /* * mono_jit_exec() will run the Main() method in the assembly. * The return value needs to be looked up from * System.Environment.ExitCode. */ mono_jit_exec (domain, assembly, argc, argv); - mono_jit_exec (domain, a2, argc, argv); + //mono_jit_exec (domain, a2, argc, argv); } int @@ -65,7 +66,22 @@ main(int argc, char* argv[]) { * We add our special internal call, so that C# code * can call us back. */ - mono_add_internal_call ("MonoEmbed::gimme", gimme); + mono_add_internal_call ("Crow.Native.LibCrow::gimme", gimme); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_create", crow_context_create); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_destroy", crow_context_destroy); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_set_root", crow_context_set_root); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_process_clipping", crow_context_process_clipping); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_process_layouting", crow_context_process_layouting); + mono_add_internal_call ("Crow.Native.LibCrow::crow_context_process_drawing", crow_context_process_drawing); + + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_create", crow_object_create); + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_destroy", crow_object_destroy); + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_set_type", crow_object_set_type); + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_do_layout", crow_object_do_layout); + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_register_layouting", crow_object_register_layouting); + + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_child_add", crow_object_child_add); + mono_add_internal_call ("Crow.Native.LibCrow::crow_object_child_remove", crow_object_child_remove); main_function (domain, file, argc - 1, argv + 1); diff --git a/MDEmbedTest/main.o b/MDEmbedTest/main.o deleted file mode 100644 index eb52af13..00000000 Binary files a/MDEmbedTest/main.o and /dev/null differ diff --git a/MDEmbedTest/mdembed b/MDEmbedTest/mdembed deleted file mode 100755 index db17b65d..00000000 Binary files a/MDEmbedTest/mdembed and /dev/null differ diff --git a/MDEmbedTest/test.exe b/MDEmbedTest/test.exe deleted file mode 100755 index b49eb856..00000000 Binary files a/MDEmbedTest/test.exe and /dev/null differ diff --git a/MDEmbedTest/test2.cs b/MDEmbedTest/test2.cs index eb23a837..ea85efd3 100644 --- a/MDEmbedTest/test2.cs +++ b/MDEmbedTest/test2.cs @@ -7,5 +7,6 @@ class MonoEmbed { static void Main() { Console.WriteLine ("test2 => " + gimme ()); + } } diff --git a/MDEmbedTest/test2.exe b/MDEmbedTest/test2.exe deleted file mode 100755 index c98fc48a..00000000 Binary files a/MDEmbedTest/test2.exe and /dev/null differ diff --git a/src/Crow.Native/LibCrow.cs b/src/Crow.Native/LibCrow.cs index 5496f19f..bd0a1473 100644 --- a/src/Crow.Native/LibCrow.cs +++ b/src/Crow.Native/LibCrow.cs @@ -25,35 +25,38 @@ // THE SOFTWARE. using System; using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; namespace Crow.Native { - internal static class LibCrow + public static class LibCrow { + [MethodImplAttribute(MethodImplOptions.InternalCall)] + public unsafe extern static string gimme(); #region PINVOKE const string lib = "libcrow"; - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern IntPtr crow_context_create (); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void crow_context_destroy (IntPtr ctx); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern void crow_context_set_root (IntPtr ctx, crow_object_t* root); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void crow_context_process_layouting (IntPtr ctx); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void crow_context_process_clipping (IntPtr ctx); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] internal static extern void crow_context_process_drawing (IntPtr ctx, IntPtr cairoCtx); - [DllImport(lib)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern crow_object_t* crow_object_create(); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern void crow_object_destroy(crow_object_t* go); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern void crow_object_set_type (crow_object_t* go, CrowType objType); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern byte crow_object_do_layout (crow_object_t* go, LayoutingType layout); - [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] + [MethodImplAttribute(MethodImplOptions.InternalCall)] unsafe internal static extern byte crow_object_register_layouting (crow_object_t* go, LayoutingType layout); diff --git a/testDrm/TestCrow.cs b/testDrm/TestCrow.cs index 552b7198..5e98ab56 100644 --- a/testDrm/TestCrow.cs +++ b/testDrm/TestCrow.cs @@ -48,22 +48,21 @@ namespace testDrm public int a = 10,b=20; } - [MethodImplAttribute(MethodImplOptions.InternalCall)] - unsafe extern static string gimme(); + [DllImport(lib, CallingConvention = CallingConvention.Cdecl)] internal static extern void registerICall (); static void Main(){ - registerICall (); - Console.WriteLine (gimme()); + //registerICall (); + Console.WriteLine (Crow.Native.LibCrow. gimme()); - /*using (Interface iface = new Interface ()) { + using (Interface iface = new Interface ()) { Console.WriteLine ("is dirty: {0}", iface.IsDirty); iface.ProcessResize (new Rectangle (0, 0, 1024, 768)); iface.LoadInterface ("#testDrm.ui.go.crow"); iface.Update (); iface.DumpTo ("/home/jp/test.png"); - }*/ + } } } }