From d0e9f61d095ddb3eea0970e7e73abde97c8b552d Mon Sep 17 00:00:00 2001 From: lixianjing Date: Fri, 2 Jul 2021 21:58:27 +0800 Subject: [PATCH] improve lcd resize --- docs/changes.md | 5 +++ src/base/lcd.c | 4 +-- src/base/native_window.c | 12 ------- src/base/native_window.h | 1 - src/native_window/native_window_fb_gl.c | 36 +++++++++++++++++-- src/native_window/native_window_fb_gl.h | 2 ++ src/native_window/native_window_raw.c | 39 +++++++++++++++------ src/native_window/native_window_sdl.c | 6 +++- src/window_manager/window_manager_default.c | 7 ++-- src/window_manager/window_manager_simple.c | 1 - 10 files changed, 81 insertions(+), 32 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index beae79fdf..a26b7ebc3 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -1,5 +1,10 @@ # 最新动态 +2021/07/02 + * 修复延迟动画刷新的问题(感谢智明提供补丁) + * 修复agge的ras初始化的值不正常的问题(感谢智明提供补丁) + * 修复linux-fb无法修改lcd分辨率问题(感谢智明提供补丁) + 2021/07/01 * 增加rectf\_t。 * 完善switch。 diff --git a/src/base/lcd.c b/src/base/lcd.c index 846a573de..51244d477 100644 --- a/src/base/lcd.c +++ b/src/base/lcd.c @@ -326,10 +326,10 @@ ret_t lcd_resize(lcd_t* lcd, wh_t w, wh_t h, uint32_t line_length) { lcd->h = h; if (lcd->resize != NULL) { - lcd->resize(lcd, w, h, line_length); + return lcd->resize(lcd, w, h, line_length); } - return RET_OK; + return RET_FAIL; } wh_t lcd_get_width(lcd_t* lcd) { diff --git a/src/base/native_window.c b/src/base/native_window.c index dc02bcd02..aae8b4743 100644 --- a/src/base/native_window.c +++ b/src/base/native_window.c @@ -77,18 +77,6 @@ ret_t native_window_invalidate(native_window_t* win, const rect_t* r) { return dirty_rects_add(&(win->dirty_rects), r); } -ret_t native_window_on_resized(native_window_t* win, wh_t w, wh_t h) { - lcd_t* lcd = NULL; - return_value_if_fail(win != NULL, RET_BAD_PARAMS); - - lcd = native_window_get_canvas(win)->lcd; - return_value_if_fail(lcd != NULL, RET_BAD_PARAMS); - - lcd_resize(lcd, w, h, 0); - - return RET_OK; -} - ret_t native_window_gl_make_current(native_window_t* win) { return_value_if_fail(win != NULL && win->vt != NULL, RET_BAD_PARAMS); return_value_if_fail(win->vt->gl_make_current != NULL, RET_BAD_PARAMS); diff --git a/src/base/native_window.h b/src/base/native_window.h index 1276a84a5..bfa7b1516 100644 --- a/src/base/native_window.h +++ b/src/base/native_window.h @@ -249,7 +249,6 @@ ret_t native_window_end_frame(native_window_t* win); rect_t native_window_calc_dirty_rect(native_window_t* win); ret_t native_window_clear_dirty_rect(native_window_t* win); ret_t native_window_update_last_dirty_rect(native_window_t* win); -ret_t native_window_on_resized(native_window_t* win, wh_t w, wh_t h); #define NATIVE_WINDOW(win) ((native_window_t*)(win)) diff --git a/src/native_window/native_window_fb_gl.c b/src/native_window/native_window_fb_gl.c index 671463350..6cac0ab17 100644 --- a/src/native_window/native_window_fb_gl.c +++ b/src/native_window/native_window_fb_gl.c @@ -31,6 +31,7 @@ #include "base/widget.h" #include "lcd/lcd_nanovg.h" #include "base/widget_consts.h" +#include "base/window_manager.h" #include "native_window/native_window_fb_gl.h" typedef struct _native_window_fb_gl_t { @@ -71,13 +72,44 @@ ret_t native_window_fb_gl_set_destroy_func(native_window_t* win, native_window_d return RET_OK; } +lcd_t* native_window_get_lcd(native_window_t* win) { + native_window_fb_gl_t* fb_gl = NATIVE_WINDOW_FB_GL(win); + return_value_if_fail(fb_gl != NULL, NULL); + return fb_gl->canvas.lcd; +} + static ret_t native_window_fb_gl_move(native_window_t* win, xy_t x, xy_t y) { return RET_OK; } +static ret_t native_window_fg_gl_on_resized_timer(const timer_info_t* info) { + widget_t* wm = window_manager(); + native_window_t* win = NATIVE_WINDOW(info->ctx); + event_t e = event_init(EVT_NATIVE_WINDOW_RESIZED, NULL); + window_manager_dispatch_native_window_event(window_manager(), &e, win); + widget_set_need_relayout_children(wm); + widget_invalidate_force(wm, NULL); + + log_debug("on_resized_idle\n"); + return RET_REMOVE; +} + static ret_t native_window_fb_gl_resize(native_window_t* win, wh_t w, wh_t h) { - win->rect.w = w; - win->rect.h = h; + ret_t ret = RET_OK; + native_window_info_t info; + native_window_fb_gl_t* fb_gl = NATIVE_WINDOW_FB_GL(win); + native_window_get_info(win, &info); + + fb_gl->w = win->rect.w = w; + fb_gl->h = win->rect.h = h; + if (system_info()->lcd_orientation == LCD_ORIENTATION_0 && (w != info.w || h != info.h)) { + + ret = lcd_resize(fb_gl->canvas.lcd, w, h, 0); + return_value_if_fail(ret == RET_OK, ret); + system_info_set_lcd_w(system_info(), w); + system_info_set_lcd_h(system_info(), h); + timer_add(native_window_fg_gl_on_resized_timer, win, 100); + } return RET_OK; } diff --git a/src/native_window/native_window_fb_gl.h b/src/native_window/native_window_fb_gl.h index 61c44744b..7b24fa9b3 100644 --- a/src/native_window/native_window_fb_gl.h +++ b/src/native_window/native_window_fb_gl.h @@ -40,6 +40,8 @@ ret_t native_window_fb_gl_set_make_current_func(native_window_t* win, ret_t native_window_fb_gl_set_destroy_func(native_window_t* win, native_window_destroy_t destroy); +lcd_t* native_window_get_lcd(native_window_t* win); + END_C_DECLS #endif /*TK_NATIVE_WINDOW_FB_GL_H*/ diff --git a/src/native_window/native_window_raw.c b/src/native_window/native_window_raw.c index 0fcdb0717..e40923536 100644 --- a/src/native_window/native_window_raw.c +++ b/src/native_window/native_window_raw.c @@ -20,6 +20,7 @@ */ #include "base/widget.h" +#include "base/window_manager.h" #include "native_window/native_window_raw.h" typedef struct _native_window_raw_t { @@ -36,13 +37,31 @@ static ret_t native_window_raw_move(native_window_t* win, xy_t x, xy_t y) { return RET_OK; } -static ret_t native_window_raw_resize(native_window_t* win, wh_t w, wh_t h) { - native_window_raw_t* raw = NATIVE_WINDOW_RAW(win); - lcd_t* lcd = raw->canvas.lcd; +static ret_t native_window_raw_on_resized_timer(const timer_info_t* info) { + widget_t* wm = window_manager(); + native_window_t* win = NATIVE_WINDOW(info->ctx); + event_t e = event_init(EVT_NATIVE_WINDOW_RESIZED, NULL); + window_manager_dispatch_native_window_event(window_manager(), &e, win); + widget_set_need_relayout_children(wm); + widget_invalidate_force(wm, NULL); - if (lcd != NULL && lcd->resize != NULL) { - ret_t ret = lcd_resize(lcd, w, h, 0); - return_value_if_fail(ret != RET_OK, ret); + log_debug("on_resized_idle\n"); + return RET_REMOVE; +} + +static ret_t native_window_raw_resize(native_window_t* win, wh_t w, wh_t h) { + ret_t ret = RET_OK; + native_window_info_t info; + native_window_get_info(win, &info); + + if (system_info()->lcd_orientation == LCD_ORIENTATION_0 && (w != info.w || h != info.h)) { + native_window_raw_t* raw = NATIVE_WINDOW_RAW(win); + + ret = lcd_resize(raw->canvas.lcd, w, h, 0); + return_value_if_fail(ret == RET_OK, ret); + system_info_set_lcd_w(system_info(), w); + system_info_set_lcd_h(system_info(), h); + timer_add(native_window_raw_on_resized_timer, win, 100); } win->rect.w = w; @@ -58,13 +77,13 @@ static canvas_t* native_window_raw_get_canvas(native_window_t* win) { } static ret_t native_window_raw_get_info(native_window_t* win, native_window_info_t* info) { - native_window_raw_t* raw = NATIVE_WINDOW_RAW(win); + system_info_t* s_info = system_info(); info->x = 0; info->y = 0; - info->ratio = raw->canvas.lcd->ratio; - info->w = lcd_get_width(raw->canvas.lcd); - info->h = lcd_get_height(raw->canvas.lcd); + info->w = s_info->lcd_w; + info->h = s_info->lcd_h; + win->ratio = info->ratio = s_info->device_pixel_ratio; log_debug("ratio=%f %d %d\n", info->ratio, info->w, info->h); diff --git a/src/native_window/native_window_sdl.c b/src/native_window/native_window_sdl.c index 6d981616b..2d02f4587 100644 --- a/src/native_window/native_window_sdl.c +++ b/src/native_window/native_window_sdl.c @@ -78,6 +78,7 @@ static ret_t native_window_sdl_move(native_window_t* win, xy_t x, xy_t y) { } static ret_t native_window_sdl_resize(native_window_t* win, wh_t w, wh_t h) { + ret_t ret = RET_OK; native_window_info_t info; native_window_sdl_t* sdl = NATIVE_WINDOW_SDL(win); @@ -88,16 +89,19 @@ static ret_t native_window_sdl_resize(native_window_t* win, wh_t w, wh_t h) { #if !defined(ANDROID) && !defined(IOS) if (system_info()->lcd_orientation == LCD_ORIENTATION_0 && (w != info.w || h != info.h)) { + lcd_t* lcd = sdl->canvas.lcd; #ifdef WIN32 w = w * win->ratio; h = h * win->ratio; #endif /*WIN32*/ SDL_SetWindowSize(sdl->window, w, h); + + ret = lcd_resize(lcd, w, h, 0); } #endif /*ANDROID*/ - return RET_OK; + return ret; } static ret_t native_window_sdl_minimize(native_window_t* win) { diff --git a/src/window_manager/window_manager_default.c b/src/window_manager/window_manager_default.c index b5c187bcc..aac7fddff 100644 --- a/src/window_manager/window_manager_default.c +++ b/src/window_manager/window_manager_default.c @@ -1226,13 +1226,15 @@ static ret_t window_manager_default_layout_child(widget_t* widget, widget_t* win } static ret_t window_manager_default_resize(widget_t* widget, wh_t w, wh_t h) { + ret_t ret = RET_OK; rect_t r = rect_init(0, 0, w, h); window_manager_default_t* wm = WINDOW_MANAGER_DEFAULT(widget); return_value_if_fail(wm != NULL, RET_BAD_PARAMS); - widget_move_resize(widget, 0, 0, w, h); + ret = native_window_resize(wm->native_window, w, h, TRUE); + return_value_if_fail(ret == RET_OK, ret); - native_window_resize(wm->native_window, w, h, TRUE); + widget_move_resize(widget, 0, 0, w, h); native_window_invalidate(wm->native_window, &r); native_window_update_last_dirty_rect(wm->native_window); @@ -1366,7 +1368,6 @@ static ret_t window_manager_default_native_window_resized(widget_t* widget, void h = w; } - native_window_on_resized(nw, w, h); if (widget->w == w && widget->h == h) { return RET_OK; } diff --git a/src/window_manager/window_manager_simple.c b/src/window_manager/window_manager_simple.c index bb0e3432d..987991665 100644 --- a/src/window_manager/window_manager_simple.c +++ b/src/window_manager/window_manager_simple.c @@ -500,7 +500,6 @@ static ret_t window_manager_native_native_window_resized(widget_t* widget, void* } window_manager_simple_resize(widget, w, h); - native_window_on_resized(nw, w, h); return RET_OK; }