Mercurial > MadButterfly
annotate src/graph_engine_openvg.c @ 608:6c74bc371e37 openvg
paint with alpha for OpenVG
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 05 Jul 2010 10:56:23 +0800 |
parents | 51dc49fd34a8 |
children | e78bff7d23d3 |
rev | line source |
---|---|
582
dd546c4da180
deal with EGL surface, context for OpenVG GE
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #include "mb_graph_engine_openvg.h" |
604
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
2 #include "mb_tools.h" |
582
dd546c4da180
deal with EGL surface, context for OpenVG GE
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 |
dd546c4da180
deal with EGL surface, context for OpenVG GE
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 EGLNativeDisplayType _ge_openvg_disp_id = EGL_DEFAULT_DISPLAY; |
584
543a2a8523fb
Make surce current VG context
Thinker K.F. Li <thinker@branda.to>
parents:
582
diff
changeset
|
5 mbe_t *_ge_openvg_current_canvas = NULL; |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
6 |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
7 #ifndef ASSERT |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
8 #define ASSERT(x) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
9 #endif |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
10 |
598
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
12 (((int)(0xf * g) & 0xf) << 16) | \ |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
13 (((int)(0xf * b) & 0xf) << 16) | \ |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
14 ((int)(0xf * a) & 0xf)) |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
15 |
606
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
16 static mbe_pattern_t * |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
17 _mbe_pattern_create_gradient(VGfloat *gradient, int grad_len, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
18 int grad_type, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
19 grad_stop_t *stops, int stop_cnt) { |
604
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
20 VGPaint paint; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
21 mbe_pattern_t *pattern; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
22 static VGfloat *ov_stops = 0; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
23 static int max_stop_cnt = 0; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
24 VGfloat *cur_ov_stop; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
25 grad_stop_t *cur_stop; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
26 int i; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
27 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
28 /* Make sure there is enough space */ |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
29 if(max_stop_cnt < stop_cnt) { |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
30 max_stop_cnt = (stop_cnt + 0xf) & ~0xf; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
31 cur_ov_stop = (VGfloat *)realloc(stops, |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
32 max_stop_cnt * sizeof(VGfloat) * 5); |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
33 if(cur_ov_stop == NULL) { |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
34 max_stop_cnt = 0; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
35 return NULL; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
36 } |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
37 ov_stops = cur_ov_stop; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
38 } |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
39 cur_ov_stop = ov_stops; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
40 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
41 cur_stop = stops; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
42 for(i = 0; i < stop_cnt; i++) { |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
43 *cur_ov_stop++ = cur_stop->offset; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
44 *cur_ov_stop++ = cur_stop->r; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
45 *cur_ov_stop++ = cur_stop->g; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
46 *cur_ov_stop++ = cur_stop->b; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
47 *cur_ov_stop++ = cur_stop->a; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
48 } |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
49 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
50 paint = vgCreatePaint(); |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
51 if(paint == VG_INVALID_HANDLE) |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
52 return NULL; |
606
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
53 vgSetParameteri(paint, VG_PAINT_TYPE, grad_type); |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
54 vgSetParameterfv(paint, VG_PAINT_RADIAL_GRADIENT, grad_len, gradient); |
604
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
55 vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, 5 * stop_cnt, ov_stops); |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
56 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
57 pattern = O_ALLOC(mbe_pattern_t); |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
58 if(pattern == NULL) { |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
59 vgPaintDestroy(paint); |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
60 return NULL; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
61 } |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
62 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
63 pattern->paint = paint; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
64 pattern->asso_img = NULL; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
65 |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
66 return pattern; |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
67 } |
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
68 |
606
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
69 /* |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
70 * \note OpenVG does not support start circle, it supports only focal |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
71 * point. It means radius0 is not working. |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
72 */ |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
73 mbe_pattern_t * |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
74 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
75 co_aix radius0, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
76 co_aix cx1, co_aix cy1, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
77 co_aix radius1, grad_stop_t *stops, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
78 int stop_cnt) { |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
79 mbe_pattern_t *pattern; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
80 VGfloat gradient[] = {cx0, cy0, cx1, cy1, radius1}; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
81 |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
82 pattern = _mbe_pattern_create_gradient(gradient, 5, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
83 VG_PAINT_TYPE_RADIAL_GRADIENT, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
84 stops, stop_cnt); |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
85 return pattern; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
86 } |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
87 |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
88 mbe_pattern_t * |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
89 mbe_pattern_create_linear(co_aix x0, co_aix y0, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
90 co_aix x1, co_aix y1, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
91 grad_stop_t *stops, int stop_cnt) { |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
92 mbe_pattern_t *pattern; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
93 VGfloat gradient[] = {x0, y0, x1, y1}; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
94 |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
95 pattern = _mbe_pattern_create_gradient(gradient, 4, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
96 VG_PAINT_TYPE_LINEAR_GRADIENT, |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
97 stops, stop_cnt); |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
98 return pattern; |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
99 } |
e21eb54c7d9c
Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents:
605
diff
changeset
|
100 |
607
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
101 mbe_pattern_t * |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
102 mbe_pattern_create_image(mb_img_data_t *img) { |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
103 VGPaint paint; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
104 mbe_pattern_t *pattern; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
105 _ge_openvg_img_t *ge_img; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
106 VGImage vg_img; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
107 VGImageFormat fmt = VG_sARGB_8888; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
108 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
109 /* \note OpenVG implementation supports one \ref MB_IFMT_ARGB32 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
110 * image. |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
111 */ |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
112 if(img->fmt != MB_IFMT_ARGB32) |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
113 return NULL; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
114 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
115 /* Create and copy pixels into VGImage */ |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
116 vg_img = vgCreateImage(fmt, img->w, img->h, |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
117 VG_IMAGE_QUALITY_NONANTIALIASED); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
118 if(vg_img == VG_INVALID_HANDLE) |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
119 return NULL; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
120 vgImageSubData(vg_img, img->content, img->stride, fmt, |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
121 0, 0, img->w, img->h); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
122 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
123 /* Allocate objects */ |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
124 ge_img = O_ALLOC(_ge_openvg_img_t); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
125 pattern = O_ALLOC(mbe_pattern_t); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
126 paint = vgCreatePaint(); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
127 if(ge_img == NULL || pattern == NULL || paint == VG_INVALID_HANDLE) |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
128 goto err; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
129 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
130 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
131 /* Initialize objects */ |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
132 ge_img->img = vg_img; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
133 ge_img->asso_pattern = NULL; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
134 ge_img->asso_surface = NULL; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
135 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
136 pattern->paint = paint; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
137 pattern->asso_img = ge_img; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
138 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
139 return pattern; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
140 |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
141 err: |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
142 if(ge_img) free(ge_img); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
143 if(pattern) free(pattern); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
144 if(paint != VG_INVALID_HANDLE) vgDestroyPaint(paint); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
145 vgDestroyImage(vg_img); |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
146 return NULL; |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
147 } |
51dc49fd34a8
Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents:
606
diff
changeset
|
148 |
600
20b396c09c23
Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents:
598
diff
changeset
|
149 void |
20b396c09c23
Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents:
598
diff
changeset
|
150 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, |
20b396c09c23
Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents:
598
diff
changeset
|
151 co_comp_t b, co_comp_t a) { |
598
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
152 VGPaint paint; |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
153 VGuint color; |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
154 |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
155 if(paint != VG_INVALID_HANDLE && canvas->src == NULL) |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
156 paint = canvas->paint; /* previous one is also a color paint */ |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
157 else { |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
158 paint = vgCreatePaint(); |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
159 ASSERT(paint != VG_INVALID_HANDLE); |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
160 canvas->paint = paint; |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
161 canvas->src = NULL; |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
162 } |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
163 |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
164 color = MB_2_VG_COLOR(r, g, b, a); |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
165 vgSetColor(paint, color); |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
166 canvas->paint_installed = 0; |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
167 } |
aba62eb9362d
define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents:
597
diff
changeset
|
168 |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
169 void |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
170 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { |
595 | 171 static VGint *scissors = NULL; |
172 static int n_scissors = 0; | |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
173 VGint *coord; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
174 area_t *area; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
175 int i; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
176 |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
177 _MK_CURRENT_CTX(canvas); |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
178 |
595 | 179 if(n_areas > n_scissors) { |
180 if(scissors) free(scissors); | |
604
38514a7c6b26
Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
600
diff
changeset
|
181 n_scissors = (n_areas + 0xf) & ~0xf; |
595 | 182 scissors = (VGint *)malloc(sizeof(VGint) * n_scissors * 4); |
183 ASSERT(scissors != NULL); | |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
184 } |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
185 |
595 | 186 coord = scissors; |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
187 for(i = 0; i < n_areas; i++) { |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
188 area = areas[i]; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
189 *coord++ = area->x; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
190 *coord++ = area->y; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
191 *coord++ = area->w; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
192 *coord++ = area->h; |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
193 } |
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
194 |
595 | 195 vgSetiv(VG_SCISSOR_RECTS, n_areas * 4, scissors); |
588
e9923024f65e
Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
584
diff
changeset
|
196 } |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
197 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
198 static int |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
199 _openvg_find_config(mb_img_fmt_t fmt, int w, int h, |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
200 EGLConfig *config) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
201 EGLDisplay display; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
202 EGLint attrib_list[16]; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
203 EGLConfig configs[1]; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
204 EGLint nconfigs; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
205 int i = 0; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
206 EGLBoolean r; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
207 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
208 switch(fmt) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
209 case MB_IFMT_ARGB32: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
210 attrib_list[i++] = EGL_RED_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
211 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
212 attrib_list[i++] = EGL_GREEN_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
213 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
214 attrib_list[i++] = EGL_BLUE_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
215 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
216 attrib_list[i++] = EGL_ALPHA_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
217 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
218 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
219 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
220 case MB_IFMT_RGB24: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
221 attrib_list[i++] = EGL_RED_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
222 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
223 attrib_list[i++] = EGL_GREEN_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
224 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
225 attrib_list[i++] = EGL_BLUE_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
226 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
227 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
228 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
229 case MB_IFMT_A8: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
230 attrib_list[i++] = EGL_ALPHA_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
231 attrib_list[i++] = 8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
232 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
233 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
234 case MB_IFMT_A1: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
235 attrib_list[i++] = EGL_ALPHA_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
236 attrib_list[i++] = 1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
237 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
238 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
239 case MB_IFMT_RGB16_565: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
240 attrib_list[i++] = EGL_RED_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
241 attrib_list[i++] = 5; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
242 attrib_list[i++] = EGL_GREEN_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
243 attrib_list[i++] = 6; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
244 attrib_list[i++] = EGL_BLUE_SIZE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
245 attrib_list[i++] = 5; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
246 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
247 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
248 default: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
249 return -1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
250 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
251 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
252 attrib_list[i++] = EGL_SURFACE_TYPE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
253 attrib_list[i++] = EGL_PBUFFER_BIT; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
254 #if 0 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
255 attrib_list[i++] = EGL_MAX_PBUFFER_WIDTH; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
256 attrib_list[i++] = w; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
257 attrib_list[i++] = EGL_MAX_PBUFFER_HEIGHT; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
258 attrib_list[i++] = h; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
259 #endif |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
260 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
261 attrib_list[i++] = EGL_NONE; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
262 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
263 display = _VG_DISPLAY(); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
264 r = eglChooseConfig(display, attrib_list, configs, 1, &nconfigs); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
265 if(!r) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
266 return -1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
267 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
268 *config = configs[0]; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
269 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
270 return 0; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
271 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
272 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
273 #ifdef EGL_GLX |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
274 #include <X11/Xlib.h> |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
275 #include <X11/Xutil.h> |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
276 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
277 static int |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
278 _get_img_fmt_from_xvisual(Display *display, Visual *visual) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
279 VisualID visual_id; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
280 XVisualInfo temp; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
281 XVisualInfo *infos; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
282 int n; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
283 int fmt = -1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
284 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
285 visual_id = XVisualIDFromVisual(visual); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
286 temp.visualid = visual_id; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
287 infos = XGetVisualInfo(display, VisualIDMask, &temp, &n); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
288 if(n != 1) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
289 return -1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
290 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
291 switch(infos->depth) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
292 case 32: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
293 fmt = MB_IFMT_ARGB32; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
294 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
295 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
296 case 24: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
297 fmt = MB_IFMT_RGB24; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
298 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
299 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
300 case 16: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
301 fmt = MB_IFMT_RGB16_565; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
302 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
303 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
304 case 8: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
305 fmt = MB_IFMT_A8; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
306 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
307 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
308 case 1: |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
309 fmt = MB_IFMT_A1; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
310 break; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
311 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
312 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
313 return fmt; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
314 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
315 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
316 /*! \brief Create an EGL window surface for X11. |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
317 * |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
318 * This function is compiled only for GLX enabled. |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
319 */ |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
320 mbe_surface_t * |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
321 mbe_vg_win_surface_create(Display *display, Drawable drawable, |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
322 Visual *visual, int width, int height) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
323 EGLDisplay egl_disp; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
324 EGLSurface egl_surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
325 mbe_surface_t *surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
326 EGLConfig config; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
327 EGLint attrib_list[2] = {EGL_NONE}; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
328 int fmt; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
329 int r; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
330 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
331 fmt = _get_img_fmt_from_xvisual(display, visual); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
332 if(fmt == -1) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
333 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
334 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
335 r = _openvg_find_config(fmt, width, height, &config); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
336 if(r != 0) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
337 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
338 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
339 egl_disp = eglGetDisplay(display); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
340 if(egl_disp == EGL_NO_DISPLAY || egl_disp != _VG_DISPLAY()) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
341 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
342 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
343 egl_surface = eglCreateWindowSurface(egl_disp, config, drawable, |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
344 attrib_list); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
345 |
605
a8fa4c550fe5
use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents:
604
diff
changeset
|
346 surface = O_ALLOC(mbe_surface_t); |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
347 if(surface == NULL) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
348 eglDestroySurface(egl_disp, egl_surface); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
349 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
350 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
351 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
352 surface->surface = egl_surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
353 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
354 return surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
355 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
356 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
357 #endif |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
358 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
359 mbe_surface_t * |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
360 mbe_image_surface_create(mb_img_fmt_t fmt, int w, int h) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
361 EGLSurface surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
362 EGLDisplay display; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
363 EGLConfig config; |
592
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
364 EGLint attrib_list[5]; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
365 mbe_surface_t *mbe_surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
366 int r; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
367 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
368 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
369 r = _openvg_find_config(fmt, w, h, &config); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
370 if(r != 0) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
371 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
372 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
373 display = _VG_DISPLAY(); |
592
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
374 attrib_list[0] = EGL_WIDTH; |
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
375 attrib_list[1] = w; |
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
376 attrib_list[2] = EGL_HEIGHT; |
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
377 attrib_list[3] = h; |
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
378 attrib_list[4] = EGL_NONE; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
379 /* Some implementation does not support pbuffer. |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
380 * We need use some other surface to replace this one. |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
381 */ |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
382 surface = eglCreatePbufferSurface(display, config, attrib_list); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
383 if(surface == EGL_NO_SURFACE) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
384 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
385 |
605
a8fa4c550fe5
use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents:
604
diff
changeset
|
386 mbe_surface = O_ALLOC(mbe_surface_t); |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
387 if(mbe_surface == NULL) { |
591
71df2896877c
build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents:
590
diff
changeset
|
388 eglDestroySurface(display, surface); |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
389 return NULL; |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
390 } |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
391 mbe_surface->surface = surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
392 mbe_surface->asso_mbe = NULL; |
592
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
393 mbe_surface->w = w; |
de9d210e9c38
Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents:
591
diff
changeset
|
394 mbe_surface->h = h; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
395 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
396 return mbe_surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
397 } |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
398 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
399 mbe_t * |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
400 mbe_create(mbe_surface_t *surface) { |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
401 EGLDisplay display; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
402 EGLConfig config; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
403 EGLContext ctx, shared; |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
404 VGPath path; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
405 EGLint attrib_list[2] = {EGL_NONE}; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
406 mbe_t *canvas; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
407 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
408 display = _VG_DISPLAY(); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
409 ctx = eglCreateContext(display, config, shared, attrib_list); |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
410 if(ctx == EGL_NO_CONTEXT) |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
411 return NULL; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
412 |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
413 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
414 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
415 if(path == VG_INVALID_HANDLE) { |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
416 eglDestroyContext(display, ctx); |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
417 return NULL; |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
418 } |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
419 |
605
a8fa4c550fe5
use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents:
604
diff
changeset
|
420 canvas = O_ALLOC(mbe_t); |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
421 if(canvas == NULL) { |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
422 eglDestroyContext(display, ctx); |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
423 vgDestroyPath(path); |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
424 return NULL; |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
425 } |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
426 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
427 canvas->src = NULL; |
595 | 428 canvas->paint = VG_INVALID_HANDLE; |
597
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
429 canvas->paint_installed = 0; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
430 canvas->tgt = surface; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
431 canvas->ctx = ctx; |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
432 canvas->path = path; |
589
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
433 |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
434 return canvas; |
d733e198bb25
Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents:
588
diff
changeset
|
435 } |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
436 |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
437 void |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
438 mbe_destroy(mbe_t *canvas) { |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
439 EGLDisplay display; |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
440 |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
441 display = _VG_DISPLAY(); |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
442 |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
443 vgDestroyPath(canvas->path); |
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
444 eglDestroyContext(display, canvas->ctx); |
591
71df2896877c
build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents:
590
diff
changeset
|
445 canvas->tgt->asso_mbe = NULL; /* remove association */ |
71df2896877c
build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents:
590
diff
changeset
|
446 free(canvas); |
590
b714f0c9992e
include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents:
589
diff
changeset
|
447 } |
593 | 448 |
608
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
449 /* |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
450 * This implementation support only paint with image paint. OpenVG |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
451 * does not support paint path with an alpha value. But, it supports |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
452 * to draw image with an alpha value. |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
453 */ |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
454 void |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
455 mbe_paint_with_alpha(mbe_t *canvas, co_comp_t alpha) { |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
456 VGImage vg_img; |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
457 _ge_openvg_img_t *ge_img; |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
458 |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
459 _MK_CURRENT_CTX(canvas); |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
460 |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
461 ASSERT(canvas->src != NULL && canvas->src->asso_img != NULL); |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
462 ge_img = canvas->src->asso_img; |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
463 vg_img = ge_img->img; |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
464 |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
465 vgDrawImage(vg_img); |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
466 } |
6c74bc371e37
paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents:
607
diff
changeset
|
467 |
595 | 468 void |
469 mbe_paint(mbe_t *canvas) { | |
596
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
470 EGLDisplay display; |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
471 EGLint w, h; |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
472 EGLBoolean r; |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
473 VGPath path; |
595 | 474 |
596
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
475 _MK_CURRENT_CTX(canvas); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
476 _MK_CURRENT_PAINT(canvas); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
477 |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
478 display = _VG_DISPLAY(); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
479 |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
480 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
481 ASSERT(r == EGL_TRUE); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
482 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
483 ASSERT(r == EGL_TRUE); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
484 |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
485 vgSeti(VG_SCISSORING, VG_FALSE); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
486 |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
487 path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
488 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
489 vguRect(path, 0, 0, w, h); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
490 vgDrawPath(path, VG_FILL_PATH); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
491 vgDestroyPath(path); |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
492 |
aaab76730beb
Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
595
diff
changeset
|
493 vgSeti(VG_SCISSORING, VG_TRUE); |
595 | 494 } |
495 | |
597
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
496 void |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
497 mbe_clear(mbe_t *canvas) { |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
498 VGPaint paint; |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
499 |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
500 _MK_CURRENT_CTX(canvas); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
501 |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
502 paint = vgCreatePaint(); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
503 ASSERT(paint != VG_INVALID_HANDLE); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
504 vgSetColor(paint, 0); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
505 |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
506 vgSetPaint(paint, VG_FILL_PATH); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
507 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
508 vgDrawPath(canvas->path, VG_FILL_PATH); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
509 vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
510 |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
511 vgDestroyPaint(paint); |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
512 |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
513 canvas->paint_installed = 0; |
3300992b29ff
Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents:
596
diff
changeset
|
514 } |