1 /*
2  * Copyright (c) 2016 Hanspeter Portner (dev@open-music-kontrollers.ch)
3  *
4  * This is free software: you can redistribute it and/or modify
5  * it under the terms of the Artistic License 2.0 as published by
6  * The Perl Foundation.
7  *
8  * This source is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * Artistic License 2.0 for more details.
12  *
13  * You should have received a copy of the Artistic License 2.0
14  * along the source as a COPYING file. If not, obtain it from
15  * http://www.perlfoundation.org/artistic_license_2_0.
16  */
17 
18 #ifndef _LV2_CANVAS_RENDER_H
19 #define _LV2_CANVAS_RENDER_H
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include <canvas.lv2/canvas.h>
26 
27 #define LV2_CANVAS_NUM_METHODS 26
28 
29 typedef struct _LV2_Canvas_Meth LV2_Canvas_Meth;
30 typedef struct _LV2_Canvas LV2_Canvas;
31 typedef void (*LV2_Canvas_Func)(void *data,
32 	LV2_Canvas_URID *urid, const LV2_Atom *body);
33 
34 struct _LV2_Canvas_Meth {
35 	LV2_URID command;
36 	LV2_Canvas_Func func;
37 };
38 
39 struct _LV2_Canvas {
40 	LV2_Canvas_URID urid;
41 	LV2_Canvas_Meth methods [LV2_CANVAS_NUM_METHODS];
42 };
43 
44 static inline const float *
_lv2_canvas_render_get_float_vecs(LV2_Canvas_URID * urid,const LV2_Atom * body,uint32_t * n)45 _lv2_canvas_render_get_float_vecs(LV2_Canvas_URID *urid, const LV2_Atom *body,
46 	uint32_t *n)
47 {
48 	const LV2_Atom_Vector *vec = (const LV2_Atom_Vector *)body;
49 	const float *flt = LV2_ATOM_CONTENTS_CONST(LV2_Atom_Vector, vec);
50 	*n = (vec->atom.type == urid->forge.Vector)
51 		&& (vec->body.child_type == urid->forge.Float)
52 		&& (vec->body.child_size == sizeof(float))
53 		? (vec->atom.size - sizeof(LV2_Atom_Vector_Body)) / vec->body.child_size
54 		: 0;
55 
56 	return flt;
57 }
58 
59 static inline const float *
_lv2_canvas_render_get_float_vec(LV2_Canvas_URID * urid,const LV2_Atom * body,uint32_t n)60 _lv2_canvas_render_get_float_vec(LV2_Canvas_URID *urid, const LV2_Atom *body,
61 	uint32_t n)
62 {
63 	uint32_t N;
64 	const float *flt = _lv2_canvas_render_get_float_vecs(urid, body, &N);
65 
66 	return n == N ? flt : NULL;
67 }
68 
69 static inline const void *
_lv2_canvas_render_get_type(const LV2_Atom * body,LV2_URID type)70 _lv2_canvas_render_get_type(const LV2_Atom *body, LV2_URID type)
71 {
72 	return body->type == type
73 		? LV2_ATOM_BODY_CONST(body)
74 		: NULL;
75 }
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #if defined(LV2_CANVAS_RENDER_NANOVG)
82 #	include <canvas.lv2/render_nanovg.h>
83 #else
84 #	include <canvas.lv2/render_cairo.h>
85 #endif
86 
87 #endif // _LV2_CANVAS_RENDER_H
88