Mercurial > MadButterfly
diff 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 |
line wrap: on
line diff
--- a/src/graph_engine_openvg.c Thu Jul 08 13:51:47 2010 +0800 +++ b/src/graph_engine_openvg.c Thu Jul 08 18:44:26 2010 +0800 @@ -80,8 +80,8 @@ } ge_img->ref = 1; ge_img->img = vg_img; - ge_img->asso_pattern = NULL; - ge_img->asso_surface = NULL; + ge_img->activated_for = NULL; + ge_img->deactivate_func = NULL; return ge_img; } @@ -89,12 +89,89 @@ /*! \brief Free image object for OpenVG */ static void _free_vgimage(_ge_openvg_img_t *ge_img) { - if(--ge_img->ref > 0) + if(--ge_img->ref > 0) { + if(ge_img->activated_for) { + ge_img->deactivate_func(ge_img->activated_for); + ge_img->activated_for = NULL; + } return; + } + vgDestroyImage(ge_img->img); free(ge_img); } +static void +_ge_vg_img_deactivate_for_pattern(void *obj) { + mbe_pattern_t *ptn = (mbe_pattern_t *)obj; + VGPaint vg_paint; + + vg_paint = ptn->paint; + vgPaintPattern(vg_paint, VG_INVALID_HANDLE); +} + +/*! \brief Activate a VGImage for a pattern paint. + * + * \sa _ge_openvg_img + */ +void +_ge_vg_img_activate_for_pattern(mbe_pattern_t *ptn) { + _ge_openvg_img_t *ge_img; + VGPaint vg_paint; + VGImage vg_img; + + ge_img = ptn->asso_img; + if(ge_img == NULL) + return; + + if(ge_img->activated_for == (void *)ptn) + return; + + if(ge_img->activated_for) + ge_img->deactivate_func(ge_img->activated_for); + + ge_img->activated_for = ptn; + ge_img->deactivate_func = _ge_vg_img_deactivate_for_pattern; + + vg_img = ge_img->img; + vg_paint = ptn->paint; + + vgPaintPattern(vg_paint, vg_img); +} + +/*! \brief Deactivate a VGImage for a VGSurface. + * + * A VGImage can not deatached from VGSurface. But, it is not clear + * in the document of EGL. We assume that a VGImage can be used as + * pattern of a paint, once associated surface is not current + * rendering context. + */ +static void +_ge_vg_img_deactivate_for_surface(void *obj) { +} + +/*! \brief Activate a VGImage for a surface + * + * \sa _ge_openvg_img + */ +void +_ge_vg_img_activate_for_surface(mbe_surface_t *surf) { + _ge_openvg_img_t *ge_img; + + ge_img = surf->asso_img; + if(ge_img == NULL) + return; + + if(ge_img->activated_for == (void *)surf) + return; + + if(ge_img->activated_for) + ge_img->deactivate_func(ge_img->activated_for); + + ge_img->activated_for = surf; + ge_img->deactivate_func = _ge_vg_img_deactivate_for_surface; +} + /* * This implementation supports only from image surface. */ @@ -263,8 +340,10 @@ void mbe_pattern_destroy(mbe_pattern_t *ptn) { - if(ptn->asso_img) { - } + if(ptn->asso_img) + _free_vgimage(ptn->asso_img); + vgDestroyPaint(ptn->paint); + free(ptn); } void @@ -498,6 +577,7 @@ } surface->surface = egl_surface; + surface->asso_img = NULL; return surface; } @@ -565,10 +645,8 @@ if(surface->asso_mbe) surface->asso_mbe->tgt = NULL; - if(surface->asso_img) { - surface->asso_img->asso_surface = NULL; + if(surface->asso_img) _free_vgimage(surface->asso_img); - } free(surface); }