diff options
author | tuberry <17917040+tuberry@users.noreply.github.com> | 2022-11-21 21:15:14 +0800 |
---|---|---|
committer | tuberry <17917040+tuberry@users.noreply.github.com> | 2022-11-21 21:41:05 +0800 |
commit | cff70ffcf5493743a71f313abb83528a5c4cb488 (patch) | |
tree | cd5f56a3c8952b8caa1956f00203d140b1b10b16 | |
parent | f547e2da1a7d06784910aac1f6c25badbefb3193 (diff) | |
download | gjs-cff70ffcf5493743a71f313abb83528a5c4cb488.tar.gz |
cairo-surface: Add finish() and flush()
closes #515
-rw-r--r-- | installed-tests/js/testCairo.js | 14 | ||||
-rw-r--r-- | modules/cairo-surface.cpp | 51 |
2 files changed, 64 insertions, 1 deletions
diff --git a/installed-tests/js/testCairo.js b/installed-tests/js/testCairo.js index c0c6d119..e9ede59f 100644 --- a/installed-tests/js/testCairo.js +++ b/installed-tests/js/testCairo.js @@ -283,6 +283,20 @@ describe('Cairo', function () { expect(x).toEqual(50); expect(y).toEqual(50); }); + + it('can be finalized', function () { + expect(() => { + let _surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 10, 10); + let _cr = new Cairo.Context(_surface); + _surface.finish(); + _cr.stroke(); + }).toThrow(); + expect(() => { + let _surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 10, 10); + _surface.finish(); + _surface.flush(); + }).not.toThrow(); + }); }); describe('GI test suite', function () { diff --git a/modules/cairo-surface.cpp b/modules/cairo-surface.cpp index 87718643..f8f8c1ce 100644 --- a/modules/cairo-surface.cpp +++ b/modules/cairo-surface.cpp @@ -64,6 +64,54 @@ writeToPNG_func(JSContext *context, } GJS_JSAPI_RETURN_CONVENTION +bool flush_func(JSContext* cx, + unsigned argc, + JS::Value* vp) { + GJS_GET_THIS(cx, argc, vp, argv, obj); + + if (argc > 1) { + gjs_throw(cx, "Surface.flush() takes no arguments"); + return false; + } + + cairo_surface_t* surface = CairoSurface::for_js(cx, obj); + if (!surface) + return false; + + cairo_surface_flush(surface); + + if (!gjs_cairo_check_status(cx, cairo_surface_status(surface), "surface")) + return false; + + argv.rval().setUndefined(); + return true; +} + +GJS_JSAPI_RETURN_CONVENTION +bool finish_func(JSContext* cx, + unsigned argc, + JS::Value* vp) { + GJS_GET_THIS(cx, argc, vp, argv, obj); + + if (argc > 1) { + gjs_throw(cx, "Surface.finish() takes no arguments"); + return false; + } + + cairo_surface_t* surface = CairoSurface::for_js(cx, obj); + if (!surface) + return false; + + cairo_surface_finish(surface); + + if (!gjs_cairo_check_status(cx, cairo_surface_status(surface), "surface")) + return false; + + argv.rval().setUndefined(); + return true; +} + +GJS_JSAPI_RETURN_CONVENTION bool CairoSurface::getType_func(JSContext* context, unsigned argc, JS::Value* vp) { GJS_GET_THIS(context, argc, vp, rec, obj); @@ -186,7 +234,8 @@ static bool getDeviceScale_func(JSContext* cx, unsigned argc, JS::Value* vp) { } const JSFunctionSpec CairoSurface::proto_funcs[] = { - // flush + JS_FN("flush", flush_func, 0, 0), + JS_FN("finish", finish_func, 0, 0), // getContent // getFontOptions JS_FN("getType", getType_func, 0, 0), |