1 /**
2 * MIT License
3 *
4 * -----------------------------------------------------------------------------
5 * Copyright (c) 2008-24 Think Silicon Single Member PC
6 * -----------------------------------------------------------------------------
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights to
11 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12 * the Software, and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next paragraph)
16 * shall be included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
19 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
23 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 /**
28 * @file lv_nema_gfx_path.c
29 *
30 */
31
32 /*********************
33 * INCLUDES
34 *********************/
35 #include "../../core/lv_refr.h"
36
37 #if LV_USE_NEMA_GFX
38 #if LV_USE_NEMA_VG
39
40 #include "lv_nema_gfx_path.h"
41
42 /**********************
43 * GLOBAL FUNCTIONS
44 **********************/
45
46 static int data_point = 0;
47 static int seg_point = 0;
48
lv_nema_gfx_path_create(void)49 lv_nema_gfx_path_t * lv_nema_gfx_path_create(void)
50 {
51 LV_PROFILER_DRAW_BEGIN;
52 lv_nema_gfx_path_t * nema_gfx_path = lv_malloc_zeroed(sizeof(lv_nema_gfx_path_t));
53 LV_ASSERT_MALLOC(nema_gfx_path);
54 nema_gfx_path->seg = NULL;
55 nema_gfx_path->data = NULL;
56 nema_gfx_path->seg_size = 0;
57 nema_gfx_path->data_size = 0;
58 data_point = 0;
59 seg_point = 0;
60 LV_PROFILER_DRAW_END;
61 return nema_gfx_path;
62 }
63
lv_nema_gfx_path_alloc(lv_nema_gfx_path_t * nema_gfx_path)64 void lv_nema_gfx_path_alloc(lv_nema_gfx_path_t * nema_gfx_path)
65 {
66 LV_PROFILER_DRAW_BEGIN;
67 nema_gfx_path->path = nema_vg_path_create();
68 nema_gfx_path->paint = nema_vg_paint_create();
69 nema_gfx_path->data = (float *) lv_malloc(nema_gfx_path->data_size * sizeof(float));
70 LV_ASSERT_MALLOC(nema_gfx_path->data);
71 nema_gfx_path->seg = (uint8_t *) lv_malloc(nema_gfx_path->seg_size * sizeof(uint8_t));
72 LV_ASSERT_MALLOC(nema_gfx_path->seg);
73 LV_PROFILER_DRAW_END;
74 }
75
lv_nema_gfx_path_destroy(lv_nema_gfx_path_t * nema_gfx_path)76 void lv_nema_gfx_path_destroy(lv_nema_gfx_path_t * nema_gfx_path)
77 {
78 LV_PROFILER_DRAW_BEGIN;
79 LV_ASSERT_NULL(nema_gfx_path);
80
81 if(nema_gfx_path->path != NULL) {
82 nema_vg_path_destroy(nema_gfx_path->path);
83 nema_gfx_path->path = NULL;
84 }
85
86 if(nema_gfx_path->paint != NULL) {
87 nema_vg_paint_destroy(nema_gfx_path->paint);
88 nema_gfx_path->paint = NULL;
89 }
90
91 if(nema_gfx_path->data != NULL) {
92 lv_free(nema_gfx_path->data);
93 nema_gfx_path->data = NULL;
94 }
95 if(nema_gfx_path->seg != NULL) {
96 lv_free(nema_gfx_path->seg);
97 nema_gfx_path->seg = NULL;
98 }
99 lv_free(nema_gfx_path);
100 LV_PROFILER_DRAW_END;
101 }
102
lv_nema_gfx_path_move_to(lv_nema_gfx_path_t * path,float x,float y)103 void lv_nema_gfx_path_move_to(lv_nema_gfx_path_t * path, float x, float y)
104 {
105 LV_ASSERT_NULL(path);
106 LV_ASSERT(path->data_size > data_point + 1);
107 LV_ASSERT(path->seg_size > seg_point);
108 path->seg[seg_point++] = NEMA_VG_PRIM_MOVE;
109 path->data[data_point++] = x;
110 path->data[data_point++] = y;
111 }
112
lv_nema_gfx_path_line_to(lv_nema_gfx_path_t * path,float x,float y)113 void lv_nema_gfx_path_line_to(lv_nema_gfx_path_t * path, float x, float y)
114 {
115 LV_ASSERT_NULL(path);
116 LV_ASSERT(path->data_size > data_point + 1);
117 LV_ASSERT(path->seg_size > seg_point);
118 path->seg[seg_point++] = NEMA_VG_PRIM_LINE;
119 path->data[data_point++] = x;
120 path->data[data_point++] = y;
121
122 }
123
lv_nema_gfx_path_quad_to(lv_nema_gfx_path_t * path,float cx,float cy,float x,float y)124 void lv_nema_gfx_path_quad_to(lv_nema_gfx_path_t * path, float cx, float cy, float x, float y)
125 {
126 LV_ASSERT_NULL(path);
127 LV_ASSERT(path->data_size > data_point + 3);
128 LV_ASSERT(path->seg_size > seg_point);
129 path->seg[seg_point++] = NEMA_VG_PRIM_BEZIER_QUAD;
130 path->data[data_point++] = cx;
131 path->data[data_point++] = cy;
132 path->data[data_point++] = x;
133 path->data[data_point++] = y;
134 }
135
lv_nema_gfx_path_cubic_to(lv_nema_gfx_path_t * path,float cx1,float cy1,float cx2,float cy2,float x,float y)136 void lv_nema_gfx_path_cubic_to(lv_nema_gfx_path_t * path, float cx1, float cy1, float cx2, float cy2, float x, float y)
137 {
138 LV_ASSERT_NULL(path);
139 LV_ASSERT(path->data_size > data_point + 5);
140 LV_ASSERT(path->seg_size > seg_point);
141 path->seg[seg_point++] = NEMA_VG_PRIM_BEZIER_CUBIC;
142 path->data[data_point++] = cx1;
143 path->data[data_point++] = cy1;
144 path->data[data_point++] = cx2;
145 path->data[data_point++] = cy2;
146 path->data[data_point++] = x;
147 path->data[data_point++] = y;
148 }
149
lv_nema_gfx_path_end(lv_nema_gfx_path_t * path)150 void lv_nema_gfx_path_end(lv_nema_gfx_path_t * path)
151 {
152 /* Do Path end jobs....whatever*/
153 seg_point = 0;
154 data_point = 0;
155
156 }
157
158 #endif /*LV_USE_NEMA_VG*/
159 #endif /*LV_USE_NEMA_GFX*/
160