annotate src/graph_engine_openvg.c @ 1082:af74a96e6624 openvg

Fix bug of access VGImage of a surface
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 03 Dec 2010 01:27:24 +0800
parents 14c2bdcbbcca
children 555d89e704c0
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
1077
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
11 #ifndef ERR
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
12 #include <stdio.h>
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
13 #include <stdlib.h>
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
14 #define ERR(msg) do { fprintf(stderr, __FILE__ ":%d: %s", __LINE__, msg); abort(); } while(0)
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
15 #endif
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
16 #ifndef NOT_IMPLEMENT
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
17 #define NOT_IMPLEMENT(func) \
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
18 ERR(func " is not impmemented\n")
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
19 #endif
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
20
598
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
21 #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
22 (((int)(0xf * g) & 0xf) << 16) | \
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
23 (((int)(0xf * b) & 0xf) << 16) | \
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
24 ((int)(0xf * a) & 0xf))
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
25
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
26 #define MK_ID(mtx) \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
27 do { \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
28 (mtx)[0] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
29 (mtx)[1] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
30 (mtx)[2] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
31 (mtx)[3] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
32 (mtx)[4] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
33 (mtx)[5] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
34 (mtx)[6] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
35 (mtx)[7] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
36 (mtx)[8] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
37 } while(0)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
38
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
39 #define VG_MBE_SURFACE(mbe) ((mbe)->tgt->surface)
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
40
1082
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
41 /*! \brief Information associated with VGImage.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
42 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
43 * A VGImage can associated one of pattern or surface. This type is
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
44 * used to make sure previous associated pattern or surface being
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
45 * released before new association.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
46 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
47 * A _ge_openvg_img can be associated by mutltiple patterns and
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
48 * surfaces. But, at most one of associated patterns or surfaces, the
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
49 * _ge_openvg_img can be activated for at any instant.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
50 * _ge_openvg_img::activated_for trace the object it being activated
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
51 * for. When a context will be current, the _ge_openvg_img associated
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
52 * with its surface would be activated for the surface. When a paint
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
53 * wil be used, the _ge_openvg_img associated must be activated for
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
54 * the paint. Before activated, the old activation must be
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
55 * deactivated. _ge_openvg_img::deactivate_func is a pointer to
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
56 * deactivation function of activated pattern or surface.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
57 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
58 * \sa _ge_openvg_img_t
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
59 * \note This is type is for internal using of OpenVG graphic engine.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
60 */
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
61 struct _ge_openvg_img {
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
62 int ref;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
63 VGImage img;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
64 void *activated_for;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
65 void (*deactivate_func)(void *obj);
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
66 };
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
67
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
68 #define SURFACE_VG_IMG(surface) ((surface)->tgt->asso_img->img)
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
69
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
70 static EGLContext init_ctx;
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
71
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
72 /*! \brief Convert mb_img_fmt_t to VGImageFormat */
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
73 static VGImageFormat
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
74 _mb_ifmt_2_vgifmt(mb_img_fmt_t fmt) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
75 VGImageFormat vgifmt;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
76
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
77 switch(fmt) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
78 case MB_IFMT_ARGB32:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
79 vgifmt = VG_sARGB_8888;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
80 break;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
81
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
82 case MB_IFMT_RGB24:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
83 vgifmt = -1;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
84 break;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
85
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
86 case MB_IFMT_A8:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
87 vgifmt = VG_A_8;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
88 break;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
89
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
90 case MB_IFMT_A1:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
91 vgifmt = -1;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
92 break;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
93
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
94 case MB_IFMT_RGB16_565:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
95 vgifmt = VG_sRGB_565;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
96 break;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
97
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
98 default:
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
99 return -1;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
100 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
101
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
102 return vgifmt;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
103 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
104
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
105 /*! \brief create image object for OpenVG */
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
106 static _ge_openvg_img_t *
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
107 _alloc_vgimage(mb_img_fmt_t fmt, int w, int h) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
108 VGImage vg_img;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
109 VGImageFormat vgifmt;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
110 _ge_openvg_img_t *ge_img;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
111
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
112 vgifmt = _mb_ifmt_2_vgifmt(fmt);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
113 if(vgifmt == -1)
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
114 return NULL;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
115 vg_img = vgCreateImage(vgifmt, w, h,
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
116 VG_IMAGE_QUALITY_NONANTIALIASED);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
117 if(vg_img == VG_INVALID_HANDLE)
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
118 return NULL;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
119 ge_img = O_ALLOC(_ge_openvg_img_t);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
120 if(ge_img == NULL) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
121 vgDestroyImage(vg_img);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
122 return NULL;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
123 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
124 ge_img->ref = 1;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
125 ge_img->img = vg_img;
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
126 ge_img->activated_for = NULL;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
127 ge_img->deactivate_func = NULL;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
128
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
129 return ge_img;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
130 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
131
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
132 /*! \brief Free image object for OpenVG */
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
133 static void
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
134 _free_vgimage(_ge_openvg_img_t *ge_img) {
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
135 if(--ge_img->ref > 0) {
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
136 if(ge_img->activated_for) {
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
137 ge_img->deactivate_func(ge_img->activated_for);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
138 ge_img->activated_for = NULL;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
139 }
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
140 return;
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
141 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
142
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
143 vgDestroyImage(ge_img->img);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
144 free(ge_img);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
145 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
146
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
147 static void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
148 _ge_vg_img_deactivate_for_pattern(void *obj) {
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
149 mbe_pattern_t *ptn = (mbe_pattern_t *)obj;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
150 VGPaint vg_paint;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
151
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
152 vg_paint = ptn->paint;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
153 vgPaintPattern(vg_paint, VG_INVALID_HANDLE);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
154 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
155
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
156 /*! \brief Activate a VGImage for a pattern paint.
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
157 *
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
158 * \sa _ge_openvg_img
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
159 */
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
160 void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
161 _ge_vg_img_activate_for_pattern(mbe_pattern_t *ptn) {
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
162 _ge_openvg_img_t *ge_img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
163 VGPaint vg_paint;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
164 VGImage vg_img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
165
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
166 ge_img = ptn->asso_img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
167 if(ge_img == NULL)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
168 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
169
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
170 if(ge_img->activated_for == (void *)ptn)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
171 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
172
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
173 if(ge_img->activated_for)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
174 ge_img->deactivate_func(ge_img->activated_for);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
175
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
176 ge_img->activated_for = ptn;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
177 ge_img->deactivate_func = _ge_vg_img_deactivate_for_pattern;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
178
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
179 vg_img = ge_img->img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
180 vg_paint = ptn->paint;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
181
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
182 vgPaintPattern(vg_paint, vg_img);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
183 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
184
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
185 /*! \brief Deactivate a VGImage for a VGSurface.
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
186 *
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
187 * A VGImage can not deatached from VGSurface. But, it is not clear
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
188 * in the document of EGL. We assume that a VGImage can be used as
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
189 * pattern of a paint, once associated surface is not current
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
190 * rendering context.
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
191 */
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
192 static void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
193 _ge_vg_img_deactivate_for_surface(void *obj) {
1077
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
194 NOT_IMPLEMENT("_ge_vg_img_deactivate_for_surface");
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
195 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
196
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
197 /*! \brief Activate a VGImage for a surface
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
198 *
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
199 * \sa _ge_openvg_img
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
200 */
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
201 void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
202 _ge_vg_img_activate_for_surface(mbe_surface_t *surf) {
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
203 _ge_openvg_img_t *ge_img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
204
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
205 ge_img = surf->asso_img;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
206 if(ge_img == NULL)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
207 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
208
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
209 if(ge_img->activated_for == (void *)surf)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
210 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
211
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
212 if(ge_img->activated_for)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
213 ge_img->deactivate_func(ge_img->activated_for);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
214
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
215 ge_img->activated_for = surf;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
216 ge_img->deactivate_func = _ge_vg_img_deactivate_for_surface;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
217 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
218
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
219 /*
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
220 * This implementation supports only from image surface.
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
221 */
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
222 mbe_pattern_t *
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
223 mbe_pattern_create_for_surface(mbe_surface_t *surface) {
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
224 mbe_pattern_t *pattern;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
225 _ge_openvg_img_t *ge_img;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
226 VGfloat *mtx;
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
227 VGPaint paint;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
228
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
229 /* Support only from image surface */
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
230 if(surface->asso_img == NULL)
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
231 return NULL;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
232
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
233 paint = vgCreatePaint();
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
234 if(paint == VG_INVALID_HANDLE)
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
235 return NULL;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
236
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
237 ge_img = surface->asso_img;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
238 pattern = O_ALLOC(mbe_pattern_t);
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
239 pattern->asso_img = ge_img;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
240 ge_img->ref++; /* increase reference count */
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
241 pattern->paint = paint;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
242
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
243 mtx = pattern->mtx;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
244 MK_ID(mtx);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
245
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
246 return pattern;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
247 }
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
248
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
249 void
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
250 _mbe_load_pattern_mtx(VGfloat *mtx1, VGfloat *mtx2, int mode) {
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
251 VGfloat affine;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
252
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
253 vgSeti(VG_MATRIX_MODE, mode);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
254 vgLoadMatrix(mtx1);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
255 if(mtx2)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
256 vgMultMatrix(mtx2);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
257 }
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
258
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
259 static mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
260 _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
261 int grad_type,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
262 grad_stop_t *stops, int stop_cnt) {
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
263 VGPaint paint;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
264 mbe_pattern_t *pattern;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
265 static VGfloat *ov_stops = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
266 static int max_stop_cnt = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
267 VGfloat *cur_ov_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
268 grad_stop_t *cur_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
269 int i;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
270
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
271 /* Make sure there is enough space */
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
272 if(max_stop_cnt < stop_cnt) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
273 max_stop_cnt = (stop_cnt + 0xf) & ~0xf;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
274 cur_ov_stop = (VGfloat *)realloc(stops,
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
275 max_stop_cnt * sizeof(VGfloat) * 5);
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
276 if(cur_ov_stop == NULL) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
277 max_stop_cnt = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
278 return NULL;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
279 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
280 ov_stops = cur_ov_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
281 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
282 cur_ov_stop = ov_stops;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
283
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
284 cur_stop = stops;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
285 for(i = 0; i < stop_cnt; i++) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
286 *cur_ov_stop++ = cur_stop->offset;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
287 *cur_ov_stop++ = cur_stop->r;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
288 *cur_ov_stop++ = cur_stop->g;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
289 *cur_ov_stop++ = cur_stop->b;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
290 *cur_ov_stop++ = cur_stop->a;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
291 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
292
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
293 paint = vgCreatePaint();
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
294 if(paint == VG_INVALID_HANDLE)
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
295 return NULL;
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
296 vgSetParameteri(paint, VG_PAINT_TYPE, grad_type);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
297 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
298 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
299
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
300 pattern = O_ALLOC(mbe_pattern_t);
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
301 if(pattern == NULL) {
627
97bf0ff7a038 linked with libEGL and libOpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 622
diff changeset
302 vgDestroyPaint(paint);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
303 return NULL;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
304 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
305
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
306 pattern->paint = paint;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
307 pattern->asso_img = NULL;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
308
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
309 MK_ID(pattern->mtx);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
310
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
311 return pattern;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
312 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
313
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
314 /*
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
315 * \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
316 * point. It means radius0 is not working.
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
317 */
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
318 mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
319 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
320 co_aix radius0,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
321 co_aix cx1, co_aix cy1,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
322 co_aix radius1, grad_stop_t *stops,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
323 int stop_cnt) {
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
324 mbe_pattern_t *pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
325 VGfloat gradient[] = {cx0, cy0, cx1, cy1, radius1};
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
326
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
327 pattern = _mbe_pattern_create_gradient(gradient, 5,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
328 VG_PAINT_TYPE_RADIAL_GRADIENT,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
329 stops, stop_cnt);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
330 return pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
331 }
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
332
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
333 mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
334 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
335 co_aix x1, co_aix y1,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
336 grad_stop_t *stops, int stop_cnt) {
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
337 mbe_pattern_t *pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
338 VGfloat gradient[] = {x0, y0, x1, y1};
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
339
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
340 pattern = _mbe_pattern_create_gradient(gradient, 4,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
341 VG_PAINT_TYPE_LINEAR_GRADIENT,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
342 stops, stop_cnt);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
343 return pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
344 }
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
345
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
346 mbe_pattern_t *
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
347 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
348 VGPaint paint;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
349 mbe_pattern_t *pattern;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
350 _ge_openvg_img_t *ge_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
351 VGImage vg_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
352 VGImageFormat fmt = VG_sARGB_8888;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
353
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
354 /* \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
355 * image.
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
356 */
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
357 if(img->fmt != MB_IFMT_ARGB32)
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
358 return NULL;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
359
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
360 /* Allocate objects */
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
361 ge_img = _alloc_vgimage(MB_IFMT_ARGB32, img->w, img->h);
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
362 pattern = O_ALLOC(mbe_pattern_t);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
363 paint = vgCreatePaint();
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
364 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
365 goto err;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
366
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
367 /* Create and copy pixels into VGImage */
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
368 vg_img = ge_img->img;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
369 vgImageSubData(vg_img, img->content, img->stride, fmt,
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
370 0, 0, img->w, img->h);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
371
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
372 pattern->paint = paint;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
373 pattern->asso_img = ge_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
374
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
375 return pattern;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
376
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
377 err:
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
378 if(ge_img) _free_vgimage(ge_img);
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
379 if(pattern) free(pattern);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
380 if(paint != VG_INVALID_HANDLE) vgDestroyPaint(paint);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
381 vgDestroyImage(vg_img);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
382 return NULL;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
383 }
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
384
600
20b396c09c23 Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents: 598
diff changeset
385 void
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
386 mbe_pattern_destroy(mbe_pattern_t *ptn) {
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
387 if(ptn->asso_img)
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
388 _free_vgimage(ptn->asso_img);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
389 vgDestroyPaint(ptn->paint);
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
390 free(ptn);
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
391 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
392
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
393 void
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
394 mbe_pattern_set_matrix(mbe_pattern_t *ptn, co_aix *mtx) {
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
395 co_aix rev[6];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
396
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
397 compute_reverse(mtx, rev);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
398 ptn->mtx[0] = rev[0];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
399 ptn->mtx[1] = rev[3];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
400 ptn->mtx[2] = 0;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
401 ptn->mtx[3] = rev[1];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
402 ptn->mtx[4] = rev[4];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
403 ptn->mtx[5] = 0;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
404 ptn->mtx[6] = rev[2];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
405 ptn->mtx[7] = rev[5];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
406 ptn->mtx[8] = 1;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
407 }
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
408
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
409 void
600
20b396c09c23 Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents: 598
diff changeset
410 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
411 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
412 VGPaint paint;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
413 VGuint color;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
414
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
415 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
416 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
417 else {
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
418 paint = vgCreatePaint();
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
419 ASSERT(paint != VG_INVALID_HANDLE);
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
420 canvas->paint = paint;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
421 canvas->src = NULL;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
422 }
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
423
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
424 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
425 vgSetColor(paint, color);
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
426 canvas->paint_installed = 0;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
427 }
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
428
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
429 void
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
430 mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) {
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
431 static VGint *scissors = NULL;
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
432 static int n_scissors = 0;
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
433 VGint *coord;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
434 area_t *area;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
435 int i;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
436
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
437 _MK_CURRENT_CTX(canvas);
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
438
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
439 if(n_areas > n_scissors) {
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
440 if(scissors) free(scissors);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
441 n_scissors = (n_areas + 0xf) & ~0xf;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
442 scissors = (VGint *)malloc(sizeof(VGint) * n_scissors * 4);
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
443 ASSERT(scissors != NULL);
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
444 }
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
445
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
446 coord = scissors;
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
447 for(i = 0; i < n_areas; i++) {
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
448 area = areas[i];
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
449 *coord++ = area->x;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
450 *coord++ = area->y;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
451 *coord++ = area->w;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
452 *coord++ = area->h;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
453 }
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
454
616
7d70a811829b mbe_fill_preserve() and mbe_reset_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 614
diff changeset
455 vgSeti(VG_SCISSORING, VG_TRUE);
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
456 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
457 }
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
458
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
459 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
460 _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
461 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
462 EGLDisplay display;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
463 EGLint attrib_list[32];
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
464 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
465 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
466 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
467 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
468
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478 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
479 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
480
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
481 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
482 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
483 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
484 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
485 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
486 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
487 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
488 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
489
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
490 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
491 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
492 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
493 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
494
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
495 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
496 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
497 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
498 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
499
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
500 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
501 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
502 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
503 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
504 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
505 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
506 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
507 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
508
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
509 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
510 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
511 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
512
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
513 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
514 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
515 #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
516 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
517 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
518 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
519 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
520 #endif
630
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
521
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
522 attrib_list[i++] = EGL_RENDERABLE_TYPE;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
523 attrib_list[i++] = EGL_OPENVG_BIT;
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
524
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
525 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
526
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
527 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
528 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
529 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
530 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
531
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
532 *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
533
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
534 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
535 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
536
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
537 #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
538 #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
539 #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
540
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
541 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
542 _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
543 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
544 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
545 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
546 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
547 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
548
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
549 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
550 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
551 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
552 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
553 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
554
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
555 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
556 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
557 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
558 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
559
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
560 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
561 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
562 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
563
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
564 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
565 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
566 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
567
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
568 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
569 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
570 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
571
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
572 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
573 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
574 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
575 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
576
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
577 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
578 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
579
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
580 /*! \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
581 *
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
582 * 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
583 */
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
584 mbe_surface_t *
1077
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
585 mbe_win_surface_create(Display *display, Drawable drawable,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
586 Visual *visual, int width, int height) {
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
587 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
588 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
589 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
590 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
591 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
592 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
593 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
594
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
595 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
596 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
597 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
598
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
599 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
600 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
601 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
602
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
603 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
604 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
605 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
606
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
607 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
608 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
609
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
610 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
611 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
612 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
613 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
614 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
615
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
616 surface->surface = egl_surface;
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
617 surface->asso_mbe = NULL;
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
618 surface->asso_img = NULL;
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
619 surface->fmt = fmt;
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
620
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
621 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
622 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
623
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
624 #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
625
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
626 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
627 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
628 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
629 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
630 EGLConfig config;
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
631 EGLint attrib_list[1] = {EGL_NONE};
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
632 _ge_openvg_img_t *ge_img;
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
633 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
634 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
635
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
636
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
637 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
638 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
639 return NULL;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
640
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
641 ge_img = _alloc_vgimage(fmt, w, h);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
642 if(ge_img == NULL)
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
643 return NULL;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
644
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
645 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
646 /* 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
647 * We need use some other surface to replace this one.
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
648 *
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
649 * EGL does not support any attributes for pbuffer used by OpenVG.
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
650 */
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
651 surface = eglCreatePbufferFromClientBuffer(display, EGL_OPENVG_IMAGE,
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
652 (EGLClientBuffer)ge_img->img,
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
653 config, attrib_list);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
654 if(surface == EGL_NO_SURFACE) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
655 _free_vgimage(ge_img);
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
656 return NULL;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
657 }
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
658
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
659 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
660 if(mbe_surface == NULL) {
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
661 _free_vgimage(ge_img);
591
71df2896877c build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents: 590
diff changeset
662 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
663 return NULL;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
664 }
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
665 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
666 mbe_surface->asso_mbe = NULL;
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
667 mbe_surface->asso_img = ge_img;
592
de9d210e9c38 Specify width and height while create an image surface
Thinker K.F. Li <thinker@branda.to>
parents: 591
diff changeset
668 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
669 mbe_surface->h = h;
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
670 mbe_surface->fmt = fmt;
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
671
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
672 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
673 }
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
674
1077
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
675 mbe_surface_t *
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
676 mbe_image_surface_create_for_data(unsigned char *data,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
677 mb_img_fmt_t fmt,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
678 int width, int height,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
679 int stride) {
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
680 NOT_IMPLEMENT("mbe_image_surface_create_for_data");
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
681 return NULL;
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
682 }
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
683
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
684 void
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
685 mbe_surface_destroy(mbe_surface_t *surface) {
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
686 EGLDisplay display;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
687
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
688 display = _VG_DISPLAY();
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
689 eglDestroySurface(display, surface->surface);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
690
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
691 if(surface->asso_mbe)
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
692 surface->asso_mbe->tgt = NULL;
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
693
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
694 if(surface->asso_img)
618
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
695 _free_vgimage(surface->asso_img);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
696
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
697 free(surface);
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
698 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
699
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
700 void
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
701 mbe_copy_source(mbe_t *src_canvas, mbe_t *dst_canvas) {
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
702 VGImage vg_img;
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
703 EGLDisplay display;
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
704
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
705 ASSERT(src_canvas->tgt->asso_img != NULL);
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
706
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
707 _MK_CURRENT_CTX(dst_canvas);
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
708
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
709 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
710 vgLoadIdentity();
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
711
1082
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
712 vg_img = SURFACE_VG_IMG(src_canvas);
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
713 vgDrawImage(vg_img);
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
714
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
715 display = _VG_DISPLAY();
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
716 eglSwapBuffers(display, VG_MBE_SURFACE(dst_canvas));
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
717 }
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
718
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
719 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
720 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
721 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
722 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
723 EGLContext ctx, shared;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
724 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
725 EGLint attrib_list[2] = {EGL_NONE};
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
726 static VGfloat clear_color[4] = {0, 0, 0, 1};
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
727 mbe_t *canvas;
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
728 int r;
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
729
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
730 display = _VG_DISPLAY();
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
731
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
732 r = _openvg_find_config(surface->fmt, surface->w, surface->h, &config);
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
733 if(r != 0)
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
734 return NULL;
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
735
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
736 /* shared = EGL_NO_CONTEXT; */
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
737 shared = init_ctx;
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
738 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
739 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
740 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
741
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
742 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
743 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
744 if(path == VG_INVALID_HANDLE) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
745 eglDestroyContext(display, ctx);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
746 return NULL;
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
747 }
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
748
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
749 canvas = O_ALLOC(mbe_t);
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
750 if(canvas == NULL) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
751 eglDestroyContext(display, ctx);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
752 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
753 return NULL;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
754 }
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
755
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
756 canvas->src = NULL;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
757 canvas->paint = VG_INVALID_HANDLE;
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
758 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
759 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
760 canvas->ctx = ctx;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
761 canvas->path = path;
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
762
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
763 surface->asso_mbe = canvas;
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
764
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
765 /* Set clear color for the context */
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
766 _MK_CURRENT_CTX(canvas);
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
767 vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
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
768
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
769 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
770 }
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
771
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
772 void
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
773 mbe_destroy(mbe_t *canvas) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
774 EGLDisplay display;
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
775
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
776 display = _VG_DISPLAY();
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
777
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
778 vgDestroyPath(canvas->path);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
779 eglDestroyContext(display, canvas->ctx);
591
71df2896877c build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents: 590
diff changeset
780 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
781 free(canvas);
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
782 }
593
ac942664fe86 stroke and fill for VG
Thinker K.F. Li <thinker@branda.to>
parents: 592
diff changeset
783
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
784 void
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
785 mbe_paint_with_alpha(mbe_t *canvas, co_comp_t alpha) {
629
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
786 VGfloat color_trans[8] = {1, 1, 1, alpha, 0, 0, 0, 0};
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
787 EGLDisplay display;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
788 EGLint w, h;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
789 EGLBoolean r;
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
790
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
791 _MK_CURRENT_CTX(canvas);
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
792
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
793 display = _VG_DISPLAY();
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
794
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
795 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
796 ASSERT(r == EGL_TRUE);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
797 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
798 ASSERT(r == EGL_TRUE);
629
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
799
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
800 /* Setup color transform for alpha */
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
801 #ifdef OPENVG_1_1
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
802 vgSetfv(VG_COLOR_TRANSFORM_VALUES, 8, color_trans);
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
803 vgSeti(VG_COLOR_TRANSFORM, VG_TRUE);
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
804 #endif
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
805
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
806 mbe_paint(canvas);
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
807
629
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
808 #ifdef OPENVG_1_1
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
809 vgSeti(VG_COLOR_TRANSFORM, VG_FALSE);
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
810 #endif
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
811 }
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
812
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
813 void
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
814 mbe_paint(mbe_t *canvas) {
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
815 EGLDisplay display;
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
816 EGLint w, h;
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
817 EGLBoolean r;
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
818 VGPath path;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
819
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
820 _MK_CURRENT_CTX(canvas);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
821 _MK_CURRENT_PAINT(canvas);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
822 if(canvas->src)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
823 _mbe_load_pattern_mtx(canvas->src->mtx, NULL,
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
824 VG_MATRIX_FILL_PAINT_TO_USER);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
825
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
826 display = _VG_DISPLAY();
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
827
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
828 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
829 ASSERT(r == EGL_TRUE);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
830 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
831 ASSERT(r == EGL_TRUE);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
832
614
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
833 /*
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
834 * Disable scissoring and identity transform matrix.
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
835 *
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
836 * Transform matrix from path to surface is assigned by
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
837 * mbe_transform(). Here, we temporary set it to identity, and
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
838 * restore it after paint.
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
839 */
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
840 vgSeti(VG_SCISSORING, VG_FALSE);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
841 vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
842 vgLoadIdentity();
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
843
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
844 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
845 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
846 vguRect(path, 0, 0, w, h);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
847 vgDrawPath(path, VG_FILL_PATH);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
848 vgDestroyPath(path);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
849
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
850 /* re-enable scissoring and restore transform matrix */
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
851 vgLoadMatrix(canvas->mtx);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
852 vgSeti(VG_SCISSORING, VG_TRUE);
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
853 }
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
854
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
855 void
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
856 mbe_clear(mbe_t *canvas) {
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
857 EGLDisplay display;
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
858 EGLint w, h;
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
859 EGLBoolean r;
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
860
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
861 _MK_CURRENT_CTX(canvas);
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
862
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
863 display = _VG_DISPLAY();
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
864
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
865 r = eglQuerySurface(display, canvas->tgt, EGL_WIDTH, &w);
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
866 ASSERT(r == EGL_TRUE);
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
867 r = eglQuerySurface(display, canvas->tgt, EGL_HEIGHT, &h);
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
868 ASSERT(r == EGL_TRUE);
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
869
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
870 /* Clear regions to the color specified by mbe_create() */
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
871 vgClear(0, 0, w, h);
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
872 }
630
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
873
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
874 void mbe_init() {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
875 static EGLSurface init_surf;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
876 EGLDisplay display;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
877 EGLConfig config;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
878 EGLint nconfigs;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
879 EGLint attrib_list[] = {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
880 EGL_RED_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
881 EGL_GREEN_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
882 EGL_BLUE_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
883 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
884 EGL_NONE};
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
885 EGLint surf_attribs[] = {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
886 EGL_WIDTH, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
887 EGL_HEIGHT, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
888 EGL_NONE};
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
889 EGLBoolean r;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
890
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
891 display = _VG_DISPLAY();
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
892 eglInitialize(display, NULL, NULL);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
893
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
894 r = eglChooseConfig(display, attrib_list, &config, 1, &nconfigs);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
895 ASSERT(r);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
896
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
897 eglBindAPI(EGL_OPENVG_API);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
898
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
899 init_ctx = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
900 ASSERT(init_ctx != EGL_NO_CONTEXT);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
901
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
902 init_surf = eglCreatePbufferSurface(display, config, surf_attribs);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
903 ASSERT(init_surf != EGL_NO_SURFACE);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
904
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
905 eglMakeCurrent(display, init_surf, init_surf, init_ctx);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
906 }
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
907