diff --git a/lime/_backend/native/NativeCFFI.hx b/lime/_backend/native/NativeCFFI.hx index 6501e1165..5a6796af1 100644 --- a/lime/_backend/native/NativeCFFI.hx +++ b/lime/_backend/native/NativeCFFI.hx @@ -334,7 +334,7 @@ class NativeCFFI { @:cffi private static function lime_window_set_maximized (handle:Dynamic, maximized:Bool):Bool; @:cffi private static function lime_window_set_minimized (handle:Dynamic, minimized:Bool):Bool; @:cffi private static function lime_window_set_resizable (handle:Dynamic, resizable:Bool):Bool; - @:cffi private static function lime_window_set_title (handle:Dynamic, title:String):Dynamic; + @:hlNative("lime", "lime_window_set_title") private static function lime_window_set_title (handle:CFFIPointer, title:String):String { return null; } @:hlNative("lime", "lime_window_event_manager_register") private static function lime_window_event_manager_register (callback:Void->Void, eventObject:WindowEventInfo):Void {} @:cffi private static function lime_zlib_compress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_zlib_decompress (data:Dynamic, bytes:Dynamic):Dynamic; diff --git a/lime/system/CFFI.hx b/lime/system/CFFI.hx index f26e7d2ac..7f8bfb03b 100644 --- a/lime/system/CFFI.hx +++ b/lime/system/CFFI.hx @@ -60,7 +60,7 @@ class CFFI { */ public static function load (library:String, method:String, args:Int = 0, lazy:Bool = false):Dynamic { - #if (disable_cffi || macro) + #if (disable_cffi || macro || hl) var enabled = false; #end @@ -200,7 +200,7 @@ class CFFI { public static macro function loadPrime (library:String, method:String, signature:String, lazy:Bool = false):Dynamic { - #if (!display && !macro) + #if (!display && !macro && cpp) return cpp.Prime.load (library, method, signature, lazy); #else var args = signature.length - 1; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 632fcb3bd..dcee32fb2 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -69,8 +69,9 @@ namespace lime { } - void hl_gc_application (Application* application) { + void hl_gc_application (HL_CFFIPointer* handle) { + Application* application = (Application*)handle->ptr; delete application; } @@ -86,9 +87,10 @@ namespace lime { } - void hl_gc_file_watcher (FileWatcher* watcher) { + void hl_gc_file_watcher (HL_CFFIPointer* handle) { #ifdef LIME_EFSW + FileWatcher* watcher = (FileWatcher*)handle->ptr; delete watcher; #endif @@ -105,9 +107,10 @@ namespace lime { } - void hl_gc_font (Font* font) { + void hl_gc_font (HL_CFFIPointer* handle) { #ifdef LIME_FREETYPE + Font* font = (Font*)handle->ptr; delete font; #endif @@ -122,8 +125,9 @@ namespace lime { } - void hl_gc_renderer (Renderer* renderer) { + void hl_gc_renderer (HL_CFFIPointer* handle) { + Renderer* renderer = (Renderer*)handle->ptr; delete renderer; } @@ -139,9 +143,10 @@ namespace lime { } - void hl_gc_text_layout (TextLayout* text) { + void hl_gc_text_layout (HL_CFFIPointer* handle) { #ifdef LIME_HARFBUZZ + TextLayout* text = (TextLayout*)handle->ptr; delete text; #endif @@ -156,8 +161,9 @@ namespace lime { } - void hl_gc_window (Window* window) { + void hl_gc_window (HL_CFFIPointer* handle) { + Window* window = (Window*)handle->ptr; delete window; } @@ -3537,7 +3543,7 @@ namespace lime { HL_PRIM HL_CFFIPointer* hl_lime_window_create (HL_CFFIPointer* application, int width, int height, int flags, HL_String* title) { - Window* window = CreateWindow ((Application*)application->ptr, width, height, flags, (const char*)title->bytes); + Window* window = CreateWindow ((Application*)application->ptr, width, height, flags, (const char*)hl_to_utf8 ((const uchar*)title->bytes)); return HLCFFIPointer (window, (hl_finalizer)hl_gc_window); } @@ -3903,10 +3909,10 @@ namespace lime { } - HL_PRIM vbyte* hl_lime_window_set_title (HL_CFFIPointer* window, vbyte* title) { + HL_PRIM HL_String* hl_lime_window_set_title (HL_CFFIPointer* window, HL_String* title) { Window* targetWindow = (Window*)window->ptr; - const char* result = targetWindow->SetTitle ((char*)title); + const char* result = targetWindow->SetTitle ((char*)hl_to_utf8 ((const uchar*)title->bytes)); if (result) { @@ -3919,7 +3925,8 @@ namespace lime { // } // return _result; - return (vbyte*)result; + //return (vbyte*)result; + return title; } else { @@ -4323,7 +4330,7 @@ namespace lime { // DEFINE_PRIME2 (lime_window_set_maximized); // DEFINE_PRIME2 (lime_window_set_minimized); // DEFINE_PRIME2 (lime_window_set_resizable); - // DEFINE_PRIME2 (lime_window_set_title); + DEFINE_HL_PRIM (_STRING, lime_window_set_title, _TCFFIPOINTER _STRING); // DEFINE_PRIME2 (lime_zlib_compress); // DEFINE_PRIME2 (lime_zlib_decompress); diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index 5a9bd6d54..1be9db218 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -191,6 +191,7 @@ namespace lime { } + void* SDLRenderer::Lock (bool useCFFIValue) { if (sdlRenderer) { @@ -232,14 +233,19 @@ namespace lime { } else { + const int id_width = hl_hash_utf8 ("width"); + const int id_height = hl_hash_utf8 ("height"); + const int id_pixels = hl_hash_utf8 ("pixels"); + const int id_pitch = hl_hash_utf8 ("pitch"); + vdynamic* result = (vdynamic*)hl_alloc_dynobj (); if (SDL_LockTexture (sdlTexture, NULL, &pixels, &pitch) == 0) { - hl_dyn_seti (result, hl_hash_utf8 ("width"), &hlt_i32, width); - hl_dyn_seti (result, hl_hash_utf8 ("height"), &hlt_i32, height); - hl_dyn_setd (result, hl_hash_utf8 ("pixels"), (uintptr_t)pixels); - hl_dyn_seti (result, hl_hash_utf8 ("pitch"), &hlt_i32, pitch); + hl_dyn_seti (result, id_width, &hlt_i32, width); + hl_dyn_seti (result, id_height, &hlt_i32, height); + hl_dyn_setd (result, id_pixels, (uintptr_t)pixels); + hl_dyn_seti (result, id_pitch, &hlt_i32, pitch); } diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index f14f68887..ab8a10527 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -20,7 +20,7 @@ namespace lime { static int id_y; static bool init = false; cairo_user_data_key_t userData; - std::map cairoObjects; + std::map cairoObjects; Mutex cairoObjects_Mutex; @@ -39,11 +39,13 @@ namespace lime { } - void hl_gc_cairo (cairo_t* cairo) { + void hl_gc_cairo (HL_CFFIPointer* handle) { - // cairoObjects_Mutex.Lock (); - // cairoObjects.erase (cairo); - // cairoObjects_Mutex.Unlock (); + cairo_t* cairo = (cairo_t*)handle->ptr; + + cairoObjects_Mutex.Lock (); + cairoObjects.erase (cairo); + cairoObjects_Mutex.Unlock (); cairo_destroy (cairo); } @@ -106,11 +108,13 @@ namespace lime { } - void hl_gc_cairo_surface (cairo_surface_t* surface) { + void hl_gc_cairo_surface (HL_CFFIPointer* handle) { - // cairoObjects_Mutex.Lock (); - // cairoObjects.erase (surface); - // cairoObjects_Mutex.Unlock (); + cairo_surface_t* surface = (cairo_surface_t*)handle->ptr; + + cairoObjects_Mutex.Lock (); + cairoObjects.erase (surface); + cairoObjects_Mutex.Unlock (); cairo_surface_destroy (surface); } @@ -191,9 +195,9 @@ namespace lime { cairo_t* cairo = cairo_create ((cairo_surface_t*)surface->ptr); HL_CFFIPointer* object = HLCFFIPointer (cairo, (hl_finalizer)hl_gc_cairo); - // cairoObjects_Mutex.Lock (); - // cairoObjects[cairo] = object; - // cairoObjects_Mutex.Unlock (); + cairoObjects_Mutex.Lock (); + cairoObjects[cairo] = object; + cairoObjects_Mutex.Unlock (); return object; } @@ -379,7 +383,7 @@ namespace lime { if (cairoObjects.find (face) != cairoObjects.end ()) { - return cairoObjects[face]; + return (value)cairoObjects[face]; } else { @@ -411,7 +415,7 @@ namespace lime { if (cairoObjects.find (surface) != cairoObjects.end ()) { - return cairoObjects[surface]; + return (value)cairoObjects[surface]; } else { @@ -479,7 +483,7 @@ namespace lime { if (cairoObjects.find (pattern) != cairoObjects.end ()) { - return cairoObjects[pattern]; + return (value)cairoObjects[pattern]; } else { @@ -502,7 +506,7 @@ namespace lime { if (cairoObjects.find (surface) != cairoObjects.end ()) { - return cairoObjects[surface]; + return (value)cairoObjects[surface]; } else { @@ -571,9 +575,9 @@ namespace lime { cairo_surface_t* surface = cairo_image_surface_create_for_data ((unsigned char*)(uintptr_t)data, (cairo_format_t)format, width, height, stride); HL_CFFIPointer* object = HLCFFIPointer (surface, (hl_finalizer)hl_gc_cairo_surface); - // cairoObjects_Mutex.Lock (); - // cairoObjects[surface] = object; - // cairoObjects_Mutex.Unlock (); + cairoObjects_Mutex.Lock (); + cairoObjects[surface] = object; + cairoObjects_Mutex.Unlock (); return object; } @@ -835,7 +839,7 @@ namespace lime { if (cairoObjects.find (pattern) != cairoObjects.end ()) { - return cairoObjects[pattern]; + return (value)cairoObjects[pattern]; } else {