summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-05-17 10:14:09 -0400
committerColin Walters <walters@verbum.org>2013-05-21 11:10:48 -0400
commit2e5fd083df1240596efa00e554f1327c44eb5de2 (patch)
tree591d02a57de727493eec20ba225c1848c5919c96
parent75b04f0fb5704f2296f38d82ea1f01a78785c4d2 (diff)
downloadgjs-2e5fd083df1240596efa00e554f1327c44eb5de2.tar.gz
cairo: Add foreign mapping for Cairo.Surface
This allows one to pass a cairo_surface_t to API like Gdk.pixbuf_new_from_surface(). Reported-by: Seif Lotfy <seif@lotfy.com> https://bugzilla.gnome.org/show_bug.cgi?id=700529
-rw-r--r--modules/cairo-private.h1
-rw-r--r--modules/cairo-surface.c59
-rw-r--r--modules/cairo.c1
3 files changed, 61 insertions, 0 deletions
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 6edfb6d8..411c33ef 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -39,6 +39,7 @@ cairo_t * gjs_cairo_context_get_context (JSContext *contex
JSObject * gjs_cairo_context_from_context (JSContext *context,
cairo_t *cr);
void gjs_cairo_context_init (JSContext *context);
+void gjs_cairo_surface_init (JSContext *context);
/* cairo_path_t */
diff --git a/modules/cairo-surface.c b/modules/cairo-surface.c
index 5f4d7a89..c38308c9 100644
--- a/modules/cairo-surface.c
+++ b/modules/cairo-surface.c
@@ -24,6 +24,7 @@
#include <gjs/gjs-module.h>
#include <gjs/compat.h>
+#include <gi/foreign.h>
#include <cairo.h>
#include "cairo-private.h"
@@ -243,3 +244,61 @@ gjs_cairo_surface_get_surface(JSContext *context,
return priv->surface;
}
+static JSBool
+surface_to_g_argument(JSContext *context,
+ jsval value,
+ const char *arg_name,
+ GjsArgumentType argument_type,
+ GITransfer transfer,
+ gboolean may_be_null,
+ GArgument *arg)
+{
+ JSObject *obj;
+ cairo_surface_t *s;
+
+ obj = JSVAL_TO_OBJECT(value);
+ s = gjs_cairo_surface_get_surface(context, obj);
+ if (!s)
+ return JS_FALSE;
+ if (transfer == GI_TRANSFER_EVERYTHING)
+ cairo_surface_destroy(s);
+
+ arg->v_pointer = s;
+ return JS_TRUE;
+}
+
+static JSBool
+surface_from_g_argument(JSContext *context,
+ jsval *value_p,
+ GArgument *arg)
+{
+ JSObject *obj;
+
+ obj = gjs_cairo_surface_from_surface(context, (cairo_surface_t*)arg->v_pointer);
+ if (!obj)
+ return JS_FALSE;
+
+ *value_p = OBJECT_TO_JSVAL(obj);
+ return JS_TRUE;
+}
+
+static JSBool
+surface_release_argument(JSContext *context,
+ GITransfer transfer,
+ GArgument *arg)
+{
+ cairo_surface_destroy((cairo_surface_t*)arg->v_pointer);
+ return JS_TRUE;
+}
+
+static GjsForeignInfo foreign_info = {
+ surface_to_g_argument,
+ surface_from_g_argument,
+ surface_release_argument
+};
+
+void
+gjs_cairo_surface_init(JSContext *context)
+{
+ gjs_struct_foreign_register("cairo", "Surface", &foreign_info);
+}
diff --git a/modules/cairo.c b/modules/cairo.c
index 6cde95de..d72e39c4 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -55,6 +55,7 @@ gjs_js_define_cairo_stuff(JSContext *context,
if (JSVAL_IS_NULL(obj))
return JS_FALSE;
gjs_cairo_context_init(context);
+ gjs_cairo_surface_init(context);
obj = gjs_cairo_surface_create_proto(context, module,
"Surface", NULL);