mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
add vgcanvas_clear_cache
This commit is contained in:
parent
f3f45018d4
commit
6a58d3b508
@ -21,6 +21,7 @@ namespace agge
|
||||
iterator push_back(const T &element);
|
||||
void pop_back();
|
||||
void clear();
|
||||
void clear_cache();
|
||||
void resize(count_t size);
|
||||
void set_end(iterator end);
|
||||
void assign(count_t size, const T &value);
|
||||
@ -75,7 +76,18 @@ namespace agge
|
||||
|
||||
template <typename T>
|
||||
inline pod_vector<T>::~pod_vector()
|
||||
{ delete []_begin; }
|
||||
{ clear_cache(); }
|
||||
|
||||
template <typename T>
|
||||
inline void pod_vector<T>::clear_cache()
|
||||
{
|
||||
if (_begin != 0) {
|
||||
delete []_begin;
|
||||
}
|
||||
_end = 0;
|
||||
_begin = 0;
|
||||
_limit = 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline typename pod_vector<T>::iterator pod_vector<T>::push_back(const T &element)
|
||||
@ -175,7 +187,9 @@ namespace agge
|
||||
|
||||
for (iterator i = _begin; i != _end; )
|
||||
*p++ = *i++;
|
||||
delete []_begin;
|
||||
if (_begin != 0) {
|
||||
delete []_begin;
|
||||
}
|
||||
_begin = buffer;
|
||||
_end = _begin + size;
|
||||
_limit = _begin + new_capacity;
|
||||
|
@ -19,6 +19,7 @@ namespace agge
|
||||
public:
|
||||
using vector_rasterizer::reset;
|
||||
|
||||
void clear_cache();
|
||||
void reset_clipping();
|
||||
void set_clipping(const rect<real_t> &window);
|
||||
|
||||
@ -77,6 +78,10 @@ namespace agge
|
||||
inline void rasterizer<ClipperT, ScalingT>::reset_clipping()
|
||||
{ _clipper.reset(); }
|
||||
|
||||
template <typename ClipperT, typename ScalingT>
|
||||
inline void rasterizer<ClipperT, ScalingT>::clear_cache()
|
||||
{ vector_rasterizer::clear_cache(); }
|
||||
|
||||
template <typename ClipperT, typename ScalingT>
|
||||
inline void rasterizer<ClipperT, ScalingT>::set_clipping(const rect<real_t> &window)
|
||||
{
|
||||
|
@ -36,6 +36,7 @@ namespace agge
|
||||
vector_rasterizer();
|
||||
|
||||
void reset();
|
||||
void clear_cache();
|
||||
|
||||
void line(int x1, int y1, int x2, int y2);
|
||||
void append(const vector_rasterizer &source, int dx, int dy);
|
||||
@ -77,6 +78,9 @@ namespace agge
|
||||
inline bool vector_rasterizer::empty() const
|
||||
{ return _min_y > _max_y; }
|
||||
|
||||
inline void vector_rasterizer::clear_cache()
|
||||
{ _cells.clear_cache(); }
|
||||
|
||||
inline bool vector_rasterizer::sorted() const
|
||||
{ return !!_sorted; }
|
||||
|
||||
|
@ -110,6 +110,22 @@ static void aggenvg__setLineCap(void* uptr, int lineCap)
|
||||
agge->line_style.set_cap(agge::caps::square());
|
||||
}
|
||||
|
||||
static void aggenvg__clearCacheTexture(AGGENVGcontext* agge) {
|
||||
AGGENVGtexture* textures = NULL;
|
||||
int ntextures = agge->ntextures;
|
||||
int size = sizeof(AGGENVGtexture) * ntextures;
|
||||
|
||||
if (agge->textures != NULL && ntextures > 0) {
|
||||
textures = (AGGENVGtexture*)malloc(size);
|
||||
memcpy(textures, agge->textures, size);
|
||||
|
||||
free(agge->textures);
|
||||
agge->textures = textures;
|
||||
agge->ntextures = ntextures;
|
||||
agge->ctextures = ntextures;
|
||||
}
|
||||
}
|
||||
|
||||
static AGGENVGtexture* aggenvg__allocTexture(AGGENVGcontext* agge) {
|
||||
int i;
|
||||
AGGENVGtexture* tex = NULL;
|
||||
@ -414,6 +430,15 @@ static void aggenvg__renderDelete(void* uptr) {
|
||||
delete agge;
|
||||
}
|
||||
|
||||
static int aggenvg__clearCache(void* uptr) {
|
||||
AGGENVGcontext* agge = (AGGENVGcontext*)uptr;
|
||||
if (agge == NULL) return -1;
|
||||
agge::rasterizer<agge::clipper<int> >& ras = agge->ras;
|
||||
ras.clear_cache();
|
||||
aggenvg__clearCacheTexture(agge);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void nvgInitAGGE(AGGENVGcontext* agge, NVGparams* params, uint32_t w, uint32_t h, uint32_t stride,
|
||||
enum NVGtexture format, uint8_t* data) {
|
||||
agge->w = w;
|
||||
@ -489,6 +514,7 @@ NVGcontext* nvgCreateAGGE(uint32_t w, uint32_t h, uint32_t stride, enum NVGtextu
|
||||
params.renderCancel = aggenvg__renderCancel;
|
||||
params.renderFlush = aggenvg__renderFlush;
|
||||
params.renderDelete = aggenvg__renderDelete;
|
||||
params.clearCache = aggenvg__clearCache;
|
||||
params.userPtr = agge;
|
||||
params.edgeAntiAlias = 1;
|
||||
|
||||
|
@ -2502,6 +2502,13 @@ void nvgCircle(NVGcontext* ctx, float cx, float cy, float r)
|
||||
nvgEllipse(ctx, cx,cy, r,r);
|
||||
}
|
||||
|
||||
int nvgClearCache(NVGcontext* ctx) {
|
||||
if(ctx->params.clearCache != NULL) {
|
||||
ctx->params.clearCache(ctx->params.userPtr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WITH_NANOVG_GPU
|
||||
void nvgDebugDumpPathCache(NVGcontext* ctx)
|
||||
{
|
||||
|
@ -699,6 +699,7 @@ struct NVGparams {
|
||||
void (*setLineCap)(void* uptr, int lineCap);
|
||||
void (*setLineJoin)(void* uptr, int lineJoin);
|
||||
|
||||
int (*clearCache)(void* uptr);
|
||||
int (*renderCreate)(void* uptr);
|
||||
int (*findTexture)(void* uptr, const void* data);
|
||||
void (*setStateXfrom)(void* uptr, float* xform);
|
||||
@ -736,6 +737,8 @@ int nvgCreateImageRaw(NVGcontext* ctx, int w, int h, int format, int stride, int
|
||||
|
||||
int nvgFindTextureRaw(NVGcontext* ctx, const void* data);
|
||||
|
||||
int nvgClearCache(NVGcontext* ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -3,7 +3,8 @@
|
||||
* 2020/08/06
|
||||
* 完善离线 lcd(感谢智明提供补丁)。
|
||||
* 完善 slist (感谢智明提供补丁)。
|
||||
|
||||
* 增加 vgcanvas_clear_cache(感谢智明提供补丁)。
|
||||
|
||||
* 2020/08/04
|
||||
* 完善 keyboard 增加 back/back_to_home 按钮的支持。
|
||||
* edit/mledit/slider 支持 WIDGET_PROP_INPUTING 属性,用于辅助实现 MVVM。
|
||||
|
@ -518,3 +518,10 @@ ret_t vgcanvas_get_text_metrics(vgcanvas_t* vg, float_t* ascent, float_t* descen
|
||||
|
||||
return vg->vt->get_text_metrics(vg, ascent, descent, line_hight);
|
||||
}
|
||||
|
||||
ret_t vgcanvas_clear_cache(vgcanvas_t* vg) {
|
||||
return_value_if_fail(vg != NULL && vg->vt != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(vg->vt->clear_cache != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return vg->vt->clear_cache(vg);
|
||||
}
|
||||
|
@ -137,6 +137,8 @@ typedef ret_t (*vgcanvas_unbind_fbo_t)(vgcanvas_t* vg, framebuffer_object_t* fbo
|
||||
typedef ret_t (*vgcanvas_nanovg_fbo_to_bitmap_t)(vgcanvas_t* vgcanvas, framebuffer_object_t* fbo,
|
||||
bitmap_t* img, rect_t* r);
|
||||
|
||||
typedef ret_t (*vgcanvas_clear_cache_t)(vgcanvas_t* vg);
|
||||
|
||||
typedef ret_t (*vgcanvas_destroy_t)(vgcanvas_t* vg);
|
||||
|
||||
typedef struct _vgcanvas_vtable_t {
|
||||
@ -206,6 +208,8 @@ typedef struct _vgcanvas_vtable_t {
|
||||
vgcanvas_unbind_fbo_t unbind_fbo;
|
||||
vgcanvas_nanovg_fbo_to_bitmap_t fbo_to_bitmap;
|
||||
|
||||
vgcanvas_clear_cache_t clear_cache;
|
||||
|
||||
vgcanvas_destroy_t destroy;
|
||||
} vgcanvas_vtable_t;
|
||||
|
||||
@ -1186,6 +1190,15 @@ wh_t vgcanvas_get_width(vgcanvas_t* vgcanvas);
|
||||
*/
|
||||
wh_t vgcanvas_get_height(vgcanvas_t* vgcanvas);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_clear_cache
|
||||
* 释放vgcanvas对象的缓冲数据。
|
||||
* @param {vgcanvas_t*} vg vgcanvas对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t vgcanvas_clear_cache(vgcanvas_t* vg);
|
||||
|
||||
/**
|
||||
* @method vgcanvas_destroy
|
||||
* 销毁vgcanvas对象。
|
||||
|
@ -599,6 +599,14 @@ static ret_t vgcanvas_nanovg_restore(vgcanvas_t* vgcanvas) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t vgcanvas_nanovg_clear_cache(vgcanvas_t* vgcanvas) {
|
||||
NVGcontext* vg = ((vgcanvas_nanovg_t*)vgcanvas)->vg;
|
||||
|
||||
nvgClearCache(vg);
|
||||
nvgDeleteFontByName(vg, NULL);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static const vgcanvas_vtable_t vt = {
|
||||
.reinit = vgcanvas_nanovg_reinit,
|
||||
.begin_frame = vgcanvas_nanovg_begin_frame,
|
||||
@ -655,4 +663,5 @@ static const vgcanvas_vtable_t vt = {
|
||||
.destroy_fbo = vgcanvas_nanovg_destroy_fbo,
|
||||
.unbind_fbo = vgcanvas_nanovg_unbind_fbo,
|
||||
.fbo_to_bitmap = vgcanvas_nanovg_fbo_to_bitmap,
|
||||
.clear_cache = vgcanvas_nanovg_clear_cache,
|
||||
.destroy = vgcanvas_nanovg_destroy};
|
||||
|
Loading…
Reference in New Issue
Block a user