[gjs] [cairo] Add foreign support for Cairo.Context



commit 5ca6efa73c031d346f063d6f1efff3aed070fe58
Author: Johan Dahlin <johan gnome org>
Date:   Thu Mar 25 10:01:39 2010 -0300

    [cairo] Add foreign support for Cairo.Context
    
    https://bugzilla.gnome.org/show_bug.cgi?id=610357

 modules/cairo-context.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++
 modules/cairo-private.h |    1 +
 modules/cairo.c         |    1 +
 3 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index b21f779..49e86e5 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -23,6 +23,8 @@
 #include <config.h>
 
 #include <gjs/gjs.h>
+#include <gi/foreign.h>
+
 #include <cairo.h>
 #include "cairo-private.h"
 
@@ -815,3 +817,65 @@ gjs_cairo_context_get_context(JSContext *context,
 
     return priv->cr;
 }
+
+static JSBool
+context_to_g_argument(JSContext      *context,
+                      jsval           value,
+                      GITypeInfo     *type_info,
+                      const char     *arg_name,
+                      GjsArgumentType argument_type,
+                      GITransfer      transfer,
+                      gboolean        may_be_null,
+                      GArgument      *arg)
+{
+    JSObject *obj;
+    cairo_t *cr;
+
+    obj = JSVAL_TO_OBJECT(value);
+    cr = gjs_cairo_context_get_context(context, obj);
+    if (!cr)
+        return JS_FALSE;
+    if (transfer == GI_TRANSFER_EVERYTHING)
+        cairo_destroy(cr);
+
+    arg->v_pointer = cr;
+    return JS_TRUE;
+}
+
+static JSBool
+context_from_g_argument(JSContext  *context,
+                        jsval      *value_p,
+                        GITypeInfo *type_info,
+                        GArgument  *arg)
+{
+    JSObject *obj;
+
+    obj = gjs_cairo_context_from_context(context, (cairo_t*)arg->v_pointer);
+    if (!obj)
+        return JS_FALSE;
+
+    *value_p = OBJECT_TO_JSVAL(obj);
+    return JS_TRUE;
+}
+
+static JSBool
+context_release_argument(JSContext  *context,
+                         GITransfer  transfer,
+                         GITypeInfo *type_info,
+                         GArgument  *arg)
+{
+    cairo_destroy((cairo_t*)arg->v_pointer);
+    return JS_TRUE;
+}
+
+static GjsForeignInfo foreign_info = {
+    context_to_g_argument,
+    context_from_g_argument,
+    context_release_argument
+};
+
+void
+gjs_cairo_context_init(JSContext *context)
+{
+    gjs_struct_foreign_register("cairo", "Context", &foreign_info);
+}
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 0b252e1..2474d8a 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -40,6 +40,7 @@ cairo_t *        gjs_cairo_context_get_context          (JSContext       *contex
                                                          JSObject        *object);
 JSObject *       gjs_cairo_context_from_context         (JSContext       *context,
                                                          cairo_t         *cr);
+void             gjs_cairo_context_init                 (JSContext       *context);
 
 /* surface */
 jsval            gjs_cairo_surface_create_proto         (JSContext       *context,
diff --git a/modules/cairo.c b/modules/cairo.c
index f5c916a..002d2c5 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -53,6 +53,7 @@ gjs_js_define_cairo_stuff(JSContext *context,
                                          "Context", NULL);
     if (obj == JSVAL_NULL)
         return JS_FALSE;
+    gjs_cairo_context_init(context);
 
     obj = gjs_cairo_surface_create_proto(context, module,
                                          "Surface", NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]