annotate src/graph_engine_openvg.c @ 1086:6723b2537993 openvg

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