fix window manager paint events

This commit is contained in:
xianjimli 2019-04-19 12:31:32 +08:00
parent 54cc95e396
commit c3d2a89f51
3 changed files with 54 additions and 24 deletions

View File

@ -28,8 +28,6 @@ static ret_t window_animator_paint_system_bar(window_animator_t* wa);
static ret_t window_animator_update_percent(window_animator_t* wa);
static ret_t window_animator_draw_prev_window(window_animator_t* wa);
static ret_t window_animator_draw_curr_window(window_animator_t* wa);
static ret_t window_animator_begin_frame_normal(window_animator_t* wa);
static ret_t window_animator_begin_frame_overlap(window_animator_t* wa);
static ret_t window_animator_open_destroy(window_animator_t* wa) {
#ifdef WITH_NANOVG_GPU
@ -64,22 +62,6 @@ static bool_t window_animator_is_overlap(window_animator_t* wa) {
return wa->vt->overlap;
}
static ret_t window_animator_begin_frame(window_animator_t* wa) {
return_value_if_fail(wa != NULL, RET_OK);
if (window_animator_is_overlap(wa)) {
return window_animator_begin_frame_overlap(wa);
} else {
return window_animator_begin_frame_normal(wa);
}
}
static ret_t window_animator_end_frame(window_animator_t* wa) {
canvas_end_frame(wa->canvas);
return RET_OK;
}
ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms) {
return_value_if_fail(wa != NULL, RET_FAIL);
@ -93,10 +75,8 @@ ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms) {
}
ENSURE(window_animator_update_percent(wa) == RET_OK);
ENSURE(window_animator_begin_frame(wa) == RET_OK);
ENSURE(window_animator_draw_prev_window(wa) == RET_OK);
ENSURE(window_animator_draw_curr_window(wa) == RET_OK);
ENSURE(window_animator_end_frame(wa) == RET_OK);
return wa->time_percent >= 1 ? RET_DONE : RET_OK;
}
@ -255,3 +235,20 @@ ret_t window_animator_overlap_default_draw_prev(window_animator_t* wa) {
return lcd_draw_image(c->lcd, &(wa->prev_img), rect_scale(&src, wa->ratio), &dst);
}
ret_t window_animator_begin_frame(window_animator_t* wa) {
return_value_if_fail(wa != NULL, RET_OK);
if (window_animator_is_overlap(wa)) {
return window_animator_begin_frame_overlap(wa);
} else {
return window_animator_begin_frame_normal(wa);
}
}
ret_t window_animator_end_frame(window_animator_t* wa) {
canvas_end_frame(wa->canvas);
return RET_OK;
}

View File

@ -160,6 +160,24 @@ struct _window_animator_t {
*/
ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms);
/**
* @method window_animator_begin_frame
* begin frame
* @param {window_animator_t*} wa
*
* @return {ret_t} RET_OK表示成功
*/
ret_t window_animator_begin_frame(window_animator_t* wa);
/**
* @method window_animator_end_frame
* end frame
* @param {window_animator_t*} wa
*
* @return {ret_t} RET_OK表示成功
*/
ret_t window_animator_end_frame(window_animator_t* wa);
/**
* @method window_animator_destroy
*

View File

@ -556,6 +556,7 @@ static ret_t window_manager_update_cursor(widget_t* widget, int32_t x, int32_t y
}
static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
paint_event_t e;
window_manager_t* wm = WINDOW_MANAGER(widget);
rect_t* dr = &(wm->dirty_rect);
@ -572,8 +573,15 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
if (r.w > 0 && r.h > 0) {
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_NORMAL) == RET_OK);
widget_dispatch(widget, paint_event_init(&e, EVT_BEFORE_PAINT, widget, c));
ENSURE(widget_paint(WIDGET(wm), c) == RET_OK);
window_manager_paint_cursor(widget, c);
widget_dispatch(widget, paint_event_init(&e, EVT_AFTER_PAINT, widget, c));
widget_dispatch(widget, paint_event_init(&e, EVT_PAINT_DONE, widget, c));
ENSURE(canvas_end_frame(c) == RET_OK);
wm->last_paint_cost = time_now_ms() - start_time;
wm->last_dirty_rect = wm->dirty_rect;
@ -590,10 +598,21 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
}
static ret_t window_manager_paint_animation(widget_t* widget, canvas_t* c) {
paint_event_t e;
uint32_t start_time = time_now_ms();
window_manager_t* wm = WINDOW_MANAGER(widget);
ENSURE(window_animator_begin_frame(wm->animator) == RET_OK);
widget_dispatch(widget, paint_event_init(&e, EVT_BEFORE_PAINT, widget, c));
ret_t ret = window_animator_update(wm->animator, start_time);
widget_dispatch(widget, paint_event_init(&e, EVT_AFTER_PAINT, widget, c));
widget_dispatch(widget, paint_event_init(&e, EVT_PAINT_DONE, widget, c));
ENSURE(window_animator_end_frame(wm->animator) == RET_OK);
wm->last_paint_cost = time_now_ms() - start_time;
window_manager_inc_fps(widget);
@ -652,7 +671,6 @@ static ret_t window_manager_update_fps(widget_t* widget) {
}
ret_t window_manager_paint(widget_t* widget, canvas_t* c) {
paint_event_t e;
ret_t ret = RET_OK;
window_manager_t* wm = WINDOW_MANAGER(widget);
return_value_if_fail(wm != NULL && c != NULL, RET_BAD_PARAMS);
@ -661,14 +679,11 @@ ret_t window_manager_paint(widget_t* widget, canvas_t* c) {
canvas_set_global_alpha(c, 0xff);
window_manager_update_fps(widget);
widget_dispatch(widget, paint_event_init(&e, EVT_BEFORE_PAINT, widget, c));
if (wm->animator != NULL) {
ret = window_manager_paint_animation(widget, c);
} else {
ret = window_manager_paint_normal(widget, c);
}
widget_dispatch(widget, paint_event_init(&e, EVT_AFTER_PAINT, widget, c));
widget_dispatch(widget, paint_event_init(&e, EVT_PAINT_DONE, widget, c));
return ret;
}