Branch data Line data Source code
1 : : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 : : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
3 : : // SPDX-FileCopyrightText: 2010 litl, LLC.
4 : :
5 : : #include <config.h>
6 : :
7 : : #include <cairo-features.h> // for CAIRO_HAS_PDF_SURFACE, CAIRO_HAS_PS_SURFA...
8 : : #include <cairo.h>
9 : :
10 : : #ifdef CAIRO_HAS_XLIB_SURFACE
11 : : # include <cairo-xlib.h>
12 : : # undef None
13 : : // X11 defines a global None macro. Rude! This conflicts with None used as an
14 : : // enum member in SpiderMonkey headers, e.g. JS::ExceptionStatus::None.
15 : : #endif
16 : :
17 : : #include <js/RootingAPI.h>
18 : : #include <js/TypeDecls.h>
19 : : #include <jsapi.h> // for JS_NewPlainObject
20 : :
21 : : #include "gjs/jsapi-util.h"
22 : : #include "modules/cairo-private.h"
23 : :
24 : : #ifdef CAIRO_HAS_XLIB_SURFACE
25 : : class XLibConstructor {
26 : : public:
27 : 125 : XLibConstructor() {
28 : 125 : XInitThreads();
29 : 125 : }
30 : : };
31 : :
32 : : static XLibConstructor constructor;
33 : : #endif
34 : :
35 : : bool
36 : 201 : gjs_cairo_check_status(JSContext *context,
37 : : cairo_status_t status,
38 : : const char *name)
39 : : {
40 [ + + ]: 201 : if (status != CAIRO_STATUS_SUCCESS) {
41 : 1 : gjs_throw(context, "cairo error on %s: \"%s\" (%d)",
42 : : name,
43 : : cairo_status_to_string(status),
44 : : status);
45 : 1 : return false;
46 : : }
47 : :
48 : 200 : return true;
49 : : }
50 : :
51 : : bool
52 : 2 : gjs_js_define_cairo_stuff(JSContext *context,
53 : : JS::MutableHandleObject module)
54 : : {
55 : 2 : module.set(JS_NewPlainObject(context));
56 : :
57 [ - + ]: 2 : if (!CairoRegion::create_prototype(context, module))
58 : 0 : return false;
59 : 2 : gjs_cairo_region_init();
60 : :
61 [ - + ]: 2 : if (!CairoContext::create_prototype(context, module))
62 : 0 : return false;
63 : 2 : gjs_cairo_context_init();
64 : :
65 [ - + ]: 2 : if (!CairoSurface::create_prototype(context, module))
66 : 0 : return false;
67 : 2 : gjs_cairo_surface_init();
68 : :
69 [ + - ]: 4 : return CairoImageSurface::create_prototype(context, module) &&
70 [ + - ]: 4 : CairoPath::create_prototype(context, module) &&
71 : : #if CAIRO_HAS_PS_SURFACE
72 [ + - ]: 4 : CairoPSSurface::create_prototype(context, module) &&
73 : : #endif
74 : : #if CAIRO_HAS_PDF_SURFACE
75 [ + - ]: 4 : CairoPDFSurface::create_prototype(context, module) &&
76 : : #endif
77 : : #if CAIRO_HAS_SVG_SURFACE
78 [ + - ]: 4 : CairoSVGSurface::create_prototype(context, module) &&
79 : : #endif
80 [ + - ]: 4 : CairoPattern::create_prototype(context, module) &&
81 [ + - ]: 4 : CairoGradient::create_prototype(context, module) &&
82 [ + - ]: 4 : CairoLinearGradient::create_prototype(context, module) &&
83 [ + - ]: 4 : CairoRadialGradient::create_prototype(context, module) &&
84 [ + - + - ]: 6 : CairoSurfacePattern::create_prototype(context, module) &&
85 : 4 : CairoSolidPattern::create_prototype(context, module);
86 : : }
|