[gjs/cairo] [cairo] Implement Context constructor
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/cairo] [cairo] Implement Context constructor
- Date: Wed, 17 Feb 2010 22:21:47 +0000 (UTC)
commit d8ab7e98bbadcbc015488c6296c6dddd61706003
Author: Johan Dahlin <johan gnome org>
Date: Wed Feb 17 20:20:40 2010 -0200
[cairo] Implement Context constructor
modules/cairo-context.c | 21 +++++++++++++++++++++
modules/cairo-image-surface.c | 11 +++++++++++
modules/cairo-private.h | 4 ++++
3 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index e857791..c853f7c 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -30,6 +30,7 @@ typedef struct {
void *dummy;
JSContext *context;
JSObject *object;
+ cairo_t * cr;
} GjsCairoContext;
static struct JSClass gjs_js_cairo_context_class;
@@ -66,6 +67,24 @@ cairo_context_constructor(JSContext *context,
jsval *retval)
{
GjsCairoContext *priv;
+ JSObject *surface_wrapper;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ if (!gjs_parse_args(context, "Context", "o", argc, argv,
+ "surface", &surface_wrapper))
+ return JS_FALSE;
+
+ surface = gjs_cairo_image_surface_get_surface(context, surface_wrapper);
+ if (!surface)
+ return JS_FALSE;
+
+ cr = cairo_create(surface);
+ if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) {
+ /* FIXME: set cairo exception properly */
+ fprintf(stderr, "FIXME set exception");
+ return JS_FALSE;
+ }
priv = g_slice_new0(GjsCairoContext);
@@ -74,6 +93,7 @@ cairo_context_constructor(JSContext *context,
priv->context = context;
priv->object = obj;
+ priv->cr = cr;
return JS_TRUE;
}
@@ -87,6 +107,7 @@ cairo_context_finalize(JSContext *context,
if (priv == NULL)
return;
+ cairo_destroy(priv->cr);
g_slice_free(GjsCairoContext, priv);
}
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
index 5f32c49..99f2e86 100644
--- a/modules/cairo-image-surface.c
+++ b/modules/cairo-image-surface.c
@@ -172,3 +172,14 @@ gjs_cairo_image_surface_create_proto(JSContext *context)
return cairo_image_surface;
}
+cairo_surface_t *
+gjs_cairo_image_surface_get_surface(JSContext *context,
+ JSObject *object)
+{
+ GjsCairoImageSurface *priv;
+ priv = priv_from_js(context, object);
+ if (priv == NULL)
+ return NULL;
+ return priv->surface;
+}
+
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 7c471ed..0c2381f 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -23,11 +23,15 @@
#ifndef __CAIRO_PRIVATE_H__
#define __CAIRO_PRIVATE_H__
+#include <cairo.h>
+
JSBool gjs_js_define_cairo_stuff(JSContext *context,
JSObject *module_obj);
jsval gjs_cairo_context_create_proto(JSContext *context);
jsval gjs_cairo_image_surface_create_proto(JSContext *context);
+cairo_surface_t * gjs_cairo_image_surface_get_surface(JSContext *context,
+ JSObject *object);
#endif /* __CAIRO_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]