Commit 0a580912 authored by Johan Dahlin's avatar Johan Dahlin

[cairo] Check status after all cairo calls

parent 360f7bdf
......@@ -79,7 +79,6 @@ gjs> pattern.set_filter(Cairo.Filter.NEAREST);
TODO:
* string leaks in macros
* status checking + raising after all calls
* reference counting
* context: wrap the remaning methods
* surface methods
......
......@@ -36,8 +36,10 @@ mname##_func(JSContext *context, \
{ \
cairo_t *cr;
#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END \
return JS_TRUE; \
#define _GJS_CAIRO_CONTEXT_DEFINE_FUNC_END \
if (!gjs_cairo_check_status(context, cairo_status(cr), "context")) \
return JS_FALSE; \
return JS_TRUE; \
}
#define _GJS_CAIRO_CONTEXT_CHECK_NO_ARGS(m) \
......@@ -228,7 +230,6 @@ gjs_cairo_context_constructor(JSContext *context,
JSObject *surface_wrapper;
cairo_surface_t *surface;
cairo_t *cr;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -244,12 +245,9 @@ gjs_cairo_context_constructor(JSContext *context,
}
cr = cairo_create(surface);
status = cairo_status(cr);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Could not create context: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
return JS_FALSE;
}
_gjs_cairo_context_construct_internal(context, obj, cr);
......@@ -376,6 +374,9 @@ mask_func(JSContext *context,
cr = gjs_cairo_context_get_context(context, obj);
cairo_mask(cr, pattern);
if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
return JS_FALSE;
return JS_TRUE;
}
......@@ -404,8 +405,12 @@ maskSurface_func(JSContext *context,
}
cr = gjs_cairo_context_get_context(context, obj);
cairo_mask_surface(cr, surface, x, y);
if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
return JS_FALSE;
return JS_TRUE;
}
......@@ -431,8 +436,12 @@ setSource_func(JSContext *context,
}
cr = gjs_cairo_context_get_context(context, obj);
cairo_set_source(cr, pattern);
if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
return JS_FALSE;
return JS_TRUE;
}
static JSBool
......@@ -460,8 +469,12 @@ setSourceSurface_func(JSContext *context,
}
cr = gjs_cairo_context_get_context(context, obj);
cairo_set_source_surface(cr, surface, x, y);
if (!gjs_cairo_check_status(context, cairo_status(cr), "context"))
return JS_FALSE;
return JS_TRUE;
}
......
......@@ -60,8 +60,12 @@ addColorStopRGB_func(JSContext *context,
return JS_FALSE;
pattern = gjs_cairo_pattern_get_pattern(context, object);
cairo_pattern_add_color_stop_rgb(pattern, offset, red, green, blue);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
return JS_TRUE;
}
......@@ -86,6 +90,9 @@ addColorStopRGBA_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, alpha);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
return JS_TRUE;
}
......
......@@ -37,7 +37,6 @@ gjs_cairo_image_surface_constructor(JSContext *context,
{
int format, width, height;
cairo_surface_t *surface;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -50,12 +49,10 @@ gjs_cairo_image_surface_constructor(JSContext *context,
return JS_FALSE;
surface = cairo_image_surface_create(format, width, height);
status = cairo_surface_status(surface);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo surface: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_surface_status(surface), "surface"))
return JS_FALSE;
}
gjs_cairo_surface_construct(context, obj, surface);
return JS_TRUE;
......@@ -82,18 +79,16 @@ createFromPNG_func(JSContext *context,
char *filename;
cairo_surface_t *surface;
JSObject *surface_wrapper;
cairo_status_t status;
if (!gjs_parse_args(context, "createFromPNG", "s", argc, argv,
"filename", &filename))
return JS_FALSE;
surface = cairo_image_surface_create_from_png(filename);
status = cairo_surface_status(surface);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "failed to create surface: %s", cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_surface_status(surface), "surface"))
return JS_FALSE;
}
surface_wrapper = JS_NewObject(context, &gjs_cairo_image_surface_class, NULL, NULL);
if (!surface_wrapper) {
gjs_throw(context, "failed to create surface");
......
......@@ -37,7 +37,6 @@ gjs_cairo_linear_gradient_constructor(JSContext *context,
{
double x0, y0, x1, y1;
cairo_pattern_t *pattern;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -50,12 +49,10 @@ gjs_cairo_linear_gradient_constructor(JSContext *context,
return JS_FALSE;
pattern = cairo_pattern_create_linear(x0, y0, x1, y1);
status = cairo_pattern_status(pattern);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo pattern: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
}
gjs_cairo_pattern_construct(context, obj, pattern);
return JS_TRUE;
......
......@@ -84,6 +84,9 @@ getType_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
type = cairo_pattern_get_type(pattern);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
*retval = INT_TO_JSVAL(type);
return JS_TRUE;
}
......
......@@ -41,7 +41,6 @@ gjs_cairo_pdf_surface_constructor(JSContext *context,
char *filename;
double width, height;
cairo_surface_t *surface;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -53,10 +52,9 @@ gjs_cairo_pdf_surface_constructor(JSContext *context,
return JS_FALSE;
surface = cairo_pdf_surface_create(filename, width, height);
status = cairo_surface_status(surface);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo surface: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_surface_status(surface),
"surface")) {
g_free(filename);
return JS_FALSE;
}
......
......@@ -35,6 +35,10 @@ typedef struct {
JSBool gjs_js_define_cairo_stuff (JSContext *context,
JSObject *module);
JSBool gjs_cairo_check_status (JSContext *context,
cairo_status_t status,
const char *name);
jsval gjs_cairo_context_create_proto (JSContext *context,
JSObject *module,
const char *proto_name,
......
......@@ -41,7 +41,6 @@ gjs_cairo_ps_surface_constructor(JSContext *context,
char *filename;
double width, height;
cairo_surface_t *surface;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -53,13 +52,15 @@ gjs_cairo_ps_surface_constructor(JSContext *context,
return JS_FALSE;
surface = cairo_ps_surface_create(filename, width, height);
status = cairo_surface_status(surface);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo surface: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_surface_status(surface),
"surface")) {
g_free(filename);
return JS_FALSE;
}
gjs_cairo_surface_construct(context, obj, surface);
g_free(filename);
return JS_TRUE;
}
......
......@@ -37,7 +37,6 @@ gjs_cairo_radial_gradient_constructor(JSContext *context,
{
double cx0, cy0, radius0, cx1, cy1, radius1;
cairo_pattern_t *pattern;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -52,12 +51,10 @@ gjs_cairo_radial_gradient_constructor(JSContext *context,
return JS_FALSE;
pattern = cairo_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1);
status = cairo_pattern_status(pattern);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo pattern: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
}
gjs_cairo_pattern_construct(context, obj, pattern);
return JS_TRUE;
......
......@@ -38,7 +38,6 @@ gjs_cairo_surface_pattern_constructor(JSContext *context,
JSObject *surface_wrapper;
cairo_surface_t *surface;
cairo_pattern_t *pattern;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -54,12 +53,10 @@ gjs_cairo_surface_pattern_constructor(JSContext *context,
}
pattern = cairo_pattern_create_for_surface(surface);
status = cairo_pattern_status(pattern);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo pattern: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
}
gjs_cairo_pattern_construct(context, obj, pattern);
return JS_TRUE;
......@@ -95,6 +92,9 @@ setExtend_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
cairo_pattern_set_extend(pattern, extend);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
return JS_TRUE;
}
......@@ -115,6 +115,10 @@ getExtend_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
extend = cairo_pattern_get_extend(pattern);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
*retval = INT_TO_JSVAL(extend);
return JS_TRUE;
......@@ -137,6 +141,9 @@ setFilter_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
cairo_pattern_set_filter(pattern, filter);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
return JS_TRUE;
}
......@@ -157,6 +164,10 @@ getFilter_func(JSContext *context,
pattern = gjs_cairo_pattern_get_pattern(context, object);
filter = cairo_pattern_get_filter(pattern);
if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
return JS_FALSE;
*retval = INT_TO_JSVAL(filter);
return JS_TRUE;
......
......@@ -41,7 +41,6 @@ gjs_cairo_svg_surface_constructor(JSContext *context,
char *filename;
double width, height;
cairo_surface_t *surface;
cairo_status_t status;
if (!gjs_check_constructing(context))
return JS_FALSE;
......@@ -53,14 +52,16 @@ gjs_cairo_svg_surface_constructor(JSContext *context,
return JS_FALSE;
surface = cairo_svg_surface_create(filename, width, height);
status = cairo_surface_status(surface);
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Failed to create cairo surface: %s",
cairo_status_to_string(status));
if (!gjs_cairo_check_status(context, cairo_surface_status(surface),
"surface")) {
g_free(filename);
return JS_FALSE;
}
gjs_cairo_surface_construct(context, obj, surface);
g_free(filename);
return JS_TRUE;
}
......
......@@ -26,6 +26,21 @@
#include "cairo-private.h"
JSBool
gjs_cairo_check_status(JSContext *context,
cairo_status_t status,
const char *name)
{
if (status != CAIRO_STATUS_SUCCESS) {
gjs_throw(context, "Could not create %s: %s",
name,
cairo_status_to_string(status));
return JS_FALSE;
}
return JS_TRUE;
}
JSBool
gjs_js_define_cairo_stuff(JSContext *context,
JSObject *module)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment