[gjs] cairo: Add foreign mapping for Cairo.Surface
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] cairo: Add foreign mapping for Cairo.Surface
- Date: Tue, 21 May 2013 15:11:09 +0000 (UTC)
commit 2e5fd083df1240596efa00e554f1327c44eb5de2
Author: Colin Walters <walters verbum org>
Date: Fri May 17 10:14:09 2013 -0400
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
modules/cairo-private.h | 1 +
modules/cairo-surface.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
modules/cairo.c | 1 +
3 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 6edfb6d..411c33e 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 5f4d7a8..c38308c 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 6cde95d..d72e39c 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]