[gjs/cairo: 3/5] [cairo] Add ImageSurface class
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/cairo: 3/5] [cairo] Add ImageSurface class
- Date: Wed, 17 Feb 2010 22:10:12 +0000 (UTC)
commit 84dea6379faec27a9c7c96180ef2b6fc1c11bf19
Author: Johan Dahlin <johan gnome org>
Date: Wed Feb 17 19:52:15 2010 -0200
[cairo] Add ImageSurface class
Makefile-modules.am | 1 +
modules/cairo-image-surface.c | 157 +++++++++++++++++++++++++++++++++++++++++
modules/cairo-private.h | 1 +
modules/cairo.c | 6 ++
4 files changed, 165 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index bcc56b5..9854325 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -84,6 +84,7 @@ cairoNative_la_LDFLAGS = \
cairoNative_la_SOURCES = \
modules/cairo-private.h \
modules/cairo-context.c \
+ modules/cairo-image-surface.c \
modules/cairo.c
diff --git a/modules/cairo-image-surface.c b/modules/cairo-image-surface.c
new file mode 100644
index 0000000..187a068
--- /dev/null
+++ b/modules/cairo-image-surface.c
@@ -0,0 +1,157 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* Copyright 2010 litl, LLC. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <gjs/gjs.h>
+#include <cairo.h>
+#include "cairo-private.h"
+
+typedef struct {
+ void *dummy;
+ JSContext *context;
+ JSObject *object;
+} GjsCairoImageSurface;
+
+static struct JSClass gjs_js_cairo_image_surface_class;
+
+GJS_DEFINE_PRIV_FROM_JS(GjsCairoImageSurface, gjs_js_cairo_image_surface_class);
+
+static JSBool
+cairo_image_surface_new_resolve(JSContext *context,
+ JSObject *obj,
+ jsval id,
+ uintN flags,
+ JSObject **objp)
+{
+ GjsCairoImageSurface *priv;
+ const char *name;
+
+ *objp = NULL;
+
+ if (!gjs_get_string_id(id, &name))
+ return JS_TRUE; /* not resolved, but no error */
+
+ priv = priv_from_js(context, obj);
+ if (priv == NULL)
+ return JS_TRUE; /* we are the prototype, or have the wrong class */
+
+ return JS_TRUE;
+}
+
+static JSBool
+cairo_image_surface_constructor(JSContext *context,
+ JSObject *obj,
+ uintN argc,
+ jsval *argv,
+ jsval *retval)
+{
+ GjsCairoImageSurface *priv;
+
+ priv = g_slice_new0(GjsCairoImageSurface);
+
+ g_assert(priv_from_js(context, obj) == NULL);
+ JS_SetPrivate(context, obj, priv);
+
+ priv->context = context;
+ priv->object = obj;
+
+ return JS_TRUE;
+}
+
+static void
+cairo_image_surface_finalize(JSContext *context,
+ JSObject *obj)
+{
+ GjsCairoImageSurface *priv;
+ priv = priv_from_js(context, obj);
+ if (priv == NULL)
+ return;
+
+ g_slice_free(GjsCairoImageSurface, priv);
+}
+
+static struct JSClass gjs_js_cairo_image_surface_class = {
+ "CairoImageSurface", /* means "new CairoContext()" works */
+ JSCLASS_HAS_PRIVATE |
+ JSCLASS_NEW_RESOLVE |
+ JSCLASS_NEW_RESOLVE_GETS_START,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_PropertyStub,
+ JS_EnumerateStub,
+ (JSResolveOp) cairo_image_surface_new_resolve, /* needs cast since it's the new resolve signature */
+ JS_ConvertStub,
+ cairo_image_surface_finalize,
+ NULL,
+ NULL,
+ NULL,
+ NULL, NULL, NULL, NULL, NULL
+};
+
+static JSPropertySpec gjs_js_cairo_image_surface_proto_props[] = {
+ { NULL }
+};
+
+static JSFunctionSpec gjs_js_cairo_image_surface_proto_funcs[] = {
+ { NULL }
+};
+
+jsval
+gjs_cairo_image_surface_create_proto(JSContext *context)
+{
+ JSContext *load_context;
+ JSObject *global;
+ jsval cairo_image_surface;
+
+ load_context = gjs_runtime_get_load_context(JS_GetRuntime(context));
+ global = JS_GetGlobalObject(context);
+
+ if (!gjs_object_has_property(load_context, global,
+ gjs_js_cairo_image_surface_class.name)) {
+ JSObject *prototype;
+
+ prototype = JS_InitClass(load_context, global,
+ NULL,
+ &gjs_js_cairo_image_surface_class,
+ cairo_image_surface_constructor,
+ 0,
+ &gjs_js_cairo_image_surface_proto_props[0],
+ &gjs_js_cairo_image_surface_proto_funcs[0],
+ NULL,
+ NULL);
+ if (prototype == NULL) {
+ gjs_move_exception(load_context, context);
+ return JSVAL_NULL;
+ }
+ if (!gjs_object_require_property(
+ load_context, global, NULL,
+ gjs_js_cairo_image_surface_class.name, &cairo_image_surface)) {
+ gjs_move_exception(load_context, context);
+ return JSVAL_NULL;
+ }
+ }
+
+ return cairo_image_surface;
+}
+
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 1d40c75..7c471ed 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -27,6 +27,7 @@ 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);
#endif /* __CAIRO_PRIVATE_H__ */
diff --git a/modules/cairo.c b/modules/cairo.c
index 6efec00..d7367b2 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -38,6 +38,12 @@ gjs_js_define_cairo_stuff(JSContext *context,
obj, NULL, NULL, GJS_MODULE_PROP_FLAGS))
return JS_FALSE;
+ obj = gjs_cairo_image_surface_create_proto(context);
+ if (obj == JSVAL_NULL ||
+ !JS_DefineProperty(context, module_obj, "ImageSurface",
+ obj, NULL, NULL, GJS_MODULE_PROP_FLAGS))
+ return JS_FALSE;
+
return JS_TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]