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 : : // SPDX-FileCopyrightText: 2020 Philip Chimento <philip.chimento@gmail.com>
5 : :
6 : : #pragma once
7 : :
8 : : #include <config.h>
9 : :
10 : : #include <cairo-features.h> // for CAIRO_HAS_PDF_SURFACE, CAIRO_HAS_PS_SURFACE
11 : : #include <cairo-gobject.h>
12 : : #include <cairo.h>
13 : : #include <glib-object.h>
14 : :
15 : : #include <js/Class.h>
16 : : #include <js/TypeDecls.h>
17 : : #include <jspubtd.h> // for JSProtoKey
18 : :
19 : : #include "gi/cwrapper.h"
20 : : #include "gjs/global.h"
21 : : #include "gjs/macros.h"
22 : : #include "util/log.h"
23 : :
24 : : struct JSFunctionSpec;
25 : : struct JSPropertySpec;
26 : : namespace JS {
27 : : class CallArgs;
28 : : }
29 : :
30 : : GJS_JSAPI_RETURN_CONVENTION
31 : : bool gjs_cairo_check_status(JSContext*, cairo_status_t, const char* name);
32 : :
33 : : class CairoRegion : public CWrapper<CairoRegion, cairo_region_t> {
34 : : friend CWrapperPointerOps<CairoRegion, cairo_region_t>;
35 : : friend CWrapper<CairoRegion, cairo_region_t>;
36 : :
37 : : CairoRegion() = delete;
38 : : CairoRegion(CairoRegion&) = delete;
39 : : CairoRegion(CairoRegion&&) = delete;
40 : :
41 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
42 : : GjsGlobalSlot::PROTOTYPE_cairo_region;
43 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
44 : : static constexpr unsigned constructor_nargs = 0;
45 : :
46 : 2 : static GType gtype() { return CAIRO_GOBJECT_TYPE_REGION; }
47 : :
48 : 0 : static cairo_region_t* copy_ptr(cairo_region_t* region) {
49 : 0 : return cairo_region_reference(region);
50 : : }
51 : :
52 : : GJS_JSAPI_RETURN_CONVENTION
53 : : static cairo_region_t* constructor_impl(JSContext*, const JS::CallArgs&);
54 : :
55 : : static void finalize_impl(JS::GCContext*, cairo_region_t*);
56 : :
57 : : static const JSFunctionSpec proto_funcs[];
58 : : static const JSPropertySpec proto_props[];
59 : : static constexpr js::ClassSpec class_spec = {
60 : : nullptr, // createConstructor
61 : : nullptr, // createPrototype
62 : : nullptr, // constructorFunctions
63 : : nullptr, // constructorProperties
64 : : CairoRegion::proto_funcs,
65 : : CairoRegion::proto_props,
66 : : CairoRegion::define_gtype_prop,
67 : : };
68 : : static constexpr JSClass klass = {
69 : : "Region", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
70 : : &CairoRegion::class_ops, &CairoRegion::class_spec};
71 : : };
72 : :
73 : : void gjs_cairo_region_init();
74 : :
75 : : class CairoContext : public CWrapper<CairoContext, cairo_t> {
76 : : friend CWrapperPointerOps<CairoContext, cairo_t>;
77 : : friend CWrapper<CairoContext, cairo_t>;
78 : :
79 : : CairoContext() = delete;
80 : : CairoContext(CairoContext&) = delete;
81 : : CairoContext(CairoContext&&) = delete;
82 : :
83 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
84 : : GjsGlobalSlot::PROTOTYPE_cairo_context;
85 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
86 : : static constexpr unsigned constructor_nargs = 1;
87 : :
88 : 2 : static GType gtype() { return CAIRO_GOBJECT_TYPE_CONTEXT; }
89 : :
90 : 4 : static cairo_t* copy_ptr(cairo_t* cr) { return cairo_reference(cr); }
91 : :
92 : : GJS_JSAPI_RETURN_CONVENTION
93 : : static cairo_t* constructor_impl(JSContext*, const JS::CallArgs&);
94 : :
95 : : static void finalize_impl(JS::GCContext*, cairo_t*);
96 : :
97 : : static const JSFunctionSpec proto_funcs[];
98 : : static const JSPropertySpec proto_props[];
99 : : static constexpr js::ClassSpec class_spec = {
100 : : nullptr, // createConstructor
101 : : nullptr, // createPrototype
102 : : nullptr, // constructorFunctions
103 : : nullptr, // constructorProperties
104 : : CairoContext::proto_funcs,
105 : : CairoContext::proto_props,
106 : : CairoContext::define_gtype_prop,
107 : : };
108 : : static constexpr JSClass klass = {
109 : : "Context", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
110 : : &CairoContext::class_ops, &CairoContext::class_spec};
111 : :
112 : : GJS_JSAPI_RETURN_CONVENTION
113 : : static bool dispose(JSContext*, unsigned, JS::Value*);
114 : : };
115 : :
116 : : void gjs_cairo_context_init();
117 : : void gjs_cairo_surface_init();
118 : :
119 : : // path
120 : : void gjs_cairo_path_init();
121 : : class CairoPath : public CWrapper<CairoPath, cairo_path_t> {
122 : : friend CWrapperPointerOps<CairoPath, cairo_path_t>;
123 : : friend CWrapper<CairoPath, cairo_path_t>;
124 : :
125 : : CairoPath() = delete;
126 : : CairoPath(CairoPath&) = delete;
127 : : CairoPath(CairoPath&&) = delete;
128 : :
129 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
130 : : GjsGlobalSlot::PROTOTYPE_cairo_path;
131 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
132 : :
133 : : static void finalize_impl(JS::GCContext*, cairo_path_t*);
134 : :
135 : : static const JSPropertySpec proto_props[];
136 : : static constexpr js::ClassSpec class_spec = {
137 : : CairoPath::create_abstract_constructor,
138 : : nullptr, // createPrototype
139 : : nullptr, // constructorFunctions
140 : : nullptr, // constructorProperties
141 : : nullptr, // prototypeFunctions
142 : : CairoPath::proto_props,
143 : : nullptr, // finishInit
144 : : };
145 : : static constexpr JSClass klass = {
146 : : "Path", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
147 : : &CairoPath::class_ops, &CairoPath::class_spec};
148 : :
149 : : public:
150 : : static cairo_path_t* copy_ptr(cairo_path_t*);
151 : : GJS_JSAPI_RETURN_CONVENTION
152 : : static JSObject* take_c_ptr(JSContext*, cairo_path_t*);
153 : : };
154 : :
155 : : // surface
156 : :
157 : : class CairoSurface : public CWrapper<CairoSurface, cairo_surface_t> {
158 : : friend CWrapperPointerOps<CairoSurface, cairo_surface_t>;
159 : : friend CWrapper<CairoSurface, cairo_surface_t>;
160 : : friend class CairoImageSurface; // "inherits" from CairoSurface
161 : : friend class CairoPSSurface;
162 : : friend class CairoPDFSurface;
163 : : friend class CairoSVGSurface;
164 : :
165 : : CairoSurface() = delete;
166 : : CairoSurface(CairoSurface&) = delete;
167 : : CairoSurface(CairoSurface&&) = delete;
168 : :
169 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
170 : : GjsGlobalSlot::PROTOTYPE_cairo_surface;
171 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
172 : :
173 : 10 : static GType gtype() { return CAIRO_GOBJECT_TYPE_SURFACE; }
174 : :
175 : : static void finalize_impl(JS::GCContext*, cairo_surface_t*);
176 : :
177 : : static const JSFunctionSpec proto_funcs[];
178 : : static const JSPropertySpec proto_props[];
179 : : static constexpr js::ClassSpec class_spec = {
180 : : &CairoSurface::create_abstract_constructor,
181 : : nullptr, // createPrototype
182 : : nullptr, // constructorFunctions
183 : : nullptr, // constructorProperties
184 : : CairoSurface::proto_funcs,
185 : : CairoSurface::proto_props,
186 : : &CairoSurface::define_gtype_prop,
187 : : };
188 : : static constexpr JSClass klass = {
189 : : "Surface", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
190 : : &CairoSurface::class_ops, &CairoSurface::class_spec};
191 : :
192 : 1 : static cairo_surface_t* copy_ptr(cairo_surface_t* surface) {
193 : 1 : return cairo_surface_reference(surface);
194 : : }
195 : :
196 : : GJS_JSAPI_RETURN_CONVENTION
197 : : static bool getType_func(JSContext*, unsigned, JS::Value*);
198 : :
199 : : public:
200 : : GJS_JSAPI_RETURN_CONVENTION
201 : : static JSObject* from_c_ptr(JSContext*, cairo_surface_t*);
202 : :
203 : : GJS_JSAPI_RETURN_CONVENTION
204 : : static cairo_surface_t* for_js(JSContext*,
205 : : JS::HandleObject surface_wrapper);
206 : : };
207 : :
208 : : class CairoImageSurface : public CWrapper<CairoImageSurface, cairo_surface_t> {
209 : : friend CWrapperPointerOps<CairoImageSurface, cairo_surface_t>;
210 : : friend CWrapper<CairoImageSurface, cairo_surface_t>;
211 : :
212 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
213 : : GjsGlobalSlot::PROTOTYPE_cairo_image_surface;
214 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
215 : : static constexpr unsigned constructor_nargs = 3;
216 : :
217 : : GJS_JSAPI_RETURN_CONVENTION
218 : : static JSObject* new_proto(JSContext*, JSProtoKey);
219 : :
220 : : static const JSFunctionSpec static_funcs[];
221 : : static const JSFunctionSpec proto_funcs[];
222 : : static const JSPropertySpec proto_props[];
223 : : static constexpr js::ClassSpec class_spec = {
224 : : nullptr, // createConstructor,
225 : : &CairoImageSurface::new_proto,
226 : : CairoImageSurface::static_funcs,
227 : : nullptr, // constructorProperties
228 : : CairoImageSurface::proto_funcs,
229 : : CairoImageSurface::proto_props,
230 : : &CairoSurface::define_gtype_prop,
231 : : };
232 : : static constexpr JSClass klass = {
233 : : "ImageSurface",
234 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
235 : : &CairoSurface::class_ops, &CairoImageSurface::class_spec};
236 : :
237 : 6 : static cairo_surface_t* copy_ptr(cairo_surface_t* surface) {
238 : 6 : return cairo_surface_reference(surface);
239 : : }
240 : :
241 : : static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
242 : :
243 : : GJS_JSAPI_RETURN_CONVENTION
244 : : static cairo_surface_t* constructor_impl(JSContext*, const JS::CallArgs&);
245 : : };
246 : :
247 : : #ifdef CAIRO_HAS_PS_SURFACE
248 : : class CairoPSSurface : public CWrapper<CairoPSSurface, cairo_surface_t> {
249 : : friend CWrapperPointerOps<CairoPSSurface, cairo_surface_t>;
250 : : friend CWrapper<CairoPSSurface, cairo_surface_t>;
251 : :
252 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
253 : : GjsGlobalSlot::PROTOTYPE_cairo_ps_surface;
254 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
255 : : static constexpr unsigned constructor_nargs = 3;
256 : :
257 : : GJS_JSAPI_RETURN_CONVENTION
258 : : static JSObject* new_proto(JSContext*, JSProtoKey);
259 : :
260 : : static const JSFunctionSpec proto_funcs[];
261 : : static const JSPropertySpec proto_props[];
262 : : static constexpr js::ClassSpec class_spec = {
263 : : nullptr, // createConstructor,
264 : : &CairoPSSurface::new_proto,
265 : : nullptr, // constructorFunctions
266 : : nullptr, // constructorProperties
267 : : CairoPSSurface::proto_funcs,
268 : : CairoPSSurface::proto_props,
269 : : &CairoSurface::define_gtype_prop,
270 : : };
271 : : static constexpr JSClass klass = {
272 : : "PSSurface",
273 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
274 : : &CairoSurface::class_ops, &CairoPSSurface::class_spec};
275 : :
276 : 0 : static cairo_surface_t* copy_ptr(cairo_surface_t* surface) {
277 : 0 : return cairo_surface_reference(surface);
278 : : }
279 : :
280 : : static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
281 : :
282 : : GJS_JSAPI_RETURN_CONVENTION
283 : : static cairo_surface_t* constructor_impl(JSContext*, const JS::CallArgs&);
284 : : };
285 : : #else
286 : : class CairoPSSurface {
287 : : GJS_JSAPI_RETURN_CONVENTION
288 : : static JSObject* from_c_ptr(JSContext*, cairo_surface_t*);
289 : : };
290 : : #endif // CAIRO_HAS_PS_SURFACE
291 : :
292 : : #ifdef CAIRO_HAS_PDF_SURFACE
293 : : class CairoPDFSurface : public CWrapper<CairoPDFSurface, cairo_surface_t> {
294 : : friend CWrapperPointerOps<CairoPDFSurface, cairo_surface_t>;
295 : : friend CWrapper<CairoPDFSurface, cairo_surface_t>;
296 : :
297 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
298 : : GjsGlobalSlot::PROTOTYPE_cairo_pdf_surface;
299 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
300 : : static constexpr unsigned constructor_nargs = 3;
301 : :
302 : : GJS_JSAPI_RETURN_CONVENTION
303 : : static JSObject* new_proto(JSContext*, JSProtoKey);
304 : :
305 : : static const JSFunctionSpec proto_funcs[];
306 : : static const JSPropertySpec proto_props[];
307 : : static constexpr js::ClassSpec class_spec = {
308 : : nullptr, // createConstructor,
309 : : &CairoPDFSurface::new_proto,
310 : : nullptr, // constructorFunctions
311 : : nullptr, // constructorProperties
312 : : CairoSurface::proto_funcs,
313 : : CairoSurface::proto_props,
314 : : &CairoSurface::define_gtype_prop,
315 : : };
316 : : static constexpr JSClass klass = {
317 : : "PDFSurface",
318 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
319 : : &CairoSurface::class_ops, &CairoPDFSurface::class_spec};
320 : :
321 : 0 : static cairo_surface_t* copy_ptr(cairo_surface_t* surface) {
322 : 0 : return cairo_surface_reference(surface);
323 : : }
324 : :
325 : : static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
326 : :
327 : : GJS_JSAPI_RETURN_CONVENTION
328 : : static cairo_surface_t* constructor_impl(JSContext*, const JS::CallArgs&);
329 : : };
330 : : #else
331 : : class CairoPDFSurface {
332 : : public:
333 : : GJS_JSAPI_RETURN_CONVENTION
334 : : static JSObject* from_c_ptr(JSContext*, cairo_surface_t*);
335 : : };
336 : : #endif // CAIRO_HAS_PDF_SURFACE
337 : :
338 : : #ifdef CAIRO_HAS_SVG_SURFACE
339 : : class CairoSVGSurface : public CWrapper<CairoSVGSurface, cairo_surface_t> {
340 : : friend CWrapperPointerOps<CairoSVGSurface, cairo_surface_t>;
341 : : friend CWrapper<CairoSVGSurface, cairo_surface_t>;
342 : :
343 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
344 : : GjsGlobalSlot::PROTOTYPE_cairo_svg_surface;
345 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
346 : : static constexpr unsigned constructor_nargs = 3;
347 : :
348 : : GJS_JSAPI_RETURN_CONVENTION
349 : : static JSObject* new_proto(JSContext*, JSProtoKey);
350 : :
351 : : static const JSPropertySpec proto_props[];
352 : : static constexpr js::ClassSpec class_spec = {
353 : : nullptr, // createConstructor,
354 : : &CairoSVGSurface::new_proto,
355 : : nullptr, // constructorFunctions
356 : : nullptr, // constructorProperties
357 : : nullptr, // prototypeFunctions
358 : : CairoSVGSurface::proto_props,
359 : : &CairoSurface::define_gtype_prop,
360 : : };
361 : : static constexpr JSClass klass = {
362 : : "SVGSurface",
363 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
364 : : &CairoSurface::class_ops, &CairoSVGSurface::class_spec};
365 : :
366 : 0 : static cairo_surface_t* copy_ptr(cairo_surface_t* surface) {
367 : 0 : return cairo_surface_reference(surface);
368 : : }
369 : :
370 : : static void finalize_impl(JS::GCContext*, cairo_surface_t*) {}
371 : :
372 : : GJS_JSAPI_RETURN_CONVENTION
373 : : static cairo_surface_t* constructor_impl(JSContext*, const JS::CallArgs&);
374 : : };
375 : : #else
376 : : class CairoSVGSurface {
377 : : public:
378 : : GJS_JSAPI_RETURN_CONVENTION
379 : : static JSObject* from_c_ptr(JSContext*, cairo_surface_t*);
380 : : };
381 : : #endif // CAIRO_HAS_SVG_SURFACE
382 : :
383 : : // pattern
384 : : void gjs_cairo_pattern_init();
385 : :
386 : : class CairoPattern : public CWrapper<CairoPattern, cairo_pattern_t> {
387 : : friend CWrapperPointerOps<CairoPattern, cairo_pattern_t>;
388 : : friend CWrapper<CairoPattern, cairo_pattern_t>;
389 : : friend class CairoGradient; // "inherits" from CairoPattern
390 : : friend class CairoLinearGradient;
391 : : friend class CairoRadialGradient;
392 : : friend class CairoSurfacePattern;
393 : : friend class CairoSolidPattern;
394 : :
395 : : CairoPattern() = delete;
396 : : CairoPattern(CairoPattern&) = delete;
397 : : CairoPattern(CairoPattern&&) = delete;
398 : :
399 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
400 : : GjsGlobalSlot::PROTOTYPE_cairo_pattern;
401 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
402 : :
403 : : static const JSFunctionSpec proto_funcs[];
404 : : static const JSPropertySpec proto_props[];
405 : : static constexpr js::ClassSpec class_spec = {
406 : : &CairoPattern::create_abstract_constructor,
407 : : nullptr, // createPrototype
408 : : nullptr, // constructorFunctions
409 : : nullptr, // constructorProperties
410 : : CairoPattern::proto_funcs,
411 : : CairoPattern::proto_props,
412 : : &CairoPattern::define_gtype_prop,
413 : : };
414 : : static constexpr JSClass klass = {
415 : : "Pattern", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
416 : : &CairoPattern::class_ops, &CairoPattern::class_spec};
417 : :
418 : 12 : static GType gtype() { return CAIRO_GOBJECT_TYPE_PATTERN; }
419 : :
420 : 2 : static cairo_pattern_t* copy_ptr(cairo_pattern_t* pattern) {
421 : 2 : return cairo_pattern_reference(pattern);
422 : : }
423 : :
424 : : GJS_JSAPI_RETURN_CONVENTION
425 : : static bool getType_func(JSContext*, unsigned, JS::Value*);
426 : :
427 : : protected:
428 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*);
429 : :
430 : : public:
431 : : static cairo_pattern_t* for_js(JSContext*,
432 : : JS::HandleObject pattern_wrapper);
433 : : };
434 : :
435 : : GJS_JSAPI_RETURN_CONVENTION
436 : : JSObject* gjs_cairo_pattern_from_pattern(JSContext*, cairo_pattern_t*);
437 : :
438 : : class CairoGradient : public CWrapper<CairoGradient, cairo_pattern_t> {
439 : : friend CWrapperPointerOps<CairoGradient, cairo_pattern_t>;
440 : : friend CWrapper<CairoGradient, cairo_pattern_t>;
441 : : friend class CairoLinearGradient; // "inherits" from CairoGradient
442 : : friend class CairoRadialGradient;
443 : :
444 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
445 : : GjsGlobalSlot::PROTOTYPE_cairo_gradient;
446 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
447 : :
448 : : GJS_JSAPI_RETURN_CONVENTION
449 : : static JSObject* new_proto(JSContext*, JSProtoKey);
450 : :
451 : : static const JSFunctionSpec proto_funcs[];
452 : : static const JSPropertySpec proto_props[];
453 : : static constexpr js::ClassSpec class_spec = {
454 : : &CairoGradient::create_abstract_constructor,
455 : : &CairoGradient::new_proto,
456 : : nullptr, // constructorFunctions
457 : : nullptr, // constructorProperties
458 : : CairoGradient::proto_funcs,
459 : : CairoGradient::proto_props,
460 : : &CairoPattern::define_gtype_prop,
461 : : };
462 : : static constexpr JSClass klass = {
463 : : "Gradient", JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
464 : : &CairoPattern::class_ops, &CairoGradient::class_spec};
465 : :
466 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
467 : : };
468 : :
469 : : class CairoLinearGradient
470 : : : public CWrapper<CairoLinearGradient, cairo_pattern_t> {
471 : : friend CWrapperPointerOps<CairoLinearGradient, cairo_pattern_t>;
472 : : friend CWrapper<CairoLinearGradient, cairo_pattern_t>;
473 : :
474 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
475 : : GjsGlobalSlot::PROTOTYPE_cairo_linear_gradient;
476 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
477 : : static constexpr unsigned constructor_nargs = 4;
478 : :
479 : : GJS_JSAPI_RETURN_CONVENTION
480 : : static JSObject* new_proto(JSContext*, JSProtoKey);
481 : :
482 : : static const JSFunctionSpec proto_funcs[];
483 : : static const JSPropertySpec proto_props[];
484 : : static constexpr js::ClassSpec class_spec = {
485 : : nullptr, // createConstructor
486 : : &CairoLinearGradient::new_proto,
487 : : nullptr, // constructorFunctions
488 : : nullptr, // constructorProperties
489 : : CairoLinearGradient::proto_funcs,
490 : : CairoLinearGradient::proto_props,
491 : : &CairoPattern::define_gtype_prop,
492 : : };
493 : : static constexpr JSClass klass = {
494 : : "LinearGradient",
495 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
496 : : &CairoPattern::class_ops, &CairoLinearGradient::class_spec};
497 : :
498 : 1 : static cairo_pattern_t* copy_ptr(cairo_pattern_t* pattern) {
499 : 1 : return cairo_pattern_reference(pattern);
500 : : }
501 : :
502 : : GJS_JSAPI_RETURN_CONVENTION
503 : : static cairo_pattern_t* constructor_impl(JSContext*, const JS::CallArgs&);
504 : :
505 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
506 : : };
507 : :
508 : : class CairoRadialGradient
509 : : : public CWrapper<CairoRadialGradient, cairo_pattern_t> {
510 : : friend CWrapperPointerOps<CairoRadialGradient, cairo_pattern_t>;
511 : : friend CWrapper<CairoRadialGradient, cairo_pattern_t>;
512 : :
513 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
514 : : GjsGlobalSlot::PROTOTYPE_cairo_radial_gradient;
515 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
516 : : static constexpr unsigned constructor_nargs = 6;
517 : :
518 : : GJS_JSAPI_RETURN_CONVENTION
519 : : static JSObject* new_proto(JSContext*, JSProtoKey);
520 : :
521 : : static const JSFunctionSpec proto_funcs[];
522 : : static const JSPropertySpec proto_props[];
523 : : static constexpr js::ClassSpec class_spec = {
524 : : nullptr, // createConstructor
525 : : &CairoRadialGradient::new_proto,
526 : : nullptr, // constructorFunctions
527 : : nullptr, // constructorProperties
528 : : CairoRadialGradient::proto_funcs,
529 : : CairoRadialGradient::proto_props,
530 : : &CairoPattern::define_gtype_prop,
531 : : };
532 : : static constexpr JSClass klass = {
533 : : "RadialGradient",
534 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
535 : : &CairoPattern::class_ops, &CairoRadialGradient::class_spec};
536 : :
537 : 1 : static cairo_pattern_t* copy_ptr(cairo_pattern_t* pattern) {
538 : 1 : return cairo_pattern_reference(pattern);
539 : : }
540 : :
541 : : GJS_JSAPI_RETURN_CONVENTION
542 : : static cairo_pattern_t* constructor_impl(JSContext*, const JS::CallArgs&);
543 : :
544 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
545 : : };
546 : :
547 : : class CairoSurfacePattern
548 : : : public CWrapper<CairoSurfacePattern, cairo_pattern_t> {
549 : : friend CWrapperPointerOps<CairoSurfacePattern, cairo_pattern_t>;
550 : : friend CWrapper<CairoSurfacePattern, cairo_pattern_t>;
551 : :
552 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
553 : : GjsGlobalSlot::PROTOTYPE_cairo_surface_pattern;
554 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
555 : : static constexpr unsigned constructor_nargs = 1;
556 : :
557 : : GJS_JSAPI_RETURN_CONVENTION
558 : : static JSObject* new_proto(JSContext*, JSProtoKey);
559 : :
560 : : static const JSFunctionSpec proto_funcs[];
561 : : static const JSPropertySpec proto_props[];
562 : : static constexpr js::ClassSpec class_spec = {
563 : : nullptr, // createConstructor
564 : : &CairoSurfacePattern::new_proto,
565 : : nullptr, // constructorFunctions
566 : : nullptr, // constructorProperties
567 : : CairoSurfacePattern::proto_funcs,
568 : : CairoSurfacePattern::proto_props,
569 : : &CairoPattern::define_gtype_prop,
570 : : };
571 : : static constexpr JSClass klass = {
572 : : "SurfacePattern",
573 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
574 : : &CairoPattern::class_ops, &CairoSurfacePattern::class_spec};
575 : :
576 : 2 : static cairo_pattern_t* copy_ptr(cairo_pattern_t* pattern) {
577 : 2 : return cairo_pattern_reference(pattern);
578 : : }
579 : :
580 : : GJS_JSAPI_RETURN_CONVENTION
581 : : static cairo_pattern_t* constructor_impl(JSContext*, const JS::CallArgs&);
582 : :
583 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
584 : : };
585 : :
586 : : class CairoSolidPattern : public CWrapper<CairoSolidPattern, cairo_pattern_t> {
587 : : friend CWrapperPointerOps<CairoSolidPattern, cairo_pattern_t>;
588 : : friend CWrapper<CairoSolidPattern, cairo_pattern_t>;
589 : :
590 : : static constexpr GjsGlobalSlot PROTOTYPE_SLOT =
591 : : GjsGlobalSlot::PROTOTYPE_cairo_solid_pattern;
592 : : static constexpr GjsDebugTopic DEBUG_TOPIC = GJS_DEBUG_CAIRO;
593 : :
594 : : GJS_JSAPI_RETURN_CONVENTION
595 : : static JSObject* new_proto(JSContext*, JSProtoKey);
596 : :
597 : : static const JSFunctionSpec static_funcs[];
598 : : static const JSPropertySpec proto_props[];
599 : : static constexpr js::ClassSpec class_spec = {
600 : : &CairoSolidPattern::create_abstract_constructor,
601 : : &CairoSolidPattern::new_proto,
602 : : CairoSolidPattern::static_funcs,
603 : : nullptr, // constructorProperties
604 : : nullptr, // prototypeFunctions
605 : : CairoSolidPattern::proto_props,
606 : : &CairoPattern::define_gtype_prop,
607 : : };
608 : : static constexpr JSClass klass = {
609 : : "SolidPattern",
610 : : JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_BACKGROUND_FINALIZE,
611 : : &CairoPattern::class_ops, &CairoSolidPattern::class_spec};
612 : :
613 : 9 : static cairo_pattern_t* copy_ptr(cairo_pattern_t* pattern) {
614 : 9 : return cairo_pattern_reference(pattern);
615 : : }
616 : :
617 : : static void finalize_impl(JS::GCContext*, cairo_pattern_t*) {}
618 : : };
|