Mercurial > MadButterfly
comparison src/graph_engine_openvg.c @ 604:38514a7c6b26 openvg
Linear gradient for OpenVG
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 04 Jul 2010 15:36:40 +0800 |
parents | 20b396c09c23 |
children | a8fa4c550fe5 |
comparison
equal
deleted
inserted
replaced
603:39d27911c3ae | 604:38514a7c6b26 |
---|---|
1 #include "mb_graph_engine_openvg.h" | 1 #include "mb_graph_engine_openvg.h" |
2 #include "mb_tools.h" | |
2 | 3 |
3 EGLNativeDisplayType _ge_openvg_disp_id = EGL_DEFAULT_DISPLAY; | 4 EGLNativeDisplayType _ge_openvg_disp_id = EGL_DEFAULT_DISPLAY; |
4 mbe_t *_ge_openvg_current_canvas = NULL; | 5 mbe_t *_ge_openvg_current_canvas = NULL; |
5 | 6 |
6 #ifndef ASSERT | 7 #ifndef ASSERT |
9 | 10 |
10 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ | 11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ |
11 (((int)(0xf * g) & 0xf) << 16) | \ | 12 (((int)(0xf * g) & 0xf) << 16) | \ |
12 (((int)(0xf * b) & 0xf) << 16) | \ | 13 (((int)(0xf * b) & 0xf) << 16) | \ |
13 ((int)(0xf * a) & 0xf)) | 14 ((int)(0xf * a) & 0xf)) |
15 | |
16 mbe_pattern_t * | |
17 mbe_pattern_create_linear(co_aix x0, co_aix y0, | |
18 co_aix x1, co_aix y1, | |
19 grad_stop_t *stops, int stop_cnt) { | |
20 VGPaint paint; | |
21 mbe_pattern_t *pattern; | |
22 VGfloat gradient[] = {x0, y0, x1, y1}; | |
23 static VGfloat *ov_stops = 0; | |
24 static int max_stop_cnt = 0; | |
25 VGfloat *cur_ov_stop; | |
26 grad_stop_t *cur_stop; | |
27 int i; | |
28 | |
29 /* Make sure there is enough space */ | |
30 if(max_stop_cnt < stop_cnt) { | |
31 max_stop_cnt = (stop_cnt + 0xf) & ~0xf; | |
32 cur_ov_stop = (VGfloat *)realloc(stops, | |
33 max_stop_cnt * sizeof(VGfloat) * 5); | |
34 if(cur_ov_stop == NULL) { | |
35 max_stop_cnt = 0; | |
36 return NULL; | |
37 } | |
38 ov_stops = cur_ov_stop; | |
39 } | |
40 cur_ov_stop = ov_stops; | |
41 | |
42 cur_stop = stops; | |
43 for(i = 0; i < stop_cnt; i++) { | |
44 *cur_ov_stop++ = cur_stop->offset; | |
45 *cur_ov_stop++ = cur_stop->r; | |
46 *cur_ov_stop++ = cur_stop->g; | |
47 *cur_ov_stop++ = cur_stop->b; | |
48 *cur_ov_stop++ = cur_stop->a; | |
49 } | |
50 | |
51 paint = vgCreatePaint(); | |
52 if(paint == VG_INVALID_HANDLE) | |
53 return NULL; | |
54 vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); | |
55 vgSetParameterfv(paint, VG_PAINT_LINEAR_GRADIENT, 4, gradient); | |
56 vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, 5 * stop_cnt, ov_stops); | |
57 | |
58 pattern = O_ALLOC(mbe_pattern_t); | |
59 if(pattern == NULL) { | |
60 vgPaintDestroy(paint); | |
61 return NULL; | |
62 } | |
63 | |
64 pattern->paint = paint; | |
65 pattern->asso_img = NULL; | |
66 | |
67 return pattern; | |
68 } | |
14 | 69 |
15 void | 70 void |
16 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, | 71 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, |
17 co_comp_t b, co_comp_t a) { | 72 co_comp_t b, co_comp_t a) { |
18 VGPaint paint; | 73 VGPaint paint; |
42 | 97 |
43 _MK_CURRENT_CTX(canvas); | 98 _MK_CURRENT_CTX(canvas); |
44 | 99 |
45 if(n_areas > n_scissors) { | 100 if(n_areas > n_scissors) { |
46 if(scissors) free(scissors); | 101 if(scissors) free(scissors); |
47 n_scissors = (n_areas + 0xf) & 0xf; | 102 n_scissors = (n_areas + 0xf) & ~0xf; |
48 scissors = (VGint *)malloc(sizeof(VGint) * n_scissors * 4); | 103 scissors = (VGint *)malloc(sizeof(VGint) * n_scissors * 4); |
49 ASSERT(scissors != NULL); | 104 ASSERT(scissors != NULL); |
50 } | 105 } |
51 | 106 |
52 coord = scissors; | 107 coord = scissors; |