[gjs/cairo: 4/5] [cairo] Implement ImageSurface constructor



commit e60598dfa9d027cbc0261563e6adb9cb579bf4e8
Author: Johan Dahlin <johan gnome org>
Date:   Wed Feb 17 20:09:16 2010 -0200

    [cairo] Implement ImageSurface constructor

 modules/cairo-image-surface.c |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
index 187a068..5f32c49 100644
--- a/modules/cairo-image-surface.c
+++ b/modules/cairo-image-surface.c
@@ -30,6 +30,7 @@ typedef struct {
     void *dummy;
     JSContext  *context;
     JSObject   *object;
+    cairo_surface_t *surface;
 } GjsCairoImageSurface;
 
 static struct JSClass gjs_js_cairo_image_surface_class;
@@ -66,7 +67,21 @@ cairo_image_surface_constructor(JSContext *context,
                           jsval     *retval)
 {
     GjsCairoImageSurface *priv;
-
+    int format, width, height;
+    cairo_surface_t *surface;
+
+    if (!gjs_parse_args(context, "ImageSurface", "iii", argc, argv,
+                        "format", &format,
+                        "width", &width,
+                        "height", &height))
+        return JS_FALSE;
+
+    surface = cairo_image_surface_create(format, width, height);
+    if (cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) {
+        /* FIXME: set cairo exception properly */
+        fprintf(stderr, "FIXME set exception");
+        return JS_FALSE;
+    }
     priv = g_slice_new0(GjsCairoImageSurface);
 
     g_assert(priv_from_js(context, obj) == NULL);
@@ -74,6 +89,7 @@ cairo_image_surface_constructor(JSContext *context,
 
     priv->context = context;
     priv->object = obj;
+    priv->surface = surface;
 
     return JS_TRUE;
 }
@@ -87,6 +103,7 @@ cairo_image_surface_finalize(JSContext *context,
     if (priv == NULL)
         return;
 
+    cairo_surface_destroy(priv->surface);
     g_slice_free(GjsCairoImageSurface, priv);
 }
 



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