diff --git a/3rd/glad/glad.c b/3rd/glad/glad.c index e37f1e339..31144a67f 100644 --- a/3rd/glad/glad.c +++ b/3rd/glad/glad.c @@ -131,11 +131,11 @@ int gladLoadGL(void) { int status = 0; if(open_gl()) { -#ifdef WITH_NANOVG_GLES2 +#ifdef WITH_GPU_GLES2 status = gladLoadGLES2Loader(&get_proc); #else status = gladLoadGLLoader(&get_proc); -#endif/*WITH_NANOVG_GLES2*/ +#endif/*WITH_GPU_GLES2*/ close_gl(); } diff --git a/awtk_config.py b/awtk_config.py index a99b25a3a..4b58aee78 100644 --- a/awtk_config.py +++ b/awtk_config.py @@ -153,7 +153,7 @@ else: COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DWITH_NANOVG_BGFX ' elif NANOVG_BACKEND == 'GLES2': NANOVG_BACKEND_LIBS=['nanovg']; - COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DWITH_NANOVG_GLES2 -DWITH_NANOVG_GL ' + COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DWITH_NANOVG_GLES2 -DWITH_GPU_GLES2 -DWITH_NANOVG_GL ' elif NANOVG_BACKEND == 'GLES3': NANOVG_BACKEND_LIBS=['nanovg']; COMMON_CCFLAGS = COMMON_CCFLAGS + ' -DWITH_NANOVG_GLES3 -DWITH_NANOVG_GL ' diff --git a/docs/changes.md b/docs/changes.md index 57c82d44c..2095a6b0f 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,7 @@ 2021/09/13 * 修改canvas\_draw\_image改成用rectf类型(感谢智明提供补丁) + * 增加宏WITH\_GPU/WITH\_GPU\_GLES2(感谢智明提供补丁) 2021/09/11 * 增加 object\_default\_create\_ex 用于禁止路径访问属性。 diff --git a/src/base/canvas.c b/src/base/canvas.c index 4eb973f1c..615998491 100644 --- a/src/base/canvas.c +++ b/src/base/canvas.c @@ -209,7 +209,7 @@ ret_t canvas_set_clip_rect(canvas_t* c, const rect_t* r_in) { rect_t clip_r = rect_init(0, 0, lcd_w, lcd_h); lcd_set_clip_rect(c->lcd, &clip_r); } -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU /* 把 canvas 的裁剪区设置为无限大,在 opengl 的状态下让 vg 来处理裁剪区的问题 */ c->clip_left = 0; c->clip_top = 0; diff --git a/src/base/canvas_offline.inc b/src/base/canvas_offline.inc index f4008016f..f481e902d 100644 --- a/src/base/canvas_offline.inc +++ b/src/base/canvas_offline.inc @@ -33,7 +33,7 @@ #include "window_manager.h" #include "canvas_offline.h" -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU #ifdef WITHOUT_GLAD #include @@ -85,7 +85,7 @@ canvas_t* canvas_offline_create(uint32_t w, uint32_t h, bitmap_format_t format) canvas_t* c = NULL; native_window_t* native_window = NULL; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU float_t ratio = 0.0f; vgcanvas_t* vg = NULL; framebuffer_object_t* fbo = NULL; @@ -115,7 +115,7 @@ canvas_t* canvas_offline_create(uint32_t w, uint32_t h, bitmap_format_t format) return_value_if_fail(native_window != NULL, NULL); c = native_window_get_canvas(native_window); -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU if (format != BITMAP_FMT_RGBA8888) { assert(!" opengl gpu only supported RGBA foramt "); @@ -220,7 +220,7 @@ ret_t canvas_offline_clear_canvas(canvas_t* canvas) { } #else ret_t canvas_offline_clear_canvas(canvas_t* canvas) { -#ifndef WITH_NANOVG_GPU +#ifndef WITH_GPU rect_t rect; canvas_offline_t* canvas_offline = NULL; #endif @@ -232,7 +232,7 @@ ret_t canvas_offline_clear_canvas(canvas_t* canvas) { } #endif -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU glEnable(GL_SCISSOR_TEST); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -249,7 +249,7 @@ ret_t canvas_offline_clear_canvas(canvas_t* canvas) { ret_t canvas_offline_begin_draw(canvas_t* canvas) { vgcanvas_t* vg = NULL; canvas_offline_t* canvas_offline = NULL; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU canvas_offline_gpu_t* c = NULL; #endif @@ -263,7 +263,7 @@ ret_t canvas_offline_begin_draw(canvas_t* canvas) { return_value_if_fail(canvas != NULL, RET_BAD_PARAMS); vg = lcd_get_vgcanvas(canvas->lcd); canvas_offline = (canvas_offline_t*)canvas; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU c = (canvas_offline_gpu_t*)canvas; if (vg != NULL && canvas_offline->begin_draw == 0) { canvas_get_clip_rect(canvas, &canvas_offline->canvas_clip_rect); @@ -302,7 +302,7 @@ ret_t canvas_offline_begin_draw(canvas_t* canvas) { ret_t canvas_offline_end_draw(canvas_t* canvas) { vgcanvas_t* vg = NULL; canvas_offline_t* canvas_offline = NULL; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU canvas_offline_gpu_t* c = NULL; #endif @@ -318,7 +318,7 @@ ret_t canvas_offline_end_draw(canvas_t* canvas) { canvas_offline = (canvas_offline_t*)canvas; canvas_offline->begin_draw--; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU c = (canvas_offline_gpu_t*)canvas; if (vg != NULL && canvas_offline->begin_draw == 0) { uint16_t flag = BITMAP_FLAG_CHANGED; @@ -412,7 +412,7 @@ ret_t canvas_offline_bitmap_move_to_new_bitmap(canvas_t* canvas, bitmap_t* bitma bitmap->specific_ctx = ctx; bitmap->image_manager = image_manager(); bitmap->specific_destroy = canvas_offline_web_bitmap_destroy; -#elif defined(WITH_NANOVG_GPU) +#elif defined(WITH_GPU) bitmap->specific = NULL; bitmap->image_manager = image_manager(); #endif @@ -423,7 +423,7 @@ ret_t canvas_offline_bitmap_move_to_new_bitmap(canvas_t* canvas, bitmap_t* bitma } ret_t canvas_offline_flush_bitmap(canvas_t* canvas) { -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU rect_t r; vgcanvas_t* vg = NULL; canvas_offline_gpu_t* c = (canvas_offline_gpu_t*)canvas; @@ -436,7 +436,7 @@ ret_t canvas_offline_flush_bitmap(canvas_t* canvas) { } #endif -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU vg = lcd_get_vgcanvas(canvas->lcd); if (vg != NULL && c->fbo != NULL) { c = (canvas_offline_gpu_t*)canvas; @@ -452,7 +452,7 @@ ret_t canvas_offline_flush_bitmap(canvas_t* canvas) { ret_t canvas_offline_destroy(canvas_t* canvas) { bitmap_t* bitmap = NULL; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU vgcanvas_t* vg = NULL; framebuffer_object_t* fbo = NULL; #else @@ -468,7 +468,7 @@ ret_t canvas_offline_destroy(canvas_t* canvas) { #endif bitmap = ((canvas_offline_t*)canvas)->bitmap; -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU vg = lcd_get_vgcanvas(canvas->lcd); fbo = ((canvas_offline_gpu_t*)canvas)->fbo; if (fbo != NULL) { diff --git a/src/base/events.c b/src/base/events.c index 7545e2ff7..499315568 100644 --- a/src/base/events.c +++ b/src/base/events.c @@ -92,7 +92,7 @@ ret_t pointer_event_rotate(pointer_event_t* evt, system_info_t* info) { switch (info->lcd_orientation) { case LCD_ORIENTATION_90: { -#if WITH_NANOVG_GPU +#ifdef WITH_GPU evt->y = info->lcd_w - x - 1; evt->x = y; #else @@ -107,7 +107,7 @@ ret_t pointer_event_rotate(pointer_event_t* evt, system_info_t* info) { break; } case LCD_ORIENTATION_270: { -#if WITH_NANOVG_GPU +#ifdef WITH_GPU evt->y = x; evt->x = info->lcd_h - y - 1; #else diff --git a/src/base/types_def.h b/src/base/types_def.h index 04530cb08..90b7a7f59 100644 --- a/src/base/types_def.h +++ b/src/base/types_def.h @@ -250,8 +250,11 @@ typedef enum _app_type_t { #endif /*WITH_NANOVG_SOFT*/ #endif /*defined(WITH_NANOVG_AGGE) || defined(WITH_NANOVG_AGG)*/ -#if defined(WITH_NANOVG_SOFT) || defined(WITH_NANOVG_GPU) -#define WITH_NANOVG 1 +#if defined(WITH_NANOVG_GPU) +#define WITH_GPU 1 +#endif + +#if defined(WITH_NANOVG_SOFT) || defined(WITH_NANOVG_GPU) || defined(WITH_GPU) #define WITH_VGCANVAS 1 #endif /*defined(WITH_NANOVG_SOFT) || defined(WITH_NANOVG_GPU)*/ @@ -340,7 +343,23 @@ typedef struct _system_info_t system_info_t; #if defined(WITH_NANOVG_GL3) || defined(WITH_NANOVG_GL2) || defined(WITH_NANOVG_GLES3) || \ defined(WITH_NANOVG_GLES2) -#define WITH_NANOVG_GL 1 +#define WITH_GPU_GL 1 +#endif + +#if defined(WITH_NANOVG_GL3) +#define WITH_GPU_GL3 1 +#endif + +#if defined(WITH_NANOVG_GL2) +#define WITH_GPU_GL2 1 +#endif + +#if defined(WITH_NANOVG_GLES3) +#define WITH_GPU_GLES3 1 +#endif + +#if defined(WITH_NANOVG_GLES2) +#define WITH_GPU_GLES2 1 #endif #ifndef TK_GLYPH_CACHE_NR diff --git a/src/base/widget.c b/src/base/widget.c index b4ad221e7..ea0b9521d 100644 --- a/src/base/widget.c +++ b/src/base/widget.c @@ -4487,7 +4487,7 @@ bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) { return NULL; } -#elif defined(WITH_NANOVG_GPU) +#elif defined(WITH_GPU) bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) { bitmap_t* img; @@ -4582,7 +4582,7 @@ bitmap_t* widget_take_snapshot_rect(widget_t* widget, const rect_t* r) { return bitmap; } -#endif /*WITH_NANOVG_GPU*/ +#endif /*WITH_GPU*/ bitmap_t* widget_take_snapshot(widget_t* widget) { return widget_take_snapshot_rect(widget, NULL); diff --git a/src/native_window/native_window_fb_gl.c b/src/native_window/native_window_fb_gl.c index ef0ba3e88..e058caa8d 100644 --- a/src/native_window/native_window_fb_gl.c +++ b/src/native_window/native_window_fb_gl.c @@ -19,14 +19,14 @@ * */ -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL #ifndef WITHOUT_GLAD #include "glad/glad.h" #define loadGL gladLoadGL #else #define loadGL() #endif /*WITHOUT_GLAD*/ -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ #include "base/widget.h" #include "lcd/lcd_nanovg.h" @@ -225,7 +225,9 @@ static native_window_t* native_window_create_internal(uint32_t w, uint32_t h, fl loadGL(); canvas_t* c = &(fb_gl->canvas); +#if WITH_NANOVG_GPU lcd = lcd_nanovg_init(win); +#endif canvas_init(c, lcd, font_manager()); return win; diff --git a/src/native_window/native_window_sdl.c b/src/native_window/native_window_sdl.c index 04ae69582..8f20567d6 100644 --- a/src/native_window/native_window_sdl.c +++ b/src/native_window/native_window_sdl.c @@ -23,7 +23,7 @@ #include "base/system_info.h" #include "base/window_manager.h" -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL #ifndef WITHOUT_GLAD #include "glad/glad.h" #define loadGL gladLoadGL @@ -40,7 +40,7 @@ #endif /*IOS*/ #endif /*WITHOUT_GLAD*/ -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ #include "lcd/lcd_sdl2.h" #include "lcd/lcd_nanovg.h" @@ -207,7 +207,7 @@ static canvas_t* native_window_sdl_get_canvas(native_window_t* win) { } static ret_t native_window_sdl_gl_make_current(native_window_t* win) { -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL int fw = 0; int fh = 0; native_window_sdl_t* sdl = NATIVE_WINDOW_SDL(win); @@ -219,16 +219,16 @@ static ret_t native_window_sdl_gl_make_current(native_window_t* win) { glViewport(0, 0, fw, fh); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ return RET_OK; } static ret_t native_window_sdl_swap_buffer(native_window_t* win) { -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL native_window_sdl_t* sdl = NATIVE_WINDOW_SDL(win); SDL_GL_SwapWindow(sdl->window); #else -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ return RET_OK; } @@ -524,7 +524,7 @@ static native_window_t* native_window_create_internal(const char* title, uint32_ win->handle = sdl->window; win->vt = &s_native_window_vtable; -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL sdl->context = SDL_GL_CreateContext(sdl->window); SDL_GL_SetSwapInterval(1); @@ -533,7 +533,7 @@ static native_window_t* native_window_create_internal(const char* title, uint32_ glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ if (native_window_get_info(win, &info) == RET_OK) { w = info.w; @@ -546,7 +546,7 @@ static native_window_t* native_window_create_internal(const char* title, uint32_ #else #ifdef WITH_NANOVG_SOFT lcd = lcd_sdl2_init(sdl->render); -#else +#elif WITH_NANOVG_GPU lcd = lcd_nanovg_init(win); #endif /*WITH_NANOVG_SOFT*/ #endif /*WITH_LCD_MONO*/ @@ -581,7 +581,7 @@ native_window_t* native_window_create(widget_t* widget) { return nw; } -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL static ret_t sdl_init_gl(void) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); @@ -591,10 +591,10 @@ static ret_t sdl_init_gl(void) { SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest"); -#ifdef WITH_NANOVG_GL2 +#ifdef WITH_GPU_GL2 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); -#elif defined(WITH_NANOVG_GL3) +#elif defined(WITH_GPU_GL3) SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); @@ -604,7 +604,7 @@ static ret_t sdl_init_gl(void) { log_debug("Init opengl done.\n"); return RET_OK; } -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ ret_t native_window_sdl_init(bool_t shared, uint32_t w, uint32_t h) { const char* title = system_info()->app_name; @@ -616,9 +616,9 @@ ret_t native_window_sdl_init(bool_t shared, uint32_t w, uint32_t h) { return RET_FAIL; } -#ifdef WITH_NANOVG_GL +#ifdef WITH_GPU_GL sdl_init_gl(); -#endif /*WITH_NANOVG_GL*/ +#endif /*WITH_GPU_GL*/ SDL_StopTextInput(); if (shared) { diff --git a/src/window_animators/window_animator_center_scale.c b/src/window_animators/window_animator_center_scale.c index 25135c5e9..102825a45 100644 --- a/src/window_animators/window_animator_center_scale.c +++ b/src/window_animators/window_animator_center_scale.c @@ -21,7 +21,7 @@ #include "window_animators/window_animator_center_scale.h" -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU #define START_PERCENT 0.5f #else #define START_PERCENT 0.9f @@ -60,7 +60,7 @@ static ret_t window_animator_center_scale_draw_curr(window_animator_t* wa) { return lcd_draw_image(c->lcd, &(wa->curr_img), rectf_scale(&src, wa->ratio), &dst); #else -#ifdef WITH_NANOVG_GPU +#ifdef WITH_GPU vgcanvas_t* vg = canvas_get_vgcanvas(c); float x = win->x + (win->w / 2); float y = win->y + (win->h / 2); @@ -77,7 +77,7 @@ static ret_t window_animator_center_scale_draw_curr(window_animator_t* wa) { #else assert(!"not supported"); return RET_FAIL; -#endif /*WITH_NANOVG_GPU*/ +#endif /*WITH_GPU*/ #endif /*WITHOUT_WINDOW_ANIMATOR_CACHE*/ }