about summary refs log tree commit diff stats
path: root/src/wrapped32/wrappedcairo.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-12-12 13:09:07 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-12-12 13:09:07 +0100
commit566ff08109b339eb3d45eaf5b0feb67eb2a12215 (patch)
tree00b09d9d2c2ca9c2acadaf0f01c7485e95b0ab5c /src/wrapped32/wrappedcairo.c
parent2247b61ed3c67ecce0bf2bd9a9b3f41e769bb05e (diff)
downloadbox64-566ff08109b339eb3d45eaf5b0feb67eb2a12215.tar.gz
box64-566ff08109b339eb3d45eaf5b0feb67eb2a12215.zip
[BOX32][WRAPPER] Added 32bits wrapped libcairo
Diffstat (limited to 'src/wrapped32/wrappedcairo.c')
-rw-r--r--src/wrapped32/wrappedcairo.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/wrapped32/wrappedcairo.c b/src/wrapped32/wrappedcairo.c
new file mode 100644
index 00000000..da155f07
--- /dev/null
+++ b/src/wrapped32/wrappedcairo.c
@@ -0,0 +1,120 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#define _GNU_SOURCE         /* See feature_test_macros(7) */
+#include <dlfcn.h>
+
+#include "wrappedlibs.h"
+
+#include "debug.h"
+#include "wrapper32.h"
+#include "bridge.h"
+#include "librarian/library_private.h"
+#include "x64emu.h"
+#include "emu/x64emu_private.h"
+#include "callback.h"
+#include "librarian.h"
+#include "box32context.h"
+#include "emu/x64emu_private.h"
+#include "myalign32.h"
+#include "converter32.h"
+
+static const char* cairoName = "libcairo.so.2";
+#define LIBNAME cairo
+
+#include "generated/wrappedcairotypes32.h"
+
+#include "wrappercallback32.h"
+
+#define SUPER() \
+GO(0)   \
+GO(1)   \
+GO(2)   \
+GO(3)   \
+GO(4)
+
+// destroy ...
+#define GO(A)   \
+static uintptr_t my_destroy_fct_##A = 0;        \
+static void my_destroy_##A(void* a)             \
+{                                               \
+    RunFunctionFmt(my_destroy_fct_##A, "p", a); \
+}
+SUPER()
+#undef GO
+static void* find_destroy_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_destroy_fct_##A == (uintptr_t)fct) return my_destroy_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_destroy_fct_##A == 0) {my_destroy_fct_##A = (uintptr_t)fct; return my_destroy_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for cairo destroy callback\n");
+    return NULL;
+}
+static void* reverse_destroy_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(CheckBridged(my_lib->w.bridge, fct))
+        return (void*)CheckBridged(my_lib->w.bridge, fct);
+    #define GO(A) if(my_destroy_##A == fct) return (void*)my_destroy_fct_##A;
+    SUPER()
+    #undef GO
+    return (void*)AddBridge(my_lib->w.bridge, vFp_32, fct, 0, NULL);
+}
+// cairo_write_func ...
+#define GO(A)   \
+static uintptr_t my_cairo_write_func_fct_##A = 0;                       \
+static uint32_t my_cairo_write_func_##A(void* a, void* b, uint32_t c)   \
+{                                                                       \
+    return RunFunctionFmt(my_cairo_write_func_fct_##A, "ppu", a, b, c); \
+}
+SUPER()
+#undef GO
+static void* find_cairo_write_func_Fct(void* fct)
+{
+    if(!fct) return fct;
+    if(GetNativeFnc((uintptr_t)fct))  return GetNativeFnc((uintptr_t)fct);
+    #define GO(A) if(my_cairo_write_func_fct_##A == (uintptr_t)fct) return my_cairo_write_func_##A;
+    SUPER()
+    #undef GO
+    #define GO(A) if(my_cairo_write_func_fct_##A == 0) {my_cairo_write_func_fct_##A = (uintptr_t)fct; return my_cairo_write_func_##A; }
+    SUPER()
+    #undef GO
+    printf_log(LOG_NONE, "Warning, no more slot for cairo cairo_write_func callback\n");
+    return NULL;
+}
+#undef SUPER
+
+EXPORT void* my32_cairo_xcb_device_get_connection(x64emu_t* emu, void* a)
+{
+    return add_xcb_connection32(my->cairo_xcb_device_get_connection(a));
+}
+
+EXPORT uint32_t my32_cairo_surface_set_user_data(x64emu_t* emu, void* surf, void* key, void* data, void* d)
+{
+    return my->cairo_surface_set_user_data(surf, key, data, find_destroy_Fct(d));
+}
+
+EXPORT uint32_t my32_cairo_set_user_data(x64emu_t* emu, void* cr, void* key, void* data, void* d)
+{
+    return my->cairo_set_user_data(cr, key, data, find_destroy_Fct(d));
+}
+
+void inplace_FT_FaceRec_shrink(void* a);
+EXPORT void* my32_cairo_ft_scaled_font_lock_face(x64emu_t* emu, void* font)
+{
+    void* ret = my->cairo_ft_scaled_font_lock_face(font);
+    inplace_FT_FaceRec_shrink(ret);
+    return ret;
+}
+
+EXPORT void* my32_cairo_pdf_surface_create_for_stream(x64emu_t* emu, void* f, void* closure, double width, double height)
+{
+    return my->cairo_pdf_surface_create_for_stream(find_cairo_write_func_Fct(f), closure, width, height);
+}
+
+#include "wrappedlib_init32.h"
\ No newline at end of file