comparison src/graph_engine_openvg.c @ 619:7020ed3c3e37 openvg

Actiavte a VGImage before using a pattern paint or image surface. - A VGImage can only activated for a pattern or an image in any instance. - _ge_openvg_img trace the object activated for currently and its deactivation function. - everytime a pattern paint or image surface will be used, the current activated one will be deactivated, and activate a new one.
author Thinker K.F. Li <thinker@branda.to>
date Thu, 08 Jul 2010 18:44:26 +0800
parents 35a67a837a53
children 39bd74da7f92
comparison
equal deleted inserted replaced
618:35a67a837a53 619:7020ed3c3e37
78 vgDestroyImage(vg_img); 78 vgDestroyImage(vg_img);
79 return NULL; 79 return NULL;
80 } 80 }
81 ge_img->ref = 1; 81 ge_img->ref = 1;
82 ge_img->img = vg_img; 82 ge_img->img = vg_img;
83 ge_img->asso_pattern = NULL; 83 ge_img->activated_for = NULL;
84 ge_img->asso_surface = NULL; 84 ge_img->deactivate_func = NULL;
85 85
86 return ge_img; 86 return ge_img;
87 } 87 }
88 88
89 /*! \brief Free image object for OpenVG */ 89 /*! \brief Free image object for OpenVG */
90 static void 90 static void
91 _free_vgimage(_ge_openvg_img_t *ge_img) { 91 _free_vgimage(_ge_openvg_img_t *ge_img) {
92 if(--ge_img->ref > 0) 92 if(--ge_img->ref > 0) {
93 if(ge_img->activated_for) {
94 ge_img->deactivate_func(ge_img->activated_for);
95 ge_img->activated_for = NULL;
96 }
93 return; 97 return;
98 }
99
94 vgDestroyImage(ge_img->img); 100 vgDestroyImage(ge_img->img);
95 free(ge_img); 101 free(ge_img);
102 }
103
104 static void
105 _ge_vg_img_deactivate_for_pattern(void *obj) {
106 mbe_pattern_t *ptn = (mbe_pattern_t *)obj;
107 VGPaint vg_paint;
108
109 vg_paint = ptn->paint;
110 vgPaintPattern(vg_paint, VG_INVALID_HANDLE);
111 }
112
113 /*! \brief Activate a VGImage for a pattern paint.
114 *
115 * \sa _ge_openvg_img
116 */
117 void
118 _ge_vg_img_activate_for_pattern(mbe_pattern_t *ptn) {
119 _ge_openvg_img_t *ge_img;
120 VGPaint vg_paint;
121 VGImage vg_img;
122
123 ge_img = ptn->asso_img;
124 if(ge_img == NULL)
125 return;
126
127 if(ge_img->activated_for == (void *)ptn)
128 return;
129
130 if(ge_img->activated_for)
131 ge_img->deactivate_func(ge_img->activated_for);
132
133 ge_img->activated_for = ptn;
134 ge_img->deactivate_func = _ge_vg_img_deactivate_for_pattern;
135
136 vg_img = ge_img->img;
137 vg_paint = ptn->paint;
138
139 vgPaintPattern(vg_paint, vg_img);
140 }
141
142 /*! \brief Deactivate a VGImage for a VGSurface.
143 *
144 * A VGImage can not deatached from VGSurface. But, it is not clear
145 * in the document of EGL. We assume that a VGImage can be used as
146 * pattern of a paint, once associated surface is not current
147 * rendering context.
148 */
149 static void
150 _ge_vg_img_deactivate_for_surface(void *obj) {
151 }
152
153 /*! \brief Activate a VGImage for a surface
154 *
155 * \sa _ge_openvg_img
156 */
157 void
158 _ge_vg_img_activate_for_surface(mbe_surface_t *surf) {
159 _ge_openvg_img_t *ge_img;
160
161 ge_img = surf->asso_img;
162 if(ge_img == NULL)
163 return;
164
165 if(ge_img->activated_for == (void *)surf)
166 return;
167
168 if(ge_img->activated_for)
169 ge_img->deactivate_func(ge_img->activated_for);
170
171 ge_img->activated_for = surf;
172 ge_img->deactivate_func = _ge_vg_img_deactivate_for_surface;
96 } 173 }
97 174
98 /* 175 /*
99 * This implementation supports only from image surface. 176 * This implementation supports only from image surface.
100 */ 177 */
261 return NULL; 338 return NULL;
262 } 339 }
263 340
264 void 341 void
265 mbe_pattern_destroy(mbe_pattern_t *ptn) { 342 mbe_pattern_destroy(mbe_pattern_t *ptn) {
266 if(ptn->asso_img) { 343 if(ptn->asso_img)
267 } 344 _free_vgimage(ptn->asso_img);
345 vgDestroyPaint(ptn->paint);
346 free(ptn);
268 } 347 }
269 348
270 void 349 void
271 mbe_pattern_set_matrix(mbe_pattern_t *ptn, co_aix *mtx) { 350 mbe_pattern_set_matrix(mbe_pattern_t *ptn, co_aix *mtx) {
272 co_aix rev[6]; 351 co_aix rev[6];
496 eglDestroySurface(egl_disp, egl_surface); 575 eglDestroySurface(egl_disp, egl_surface);
497 return NULL; 576 return NULL;
498 } 577 }
499 578
500 surface->surface = egl_surface; 579 surface->surface = egl_surface;
580 surface->asso_img = NULL;
501 581
502 return surface; 582 return surface;
503 } 583 }
504 584
505 #endif 585 #endif
563 eglDestroySurface(display, surface->surface); 643 eglDestroySurface(display, surface->surface);
564 644
565 if(surface->asso_mbe) 645 if(surface->asso_mbe)
566 surface->asso_mbe->tgt = NULL; 646 surface->asso_mbe->tgt = NULL;
567 647
568 if(surface->asso_img) { 648 if(surface->asso_img)
569 surface->asso_img->asso_surface = NULL;
570 _free_vgimage(surface->asso_img); 649 _free_vgimage(surface->asso_img);
571 }
572 650
573 free(surface); 651 free(surface);
574 } 652 }
575 653
576 mbe_t * 654 mbe_t *