annotate src/graph_engine_openvg.c @ 1532:4a92b639a1cd

Clear selection set when switching current scene. To clear selection set after switching away from current to another scene. It avoids Inkscape select on nodes they are not saw after switching.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 30 Sep 2011 12:31:33 +0800
parents baf4c4d48cff
children
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
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
21 #define MK_ID(mtx) \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
22 do { \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
23 (mtx)[0] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
24 (mtx)[1] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
25 (mtx)[2] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
26 (mtx)[3] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
27 (mtx)[4] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
28 (mtx)[5] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
29 (mtx)[6] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
30 (mtx)[7] = 0; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
31 (mtx)[8] = 1; \
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
32 } while(0)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
33
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
34 #define VG_MBE_EGLSURFACE(mbe) ((EGLSurface *)(mbe)->tgt->surface)
1080
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
35
1082
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
36 /*! \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
37 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
38 * 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
39 * 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
40 * released before new association.
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
41 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
42 * 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
43 * 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
44 * _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
45 * _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
46 * 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
47 * 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
48 * 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
49 * 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
50 * 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
51 * 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
52 *
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
53 * \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
54 * \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
55 */
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
56 struct _ge_openvg_img {
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
57 int ref;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
58 VGImage img;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
59 void *activated_for;
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
60 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
61 };
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
62
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
63 #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
64
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
65 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
66
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
67 /*! \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
68 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
69 _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
70 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
71
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 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
73 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
74 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
75 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
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 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
78 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
79 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
80
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 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
82 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
83 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
84
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 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
86 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
87 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
88
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 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
90 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
91 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
92
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 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
94 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
95 }
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
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 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
98 }
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
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 /*! \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
101 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
102 _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
103 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
104 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
105 _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
106
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 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
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 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
117 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
118 }
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->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
120 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
121 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
122 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
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 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
125 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
126
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
127 /*! \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
128 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
129 _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
130 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
131 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
132 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
133 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
134 }
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
135 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
136 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
137
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
138 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
139 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
140 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
141
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
142 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
143 _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
144 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
145 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
146
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
147 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
148 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
149 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
150
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
151 /*! \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
152 *
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
153 * \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
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 void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
156 _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
157 _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
158 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
159 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
160
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_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
162 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
163 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
164
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
165 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
166 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
167
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
168 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
169 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
170
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
171 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
172 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
173
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
174 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
175 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
176
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
177 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
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
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
180 /*! \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
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 * 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
183 * 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
184 * 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
185 * 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
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 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
188 _ge_vg_img_deactivate_for_surface(void *obj) {
1083
555d89e704c0 Check if the pattern is NULL for free it for a radial paint
Thinker K.F. Li <thinker@codemud.net>
parents: 1082
diff changeset
189 /* 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
190 }
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 /*! \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
193 *
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
194 * \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
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 void
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
197 _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
198 _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
199
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
200 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
201 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
202 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
203
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
204 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
205 return;
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
206
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
207 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
208 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
209
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
210 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
211 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
212 }
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
213
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
214 /*
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
215 * 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
216 */
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
217 mbe_pattern_t *
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
218 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
219 mbe_pattern_t *pattern;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
220 _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
221 VGfloat *mtx;
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
222 VGPaint paint;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
223
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
224 /* Support only from image surface */
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
225 if(surface->asso_img == NULL)
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
226 return NULL;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
227
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
228 paint = vgCreatePaint();
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
229 if(paint == VG_INVALID_HANDLE)
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
230 return NULL;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
231
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
232 ge_img = surface->asso_img;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
233 pattern = O_ALLOC(mbe_pattern_t);
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
234 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
235 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
236 pattern->paint = paint;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
237
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
238 mtx = pattern->mtx;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
239 MK_ID(mtx);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
240
610
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
241 return pattern;
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
242 }
e78bff7d23d3 create pattern from surface for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 608
diff changeset
243
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
244 void
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
245 _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
246 VGfloat affine;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
247
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
248 vgSeti(VG_MATRIX_MODE, mode);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
249 vgLoadMatrix(mtx1);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
250 if(mtx2)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
251 vgMultMatrix(mtx2);
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
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
254 static mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
255 _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
256 int grad_type,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
257 grad_stop_t *stops, int stop_cnt) {
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
258 VGPaint paint;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
259 mbe_pattern_t *pattern;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
260 static VGfloat *ov_stops = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
261 static int max_stop_cnt = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
262 VGfloat *cur_ov_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
263 grad_stop_t *cur_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
264 int i;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
265
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
266 /* Make sure there is enough space */
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
267 if(max_stop_cnt < stop_cnt) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
268 max_stop_cnt = (stop_cnt + 0xf) & ~0xf;
1086
6723b2537993 Fix the issue that radial patterns would be changed in undefined way.
Thinker K.F. Li <thinker@codemud.net>
parents: 1085
diff changeset
269 cur_ov_stop = (VGfloat *)realloc(ov_stops,
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
270 max_stop_cnt * sizeof(VGfloat) * 5);
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
271 if(cur_ov_stop == NULL) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
272 max_stop_cnt = 0;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
273 return NULL;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
274 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
275 ov_stops = cur_ov_stop;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
276 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
277 cur_ov_stop = ov_stops;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
278
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
279 cur_stop = stops;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
280 for(i = 0; i < stop_cnt; i++) {
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
281 *cur_ov_stop++ = cur_stop->offset;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
282 *cur_ov_stop++ = cur_stop->r;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
283 *cur_ov_stop++ = cur_stop->g;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
284 *cur_ov_stop++ = cur_stop->b;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
285 *cur_ov_stop++ = cur_stop->a;
1085
e229e1be6b82 Fix issue of radial pattern does not be gradiant
Thinker K.F. Li <thinker@codemud.net>
parents: 1083
diff changeset
286 cur_stop++;
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
287 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
288
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
289 paint = vgCreatePaint();
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
290 if(paint == VG_INVALID_HANDLE)
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
291 return NULL;
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
292 vgSetParameteri(paint, VG_PAINT_TYPE, grad_type);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
293 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
294 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
295
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
296 pattern = O_ALLOC(mbe_pattern_t);
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
297 if(pattern == NULL) {
627
97bf0ff7a038 linked with libEGL and libOpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 622
diff changeset
298 vgDestroyPaint(paint);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
299 return NULL;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
300 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
301
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
302 pattern->paint = paint;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
303 pattern->asso_img = NULL;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
304
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
305 MK_ID(pattern->mtx);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
306
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
307 return pattern;
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
308 }
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
309
606
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
310 /*
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
311 * \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
312 * point. It means radius0 is not working.
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
313 */
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
314 mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
315 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
316 co_aix radius0,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
317 co_aix cx1, co_aix cy1,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
318 co_aix radius1, grad_stop_t *stops,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
319 int stop_cnt) {
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
320 mbe_pattern_t *pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
321 VGfloat gradient[] = {cx0, cy0, cx1, cy1, radius1};
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
322
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
323 pattern = _mbe_pattern_create_gradient(gradient, 5,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
324 VG_PAINT_TYPE_RADIAL_GRADIENT,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
325 stops, stop_cnt);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
326 return pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
327 }
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
328
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
329 mbe_pattern_t *
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
330 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
331 co_aix x1, co_aix y1,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
332 grad_stop_t *stops, int stop_cnt) {
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
333 mbe_pattern_t *pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
334 VGfloat gradient[] = {x0, y0, x1, y1};
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
335
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
336 pattern = _mbe_pattern_create_gradient(gradient, 4,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
337 VG_PAINT_TYPE_LINEAR_GRADIENT,
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
338 stops, stop_cnt);
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
339 return pattern;
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
340 }
e21eb54c7d9c Implement radial gradient paint.
Thinker K.F. Li <thinker@branda.to>
parents: 605
diff changeset
341
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
342 mbe_pattern_t *
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
343 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
344 VGPaint paint;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
345 mbe_pattern_t *pattern;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
346 _ge_openvg_img_t *ge_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
347 VGImage vg_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
348 VGImageFormat fmt = VG_sARGB_8888;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
349
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
350 /* \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
351 * image.
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
352 */
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
353 if(img->fmt != MB_IFMT_ARGB32)
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
354 return NULL;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
355
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
356 /* 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
357 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
358 pattern = O_ALLOC(mbe_pattern_t);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
359 paint = vgCreatePaint();
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
360 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
361 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
362
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
363 /* 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
364 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
365 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
366 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
367
607
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
368 pattern->paint = paint;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
369 pattern->asso_img = ge_img;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
370
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
371 return pattern;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
372
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
373 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
374 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
375 if(pattern) free(pattern);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
376 if(paint != VG_INVALID_HANDLE) vgDestroyPaint(paint);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
377 vgDestroyImage(vg_img);
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
378 return NULL;
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
379 }
51dc49fd34a8 Create pattern from an image
Thinker K.F. Li <thinker@branda.to>
parents: 606
diff changeset
380
600
20b396c09c23 Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents: 598
diff changeset
381 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
382 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
383 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
384 _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
385 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
386 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
387 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
388
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
389 void
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
390 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
391 co_aix rev[6];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
392
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
393 compute_reverse(mtx, rev);
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
394 ptn->mtx[0] = rev[0];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
395 ptn->mtx[1] = rev[3];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
396 ptn->mtx[2] = 0;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
397 ptn->mtx[3] = rev[1];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
398 ptn->mtx[4] = rev[4];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
399 ptn->mtx[5] = 0;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
400 ptn->mtx[6] = rev[2];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
401 ptn->mtx[7] = rev[5];
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
402 ptn->mtx[8] = 1;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
403 }
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
404
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
405 void
600
20b396c09c23 Integrate pattern source with paint model of canvas
Thinker K.F. Li <thinker@branda.to>
parents: 598
diff changeset
406 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
407 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
408 VGPaint paint;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
409 VGuint color;
1087
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
410 VGfloat rgba[4];
598
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
411
1088
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
412 paint = canvas->paint;
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
413 if(paint == VG_INVALID_HANDLE || canvas->src != NULL) {
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
414 /* previous one is not a color paint */
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
415 if(canvas->src) {
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
416 mbe_pattern_destroy(canvas->src);
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
417 canvas->src = NULL;
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
418 }
7f4dd130a78e Fix issue of color paints that do not show right color.
Thinker K.F. Li <thinker@codemud.net>
parents: 1087
diff changeset
419
598
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
420 paint = vgCreatePaint();
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
421 ASSERT(paint != VG_INVALID_HANDLE);
1087
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
422 vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
598
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
423 canvas->paint = paint;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
424 }
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
425
1087
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
426 rgba[0] = r;
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
427 rgba[1] = g;
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
428 rgba[2] = b;
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
429 rgba[3] = a;
cd34de1a6960 Fix issue of incorrect color for color paint.
Thinker K.F. Li <thinker@codemud.net>
parents: 1086
diff changeset
430 vgSetParameterfv(paint, VG_PAINT_COLOR, 4, rgba);
598
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
431 canvas->paint_installed = 0;
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
432 }
aba62eb9362d define color source for VG
Thinker K.F. Li <thinker@branda.to>
parents: 597
diff changeset
433
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
434 void
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
435 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
436 static VGint *scissors = NULL;
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
437 static int n_scissors = 0;
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
438 VGint *coord;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
439 area_t *area;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
440 int i;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
441
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
442 _MK_CURRENT_CTX(canvas);
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
443
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
444 if(n_areas > n_scissors) {
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
445 if(scissors) free(scissors);
604
38514a7c6b26 Linear gradient for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 600
diff changeset
446 n_scissors = (n_areas + 0xf) & ~0xf;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
447 scissors = (VGint *)malloc(sizeof(VGint) * n_scissors * 4);
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
448 ASSERT(scissors != NULL);
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
449 }
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
450
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
451 coord = scissors;
588
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
452 for(i = 0; i < n_areas; i++) {
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
453 area = areas[i];
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
454 *coord++ = area->x;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
455 *coord++ = area->y;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
456 *coord++ = area->w;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
457 *coord++ = area->h;
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
458 }
e9923024f65e Implement mbe_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 584
diff changeset
459
616
7d70a811829b mbe_fill_preserve() and mbe_reset_scissoring() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 614
diff changeset
460 vgSeti(VG_SCISSORING, VG_TRUE);
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
461 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
462 }
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
463
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 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
465 _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
466 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
467 EGLDisplay display;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
468 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
469 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
470 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
471 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
472 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
473
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 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
475 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
476 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
477 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
478 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
479 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
480 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
481 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
482 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
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 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
485
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 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
487 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
488 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
489 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
490 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
491 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
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_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
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++] = 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
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_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
501 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
502 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
503 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
504
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 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
506 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
507 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
508 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
509 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
510 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
511 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
512 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
513
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 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
515 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
516 }
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
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_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
519 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
520 #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
521 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
522 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
523 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
524 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
525 #endif
630
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
526
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
527 attrib_list[i++] = EGL_RENDERABLE_TYPE;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
528 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
529
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 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
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 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
533 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
534 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
535 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
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 *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
538
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 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
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
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 #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
543 /*! \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
544 *
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 * 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
546 */
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 mbe_surface_t *
1110
851a062368bd Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents: 1088
diff changeset
548 mbe_win_surface_create(void *display, void *drawable,
851a062368bd Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents: 1088
diff changeset
549 int fmt, 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
550 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
551 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
552 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
553 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
554 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
555 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
556
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 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
558 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
559 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
560
1110
851a062368bd Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents: 1088
diff changeset
561 egl_disp = eglGetDisplay((Display *)display);
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
562 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
563 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
564
1110
851a062368bd Change signature of mbe_win_surface_create() by using format argument
Thinker K.F. Li <thinker@codemud.net>
parents: 1088
diff changeset
565 egl_surface = eglCreateWindowSurface(egl_disp, config,
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
566 (EGLNativeWindowType)drawable,
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
567 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
568
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
569 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
570 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
571 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
572 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
573 }
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
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 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
576 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
577 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
578 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
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 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
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
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 #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
584
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
585 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
586 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
587 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
588 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
589 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
590 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
591 _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
592 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
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
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 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
597 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
598 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
599
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
600 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
601 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
602 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
603
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
604 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
605 /* 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
606 * 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
607 *
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
608 * 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
609 */
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
610 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
611 (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
612 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
613 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
614 _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
615 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
616 }
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
617
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
618 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
619 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
620 _free_vgimage(ge_img);
591
71df2896877c build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents: 590
diff changeset
621 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
622 return NULL;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
623 }
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
624 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
625 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
626 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
627 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
628 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
629 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
630
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
631 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
632 }
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
1077
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
634 mbe_surface_t *
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
635 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
636 mb_img_fmt_t fmt,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
637 int width, int height,
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
638 int stride) {
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
639 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
640 return NULL;
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
641 }
e224f496e6b8 Add missed functions for openvg
Thinker K.F. Li <thinker@codemud.net>
parents: 630
diff changeset
642
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
643 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
644 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
645 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
646
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
647 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
648 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
649
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
650 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
651 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
652
619
7020ed3c3e37 Actiavte a VGImage before using a pattern paint or image surface.
Thinker K.F. Li <thinker@branda.to>
parents: 618
diff changeset
653 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
654 _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
655
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
656 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
657 }
35a67a837a53 Use reference count to trace life of _ge_openvg_img_t objects
Thinker K.F. Li <thinker@branda.to>
parents: 616
diff changeset
658
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
659 void
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
660 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
661 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
662 EGLDisplay display;
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
663
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
664 ASSERT(src_canvas->tgt->asso_img != NULL);
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
665
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
666 _MK_CURRENT_CTX(dst_canvas);
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
667
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
668 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
669 vgLoadIdentity();
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
670
1082
af74a96e6624 Fix bug of access VGImage of a surface
Thinker K.F. Li <thinker@codemud.net>
parents: 1081
diff changeset
671 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
672 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
673
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
674 display = _VG_DISPLAY();
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
675 eglSwapBuffers(display, VG_MBE_EGLSURFACE(dst_canvas));
622
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
676 }
39bd74da7f92 mbe_copy_source() for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 619
diff changeset
677
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
678 void
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
679 mbe_flush(mbe_t *canvas) {
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
680 EGLDisplay display;
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
681 EGLSurface *egl_surface;
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
682
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
683 _MK_CURRENT_CTX(canvas);
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
684 display = _VG_DISPLAY();
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
685 egl_surface = VG_MBE_EGLSURFACE(canvas);
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
686 eglSwapBuffers(display, egl_surface);
1114
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
687 }
7451af5d63ec Make tank and calculator works for console backend
Thinker K.F. Li <thinker@codemud.net>
parents: 1110
diff changeset
688
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
689 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
690 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
691 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
692 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
693 EGLContext ctx, shared;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
694 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
695 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
696 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
697 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
698 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
699
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
700 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
701
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
702 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
703 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
704 return NULL;
394d7d4c0673 Fix issue that tank does not update window with OpenVG.
Thinker K.F. Li <thinker@codemud.net>
parents: 1077
diff changeset
705
1081
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
706 /* 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
707 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
708 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
709 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
710 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
711
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
712 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
713 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
714 if(path == VG_INVALID_HANDLE) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
715 eglDestroyContext(display, ctx);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
716 return NULL;
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
717 }
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
718
605
a8fa4c550fe5 use O_ALLOC() to make code clear
Thinker K.F. Li <thinker@branda.to>
parents: 604
diff changeset
719 canvas = O_ALLOC(mbe_t);
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
720 if(canvas == NULL) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
721 eglDestroyContext(display, ctx);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
722 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
723 return NULL;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
724 }
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
d733e198bb25 Move functions from mb_graph_engine_openvg.h to the C file
Thinker K.F. Li <thinker@branda.to>
parents: 588
diff changeset
726 canvas->src = NULL;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
727 canvas->paint = VG_INVALID_HANDLE;
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
728 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
729 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
730 canvas->ctx = ctx;
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
731 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
732
14c2bdcbbcca Make an association between mbe and surface for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1080
diff changeset
733 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
734
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
735 /* 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
736 _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
737 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
738
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 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
740 }
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
741
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
742 void
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
743 mbe_destroy(mbe_t *canvas) {
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
744 EGLDisplay display;
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
745
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
746 display = _VG_DISPLAY();
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 vgDestroyPath(canvas->path);
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
749 eglDestroyContext(display, canvas->ctx);
591
71df2896877c build graph_engine_openvg.c in makefile
Thinker K.F. Li <thinker@branda.to>
parents: 590
diff changeset
750 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
751 free(canvas);
590
b714f0c9992e include a VGPath in VG canvas
Thinker K.F. Li <thinker@branda.to>
parents: 589
diff changeset
752 }
593
ac942664fe86 stroke and fill for VG
Thinker K.F. Li <thinker@branda.to>
parents: 592
diff changeset
753
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
754 void
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
755 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
756 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
757 EGLDisplay display;
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
758 EGLSurface *egl_surface;
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
759 EGLint w, h;
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
760 EGLBoolean r;
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
761
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
762 _MK_CURRENT_CTX(canvas);
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
763
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
764 display = _VG_DISPLAY();
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
765
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
766 egl_surface = VG_MBE_EGLSURFACE(canvas);
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
767 r = eglQuerySurface(display, egl_surface, EGL_WIDTH, &w);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
768 ASSERT(r == EGL_TRUE);
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
769 r = eglQuerySurface(display, egl_surface, EGL_HEIGHT, &h);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
770 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
771
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
772 /* 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
773 #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
774 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
775 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
776 #endif
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
777
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
778 mbe_paint(canvas);
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
779
629
608f58b9b84d Use color transform and make compatible with OpenVG 1.0.
Thinker K.F. Li <thinker@branda.to>
parents: 627
diff changeset
780 #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
781 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
782 #endif
608
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
783 }
6c74bc371e37 paint with alpha for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 607
diff changeset
784
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
785 void
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
786 mbe_paint(mbe_t *canvas) {
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
787 EGLDisplay display;
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
788 EGLSurface *egl_surface;
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
789 EGLint w, h;
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
790 EGLBoolean r;
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
791 VGPath path;
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
792
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
793 _MK_CURRENT_CTX(canvas);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
794 _MK_CURRENT_PAINT(canvas);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
795 if(canvas->src)
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
796 _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
797 VG_MATRIX_FILL_PAINT_TO_USER);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
798
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
799 display = _VG_DISPLAY();
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
800
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
801 egl_surface = VG_MBE_EGLSURFACE(canvas);
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
802 r = eglQuerySurface(display, egl_surface, EGL_WIDTH, &w);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
803 ASSERT(r == EGL_TRUE);
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
804 r = eglQuerySurface(display, egl_surface, EGL_HEIGHT, &h);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
805 ASSERT(r == EGL_TRUE);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
806
614
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
807 /*
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
808 * 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
809 *
9c5705da2495 Fix the bug of foregting make current context before seting transform
Thinker K.F. Li <thinker@branda.to>
parents: 613
diff changeset
810 * 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
811 * 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
812 * 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
813 */
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
814 vgSeti(VG_SCISSORING, VG_FALSE);
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
815 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
816 vgLoadIdentity();
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
817
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
818 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
819 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
820 vguRect(path, 0, 0, w, h);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
821 vgDrawPath(path, VG_FILL_PATH);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
822 vgDestroyPath(path);
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
823
612
b1d1b6c5af90 Implements setting pattern matrix for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 610
diff changeset
824 /* 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
825 vgLoadMatrix(canvas->mtx);
596
aaab76730beb Define mbe_paint() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 595
diff changeset
826 vgSeti(VG_SCISSORING, VG_TRUE);
595
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
827 }
aaaaa03af04d Set VGPaint for canvas
Thinker K.F. Li <thinker@branda.to>
parents: 593
diff changeset
828
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
829 void
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
830 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
831 EGLDisplay display;
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
832 EGLSurface *egl_surface;
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
833 EGLint w, h;
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
834 EGLBoolean r;
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
835
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
836 _MK_CURRENT_CTX(canvas);
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
837
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
838 display = _VG_DISPLAY();
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
839
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
840 egl_surface = VG_MBE_EGLSURFACE(canvas);
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
841 r = eglQuerySurface(display, egl_surface, EGL_WIDTH, &w);
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
842 ASSERT(r == EGL_TRUE);
1127
baf4c4d48cff Fix issue of passing EGLSurface with mbe_surface_t for OpenVG
Thinker K.F. Li <thinker@codemud.net>
parents: 1126
diff changeset
843 r = eglQuerySurface(display, egl_surface, EGL_HEIGHT, &h);
613
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
844 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
845
6a0be737a3f3 mbe_clear() use vgClear() to clear regions for OpenVG
Thinker K.F. Li <thinker@branda.to>
parents: 612
diff changeset
846 /* 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
847 vgClear(0, 0, w, h);
597
3300992b29ff Define mbe_clear() for VG
Thinker K.F. Li <thinker@branda.to>
parents: 596
diff changeset
848 }
630
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
849
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
850 void mbe_init() {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
851 static EGLSurface init_surf;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
852 EGLDisplay display;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
853 EGLConfig config;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
854 EGLint nconfigs;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
855 EGLint attrib_list[] = {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
856 EGL_RED_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
857 EGL_GREEN_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
858 EGL_BLUE_SIZE, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
859 EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
860 EGL_NONE};
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
861 EGLint surf_attribs[] = {
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
862 EGL_WIDTH, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
863 EGL_HEIGHT, 1,
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
864 EGL_NONE};
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
865 EGLBoolean r;
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
866
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
867 display = _VG_DISPLAY();
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
868 eglInitialize(display, NULL, NULL);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
869
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
870 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
871 ASSERT(r);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
872
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
873 eglBindAPI(EGL_OPENVG_API);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
874
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
875 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
876 ASSERT(init_ctx != EGL_NO_CONTEXT);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
877
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
878 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
879 ASSERT(init_surf != EGL_NO_SURFACE);
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
880
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
881 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
882 }
bd18951b51d5 Add initial code for graphic engines
Thinker K.F. Li <thinker@branda.to>
parents: 629
diff changeset
883