diff --git a/awtk_config.py b/awtk_config.py index 55db49a202..73fa5689a0 100644 --- a/awtk_config.py +++ b/awtk_config.py @@ -43,7 +43,7 @@ INPUT_ENGINE = complie_helper.get_value('INPUT_ENGINE', INPUT_ENGINE) VGCANVAS = 'NANOVG' -# VGCANVAS='NANOVG_PLUS' +VGCANVAS='NANOVG_PLUS' # VGCANVAS='CAIRO' VGCANVAS = complie_helper.get_value('VGCANVAS', VGCANVAS) diff --git a/docs/changes.md b/docs/changes.md index bf4ea716a9..7a4e86211b 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -6,6 +6,7 @@ * 完善object_array(感谢兆坤提供补丁) * 完善tk_atob(感谢兆坤提供补丁) * 统一是否可从名字中获取index的判断逻辑(感谢兆坤提供补丁) + * 完善nanovg_plus,设置为默认渲染引擎(感谢智明提供补丁) 2024/11/06 * 完善编译脚本。 diff --git a/src/vgcanvas/vgcanvas_nanovg_gl_common.inc b/src/vgcanvas/vgcanvas_nanovg_gl_common.inc index 6a501335a5..4df9767bc8 100644 --- a/src/vgcanvas/vgcanvas_nanovg_gl_common.inc +++ b/src/vgcanvas/vgcanvas_nanovg_gl_common.inc @@ -24,6 +24,7 @@ #endif #include "base/system_info.h" +#include "base/vgcanvas_asset_manager.h" #if defined(WITH_NANOVG_GL3) #define NANOVG_GL3_IMPLEMENTATION @@ -41,7 +42,12 @@ #define NANOVG_GLES3_IMPLEMENTATION #endif +#ifdef WITH_NANOVG_PLUS_GPU +#include "nanovg_plus.h" +#else #include "nanovg.h" +#endif + #include "tkc/utf8.h" #include "tkc/mem.h" #include "base/opengl.h" @@ -49,23 +55,36 @@ #include "base/image_manager.h" #include "base/native_window.h" +#ifdef WITH_NANOVG_PLUS_GPU +#include "nanovg_plus_gl.h" +#define vgcanvas_nanovg_init vgcanvas_nanovg_plus_init +#else #include "nanovg_gl.h" #include "nanovg_gl_utils.h" +#endif typedef struct _vgcanvas_nanovg_t { vgcanvas_t base; int font_id; +#ifdef WITH_NANOVG_PLUS_GPU + nvgp_context_t* vg; +#else NVGcontext* vg; +#endif uint32_t text_align_v; uint32_t text_align_h; native_window_t* window; } vgcanvas_nanovg_t; +#ifdef WITH_NANOVG_PLUS_GPU +#include "vgcanvas_nanovg_plus.h" +#else #include "texture.inc" #include "vgcanvas_nanovg_gl.inc" #include "vgcanvas_asset_manager_nanovg.inc" +#endif vgcanvas_t* VGCANVAS_CREATE_GL(uint32_t w, uint32_t h, uint32_t stride, bitmap_format_t format, void* win) { @@ -79,15 +98,22 @@ vgcanvas_t* VGCANVAS_CREATE_GL(uint32_t w, uint32_t h, uint32_t stride, bitmap_f nanovg->base.w = w; nanovg->base.h = h; - nanovg->base.vt = &vt; nanovg->window = window; nanovg->base.ratio = info.ratio; +#if defined(WITH_NANOVG_PLUS_GPU) + nanovg->base.vt = vgcanvas_nanovg_plus_get_vt(); +#else + nanovg->base.vt = &vt; +#endif + vgcanvas_nanovg_init((vgcanvas_t*)nanovg); opengl_init(); -#if defined(WITH_NANOVG_GL2) +#if defined(WITH_NANOVG_PLUS_GPU) + nanovg->vg = nvgp_create(NVGP_MODE_GPU, w, h); +#elif defined(WITH_NANOVG_GL2) nanovg->vg = nvgCreateGL2(NVG_ANTIALIAS | NVG_STENCIL_STROKES); #elif defined(WITH_NANOVG_GL3) nanovg->vg = nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES); @@ -101,8 +127,15 @@ vgcanvas_t* VGCANVAS_CREATE_GL(uint32_t w, uint32_t h, uint32_t stride, bitmap_f assert(!"OpenGL is not supported!"); } +#if defined(WITH_NANOVG_PLUS_GPU) + vgcanvas_asset_manager_add_vg(vgcanvas_asset_manager(), &(nanovg->base), + vgcanvas_asset_manager_nanovg_plus_bitmap_destroy, + vgcanvas_asset_manager_nanovg_plus_font_destroy); +#else vgcanvas_asset_manager_add_vg(vgcanvas_asset_manager(), &(nanovg->base), vgcanvas_asset_manager_nanovg_bitmap_destroy, vgcanvas_asset_manager_nanovg_font_destroy); +#endif + return &(nanovg->base); } diff --git a/src/vgcanvas/vgcanvas_nanovg_plus.c b/src/vgcanvas/vgcanvas_nanovg_plus.c index b8c8bf7384..503173804e 100644 --- a/src/vgcanvas/vgcanvas_nanovg_plus.c +++ b/src/vgcanvas/vgcanvas_nanovg_plus.c @@ -5,6 +5,7 @@ #include "base/image_manager.h" #include "base/native_window.h" +#include "base/opengl.h" #include "nanovg_plus.h" #include "nanovg_plus_gl.h" #include "nanovg_plus_gl_utils.h" @@ -276,7 +277,7 @@ static ret_t vgcanvas_nanovg_plus_destroy(vgcanvas_t* vgcanvas) { return RET_OK; } -static ret_t vgcanvas_asset_manager_nanovg_plus_font_destroy(void* vg, const char* font_name, +ret_t vgcanvas_asset_manager_nanovg_plus_font_destroy(void* vg, const char* font_name, void* specific) { int32_t id = tk_pointer_to_int(specific); vgcanvas_nanovg_plus_t* canvas = (vgcanvas_nanovg_plus_t*)vg; @@ -286,7 +287,7 @@ static ret_t vgcanvas_asset_manager_nanovg_plus_font_destroy(void* vg, const cha return RET_OK; } -static ret_t vgcanvas_asset_manager_nanovg_plus_bitmap_destroy(void* vg, void* specific) { +ret_t vgcanvas_asset_manager_nanovg_plus_bitmap_destroy(void* vg, void* specific) { vgcanvas_nanovg_plus_t* canvas = (vgcanvas_nanovg_plus_t*)vg; vgcanvas_nanovg_plus_gl_texture_t* texture = (vgcanvas_nanovg_plus_gl_texture_t*)specific; if (canvas != NULL && canvas->vg != NULL && texture != NULL) { @@ -320,6 +321,8 @@ vgcanvas_t* vgcanvas_create(uint32_t w, uint32_t h, uint32_t stride, bitmap_form nanovg->base.ratio = info.ratio; vgcanvas_nanovg_plus_init((vgcanvas_t*)nanovg); + + opengl_init(); nanovg->vg = nvgp_create(NVGP_MODE_GPU, w, h); diff --git a/src/vgcanvas/vgcanvas_nanovg_plus.h b/src/vgcanvas/vgcanvas_nanovg_plus.h new file mode 100644 index 0000000000..bca89b36fc --- /dev/null +++ b/src/vgcanvas/vgcanvas_nanovg_plus.h @@ -0,0 +1,8 @@ +#ifndef TK_VGCANVAS_NANOVG_PLUS_H +#define TK_VGCANVAS_NANOVG_PLUS_H +/* internal */ +ret_t vgcanvas_nanovg_plus_init(vgcanvas_t* vgcanvas); +const vgcanvas_vtable_t* vgcanvas_nanovg_plus_get_vt(); +ret_t vgcanvas_asset_manager_nanovg_plus_font_destroy(void* vg, const char* font_name, void* specific); +ret_t vgcanvas_asset_manager_nanovg_plus_bitmap_destroy(void* vg, void* specific); +#endif diff --git a/src/vgcanvas/vgcanvas_nanovg_plus.inc b/src/vgcanvas/vgcanvas_nanovg_plus.inc index a853d2f816..c08144f130 100644 --- a/src/vgcanvas/vgcanvas_nanovg_plus.inc +++ b/src/vgcanvas/vgcanvas_nanovg_plus.inc @@ -40,7 +40,7 @@ static ret_t vgcanvas_nanovg_plus_on_asset_events(void* ctx, event_t* e) { return RET_OK; } -static ret_t vgcanvas_nanovg_plus_init(vgcanvas_t* vgcanvas) { +ret_t vgcanvas_nanovg_plus_init(vgcanvas_t* vgcanvas) { (void)vgcanvas; return RET_OK; } @@ -800,3 +800,7 @@ static const vgcanvas_vtable_t vt = { .fbo_to_bitmap = vgcanvas_nanovg_plus_fbo_to_bitmap, .clear_cache = vgcanvas_nanovg_plus_clear_cache, .destroy = vgcanvas_nanovg_plus_destroy}; + +const vgcanvas_vtable_t* vgcanvas_nanovg_plus_get_vt() { + return &vt; +}