window animator on framebuffer

This commit is contained in:
xianjimli 2018-04-22 16:57:05 +08:00
parent e87c457344
commit 6d5f099997
31 changed files with 304 additions and 111 deletions

View File

@ -10,8 +10,8 @@ GTEST_ROOT = os.path.join(LFTK_ROOT, '3rd/gtest/googletest')
BIN_DIR=os.path.join(LFTK_ROOT, 'bin')
LIB_DIR=os.path.join(LFTK_ROOT, 'lib')
LCD='SDL'
LCD='NANOVG'
LCD='SDL'
os.environ['LCD'] = LCD
os.environ['BIN_DIR'] = BIN_DIR;

View File

@ -115,7 +115,7 @@ ret_t application_init() {
progress_bar = progress_bar_create(win, 10, 80, 168, 20);
widget_set_value(progress_bar, 40);
timer_add(on_timer, progress_bar, 200);
// timer_add(on_timer, progress_bar, 200);
#ifndef WITH_STM32F103ZE_RAW
progress_bar_set_show_text(progress_bar, TRUE);

View File

@ -157,4 +157,4 @@ const unsigned char image_slider_drag_p[] = {
0x11,0x96,0xdb,0xc0,0x12,0x96,0xdb,0xff,0x12,0x96,0xdb,0xff,0x12,0x96,0xdb,0xff,0x12,0x96,0xdb,0xff,
0x11,0x96,0xda,0xd0,0x12,0x96,0xda,0xa0,0x10,0x96,0xdc,0x50,0x12,0x96,0xdb,0x00,0x12,0x96,0xdb,0x00,
0x12,0x96,0xdb,0x00,0x12,0x96,0xdb,0x00,0x11,0x95,0xdb,0x00,0x10,0x95,0xda,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x7f,0x00,0x00,};/*3176*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*3176*/

View File

@ -17,6 +17,7 @@ if os.environ['LCD'] == 'NANOVG':
sources += ['lcd/lcd_nanovg.c', 'lcd/lcd_mem_rgba.c', 'main_loop/main_loop_nanovg.c'];
else:
sources += Glob('vgcanvas/vgcanvas_agg.cpp')
sources += ['animator/window_animator_fb.c'];
sources += ['lcd/lcd_sdl2.c', 'lcd/lcd_mem_rgba.c', 'main_loop/main_loop_sdl2.c']
env=DefaultEnvironment().Clone()

View File

@ -39,8 +39,8 @@ static ret_t window_animator_open_bottom_to_top_draw_curr(window_animator_t* wa)
#ifdef WITH_NANOVG
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
vgcanvas_set_global_alpha(vg, alpha);
vgcanvas_draw_image(vg, &(wa->curr_img), win->x * ratio, win->y * ratio, win->w * ratio, h * ratio,
win->x, y, win->w, h);
vgcanvas_draw_image(vg, &(wa->curr_img), win->x * ratio, win->y * ratio, win->w * ratio,
h * ratio, win->x, y, win->w, h);
#else
rect_init(src, win->x * ratio, win->y * ratio, win->w * ratio, h * ratio);
rect_init(dst, win->x, y, win->w, h);

View File

@ -49,7 +49,7 @@ static ret_t window_animator_open_scale_draw_curr(window_animator_t* wa) {
rect_init(dst, 0, 0, win->w * scale, win->h * scale);
dst.x = win->x + ((win->w - dst.w) >> 1);
dst.y = win->y + ((win->h - dst.h) >> 1);
log_debug("%d %d %d %d\n", dst.x, dst.y, dst.w, dst.h);
lcd_set_global_alpha(c->lcd, alpha * 0xff);
lcd_draw_image(c->lcd, &(wa->curr_img), &src, &dst);
#endif

40
src/animator/common.inc Normal file
View File

@ -0,0 +1,40 @@
static window_animator_t* window_animator_create(window_animator_type_t type, bool_t open) {
window_animator_t* wa = NULL;
if (type == WINDOW_ANIMATOR_CENTER_SCALE) {
wa = window_animator_create_scale(open);
} else if (type == WINDOW_ANIMATOR_HTRANSLATE) {
wa = window_animator_create_htranslate(open);
} else if (type == WINDOW_ANIMATOR_VTRANSLATE) {
wa = window_animator_create_vtranslate(open);
} else if (type == WINDOW_ANIMATOR_BOTTOM_TO_TOP) {
wa = window_animator_create_bottom_to_top(open);
} else if (type == WINDOW_ANIMATOR_TOP_TO_BOTTOM) {
wa = window_animator_create_top_to_bottom(open);
} else if (type == WINDOW_ANIMATOR_FADE) {
wa = window_animator_create_fade(open);
}
return wa;
}
window_animator_t* window_animator_create_for_open(window_animator_type_t type, canvas_t* c,
widget_t* prev_win, widget_t* curr_win) {
window_animator_t* wa = window_animator_create(type, TRUE);
return_value_if_fail(wa != NULL, NULL);
window_animator_prepare(wa, c, prev_win, curr_win, TRUE);
return wa;
}
window_animator_t* window_animator_create_for_close(window_animator_type_t type, canvas_t* c,
widget_t* prev_win, widget_t* curr_win) {
window_animator_t* wa = window_animator_create(type, FALSE);
return_value_if_fail(wa != NULL, NULL);
window_animator_prepare(wa, c, prev_win, curr_win, FALSE);
return wa;
}

View File

@ -22,7 +22,8 @@ static ret_t window_animator_open_htranslate_draw_prev(window_animator_t* wa) {
#ifdef WITH_NANOVG
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
vgcanvas_draw_image(vg, &(wa->prev_img), x * ratio, win->y * ratio, w * ratio, win->h * ratio, 0, win->y, w, win->h);
vgcanvas_draw_image(vg, &(wa->prev_img), x * ratio, win->y * ratio, w * ratio, win->h * ratio, 0,
win->y, w, win->h);
#else
rect_init(src, x * ratio, win->y * ratio, w * ratio, win->h * ratio);
rect_init(dst, 0, win->y, w, win->h);
@ -44,7 +45,8 @@ static ret_t window_animator_open_htranslate_draw_curr(window_animator_t* wa) {
#ifdef WITH_NANOVG
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
vgcanvas_draw_image(vg, &(wa->curr_img), 0, win->y * ratio, w * ratio, win->h * ratio, x, win->y, w, win->h);
vgcanvas_draw_image(vg, &(wa->curr_img), 0, win->y * ratio, w * ratio, win->h * ratio, x, win->y,
w, win->h);
#else
rect_init(src, 0, win->y * ratio, w * ratio, win->h * ratio);
rect_init(dst, x, win->y, w, win->h);

View File

@ -41,8 +41,8 @@ static ret_t window_animator_open_top_to_bottom_draw_curr(window_animator_t* wa)
vgcanvas_draw_image(vg, &(wa->curr_img), win->x * ratio, y * ratio, win->w * ratio, h * ratio,
win->x, 0, win->w, h);
#else
rect_init(src, win->x * ratio, win->y * ratio, win->w * ratio, h * ratio);
rect_init(dst, win->x, y, win->w, h);
rect_init(src, win->x * ratio, y * ratio, win->w * ratio, h * ratio);
rect_init(dst, win->x, 0, win->w, h);
lcd_set_global_alpha(c->lcd, alpha * 0xff);
lcd_draw_image(c->lcd, &(wa->curr_img), &src, &dst);
#endif
@ -68,4 +68,3 @@ static window_animator_t* window_animator_create_top_to_bottom(bool_t open) {
return wa;
}

View File

@ -22,7 +22,8 @@ static ret_t window_animator_open_vtranslate_draw_prev(window_animator_t* wa) {
#ifdef WITH_NANOVG
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
vgcanvas_draw_image(vg, &(wa->prev_img), win->x * ratio, y * ratio, win->w * ratio, h * ratio, win->x, 0, win->w, h);
vgcanvas_draw_image(vg, &(wa->prev_img), win->x * ratio, y * ratio, win->w * ratio, h * ratio,
win->x, 0, win->w, h);
#else
rect_init(src, win->x * ratio, y * ratio, win->w * ratio, h * ratio);
rect_init(dst, win->x, 0, win->w, h);
@ -44,7 +45,8 @@ static ret_t window_animator_open_vtranslate_draw_curr(window_animator_t* wa) {
#ifdef WITH_NANOVG
vgcanvas_t* vg = lcd_get_vgcanvas(c->lcd);
vgcanvas_draw_image(vg, &(wa->curr_img), win->x, 0, win->w * ratio, h * ratio, win->x, y, win->w, h);
vgcanvas_draw_image(vg, &(wa->curr_img), win->x, 0, win->w * ratio, h * ratio, win->x, y, win->w,
h);
#else
rect_init(src, win->x, 0, win->w * ratio, h * ratio);
rect_init(dst, win->x, y, win->w, h);

View File

@ -0,0 +1,78 @@
/**
* File: window_animator_fb
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: fb implemented window animator
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-04-22 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "base/mem.h"
#include "base/window_animator.h"
static ret_t window_animator_open_destroy(window_animator_t* wa) {
bitmap_destroy(&(wa->prev_img));
bitmap_destroy(&(wa->curr_img));
memset(wa, 0x00, sizeof(window_animator_t));
MEM_FREE(wa);
return RET_OK;
}
static ret_t window_animator_close_destroy(window_animator_t* wa) {
widget_destroy(wa->curr_win);
return window_animator_open_destroy(wa);
}
static ret_t window_animator_prepare(window_animator_t* wa, canvas_t* c, widget_t* prev_win,
widget_t* curr_win, bool_t open) {
rect_t r;
lcd_t* lcd = c->lcd;
widget_t* wm = prev_win->parent;
wa->ratio = 1;
wa->canvas = c;
wa->open = open;
wa->duration = 400;
wa->prev_win = prev_win;
wa->curr_win = curr_win;
rect_init(r, 0, 0, wm->w, wm->h);
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_OFFLINE) == RET_OK);
ENSURE(widget_paint(prev_win, c) == RET_OK);
ENSURE(lcd_take_snapshot(lcd, &(wa->prev_img)) == RET_OK);
ENSURE(canvas_end_frame(c) == RET_OK);
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_OFFLINE) == RET_OK);
ENSURE(widget_paint(curr_win, c) == RET_OK);
ENSURE(lcd_take_snapshot(lcd, &(wa->curr_img)) == RET_OK);
ENSURE(canvas_end_frame(c) == RET_OK);
wa->prev_img.flags = BITMAP_FLAG_OPAQUE;
wa->curr_img.flags = BITMAP_FLAG_OPAQUE;
return RET_OK;
}
#include "fade.inc"
#include "htranslate.inc"
#include "vtranslate.inc"
#include "center_scale.inc"
#include "bottom_to_top.inc"
#include "top_to_bottom.inc"
#include "common.inc"

View File

@ -1,7 +1,7 @@
/**
* File: window_animator_direct
* File: window_animator_nanovg
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: window_animator_direct
* Brief: nanovg implemented window animator
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
@ -34,15 +34,9 @@ static ret_t window_animator_open_destroy(window_animator_t* wa) {
}
static ret_t window_animator_close_destroy(window_animator_t* wa) {
vgcanvas_t* vg = lcd_get_vgcanvas(wa->canvas->lcd);
widget_destroy(wa->curr_win);
vgcanvas_destroy_fbo(vg, &(wa->prev_fbo));
vgcanvas_destroy_fbo(vg, &(wa->curr_fbo));
memset(wa, 0x00, sizeof(window_animator_t));
MEM_FREE(wa);
return RET_OK;
return window_animator_open_destroy(wa);
}
static ret_t fbo_to_img(framebuffer_object_t* fbo, bitmap_t* img) {
@ -93,42 +87,4 @@ static ret_t window_animator_prepare(window_animator_t* wa, canvas_t* c, widget_
#include "bottom_to_top.inc"
#include "top_to_bottom.inc"
static window_animator_t* window_animator_create(window_animator_type_t type, bool_t open) {
window_animator_t* wa = NULL;
if(type == WINDOW_ANIMATOR_CENTER_SCALE) {
wa = window_animator_create_scale(open);
} else if(type == WINDOW_ANIMATOR_HTRANSLATE) {
wa = window_animator_create_htranslate(open);
} else if(type == WINDOW_ANIMATOR_VTRANSLATE) {
wa = window_animator_create_vtranslate(open);
} else if(type == WINDOW_ANIMATOR_BOTTOM_TO_TOP) {
wa = window_animator_create_bottom_to_top(open);
} else if(type == WINDOW_ANIMATOR_TOP_TO_BOTTOM) {
wa = window_animator_create_top_to_bottom(open);
} else if(type == WINDOW_ANIMATOR_FADE) {
wa = window_animator_create_fade(open);
}
return wa;
}
window_animator_t* window_animator_create_for_open(window_animator_type_t type, canvas_t* c,
widget_t* prev_win, widget_t* curr_win) {
window_animator_t* wa = window_animator_create(type, TRUE);
return_value_if_fail(wa != NULL, NULL);
window_animator_prepare(wa, c, prev_win, curr_win, TRUE);
return wa;
}
window_animator_t* window_animator_create_for_close(window_animator_type_t type, canvas_t* c,
widget_t* prev_win, widget_t* curr_win) {
window_animator_t* wa = window_animator_create(type, FALSE);
return_value_if_fail(wa != NULL, NULL);
window_animator_prepare(wa, c, prev_win, curr_win, FALSE);
return wa;
}
#include "common.inc"

View File

@ -51,7 +51,7 @@ typedef enum _bitmap_format_t {
* @const BITMAP_FMT_RGB565
* 2RGB分别占用5,6,5
*/
BITMAP_FTM_RGB565
BITMAP_FMT_RGB565
} bitmap_format_t;
/**

View File

@ -165,14 +165,14 @@ wh_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr) {
}
}
ret_t canvas_begin_frame(canvas_t* c, rect_t* dirty_rect) {
ret_t canvas_begin_frame(canvas_t* c, rect_t* dirty_rect, lcd_draw_mode_t draw_mode) {
return_value_if_fail(c != NULL, RET_BAD_PARAMS);
c->ox = 0;
c->oy = 0;
canvas_set_clip_rect(c, dirty_rect);
return lcd_begin_frame(c->lcd, dirty_rect);
return lcd_begin_frame(c->lcd, dirty_rect, draw_mode);
}
static ret_t canvas_draw_hline_impl(canvas_t* c, xy_t x, xy_t y, wh_t w) {
@ -863,7 +863,7 @@ ret_t canvas_test_paint(canvas_t* c, bool_t pressed, xy_t x, xy_t y) {
color_t bg = color_init(0xff, 0xff, 0, 0xff);
color_t fg = color_init(0xff, 0, 0, 0xff);
canvas_begin_frame(c, NULL);
canvas_begin_frame(c, NULL, LCD_DRAW_NORMAL);
canvas_set_clip_rect(c, NULL);
canvas_set_fill_color(c, bg);
canvas_set_stroke_color(c, fg);

View File

@ -64,7 +64,7 @@ ret_t canvas_set_font(canvas_t* c, const char* name, uint16_t size);
wh_t canvas_measure_text(canvas_t* c, wchar_t* str, int32_t nr);
ret_t canvas_begin_frame(canvas_t* c, rect_t* dirty_rect);
ret_t canvas_begin_frame(canvas_t* c, rect_t* dirty_rect, lcd_draw_mode_t draw_mode);
ret_t canvas_translate(canvas_t* c, xy_t dx, xy_t dy);
ret_t canvas_untranslate(canvas_t* c, xy_t dx, xy_t dy);

View File

@ -100,7 +100,6 @@ static ret_t dialog_on_relayout_children(widget_t* widget) {
return RET_OK;
}
static const widget_vtable_t s_dialog_vtable = {.get_prop = dialog_get_prop,
.set_prop = dialog_set_prop,
.on_layout_children = dialog_on_relayout_children,
@ -145,6 +144,7 @@ widget_t* dialog_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
dialog->margin = 0;
dialog->title = dialog_title_create(widget, 0, 0, 0, 0);
dialog->client = dialog_client_create(widget, 0, 0, 0, 0);
dialog_on_relayout_children(widget);
return widget;
}

View File

@ -21,9 +21,10 @@
#include "base/lcd.h"
ret_t lcd_begin_frame(lcd_t* lcd, rect_t* dirty_rect) {
ret_t lcd_begin_frame(lcd_t* lcd, rect_t* dirty_rect, lcd_draw_mode_t draw_mode) {
return_value_if_fail(lcd != NULL && lcd->begin_frame != NULL, RET_BAD_PARAMS);
lcd->draw_mode = draw_mode;
return lcd->begin_frame(lcd, dirty_rect);
}
@ -183,3 +184,9 @@ vgcanvas_t* lcd_get_vgcanvas(lcd_t* lcd) {
return lcd->get_vgcanvas(lcd);
}
ret_t lcd_take_snapshot(lcd_t* lcd, bitmap_t* img) {
return_value_if_fail(lcd != NULL && lcd->take_snapshot != NULL, RET_BAD_PARAMS);
return lcd->take_snapshot(lcd, img);
}

View File

@ -56,10 +56,36 @@ typedef ret_t (*lcd_draw_text_t)(lcd_t* lcd, wchar_t* str, int32_t nr, xy_t x, x
typedef ret_t (*lcd_draw_image_t)(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst);
typedef vgcanvas_t* (*lcd_get_vgcanvas_t)(lcd_t* lcd);
typedef ret_t (*lcd_take_snapshot_t)(lcd_t* lcd, bitmap_t* img);
typedef ret_t (*lcd_end_frame_t)(lcd_t* lcd);
typedef ret_t (*lcd_destroy_t)(lcd_t* lcd);
/**
* @enum lcd_draw_mode_t
* @prefix LCD_DRAW_
* LCD绘制模式常量定义
*/
typedef enum _lcd_draw_mode_t {
/**
* @const LCD_DRAW_NORMAL
*
*/
LCD_DRAW_NORMAL = 0,
/**
* @const LCD_DRAW_ANIMATION
*
* framebuffer中
*/
LCD_DRAW_ANIMATION,
/**
* @const LCD_DRAW_OFFLINE
* 线(framebuffer)
* take_snapshot取出来
*/
LCD_DRAW_OFFLINE
} lcd_draw_mode_t;
/**
* @class lcd_t
*
@ -85,6 +111,7 @@ struct _lcd_t {
lcd_get_point_color_t get_point_color;
lcd_end_frame_t end_frame;
lcd_get_vgcanvas_t get_vgcanvas;
lcd_take_snapshot_t take_snapshot;
lcd_destroy_t destroy;
@ -137,6 +164,13 @@ struct _lcd_t {
*/
uint32_t font_size;
/**
* @property {lcd_draw_mode_t} draw_mode
* @readonly
*
*/
lcd_draw_mode_t draw_mode;
rect_t* dirty_rect;
};
@ -145,10 +179,11 @@ struct _lcd_t {
*
* @param {lcd_t*} lcd lcd对象
* @param {rect_t*} dirty_rect
* @param {bool_t} anim_mode 线framebuffer
*
* @return {ret_t} RET_OK表示成功
*/
ret_t lcd_begin_frame(lcd_t* lcd, rect_t* dirty_rect);
ret_t lcd_begin_frame(lcd_t* lcd, rect_t* dirty_rect, lcd_draw_mode_t draw_mode);
/**
* @method lcd_set_clip_rect
@ -350,6 +385,16 @@ ret_t lcd_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst);
*/
vgcanvas_t* lcd_get_vgcanvas(lcd_t* lcd);
/**
* @method lcd_take_snapshot
* framebuffer模式
* @param {lcd_t*} lcd lcd对象
* @param {bitmap_t*} img
*
* @return {ret_t} RET_OK表示成功
*/
ret_t lcd_take_snapshot(lcd_t* lcd, bitmap_t* img);
/**
* @method lcd_end_frame
*

View File

@ -87,4 +87,3 @@ ret_t window_close(widget_t* widget) {
return window_manager_remove_child(widget->parent, widget);
}

View File

@ -45,7 +45,7 @@ ret_t window_animator_update(window_animator_t* wa, uint32_t time_ms) {
}
rect_init(r, wm->x, wm->y, wm->w, wm->h);
ENSURE(canvas_begin_frame(c, &r) == RET_OK);
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_ANIMATION) == RET_OK);
if (wa->draw_prev_window != NULL) {
wa->draw_prev_window(wa);

View File

@ -208,7 +208,7 @@ static ret_t window_manager_paint_normal(widget_t* widget, canvas_t* c) {
rect_merge(&r, ldr);
if (r.w > 0 && r.h > 0) {
ENSURE(canvas_begin_frame(c, &r) == RET_OK);
ENSURE(canvas_begin_frame(c, &r, LCD_DRAW_NORMAL) == RET_OK);
ENSURE(widget_paint(WIDGETP(wm), c) == RET_OK);
ENSURE(canvas_end_frame(c) == RET_OK);
}

View File

@ -19,6 +19,7 @@
*
*/
#include "base/mem.h"
#include "base/vgcanvas.h"
static ret_t lcd_mem_begin_frame(lcd_t* lcd, rect_t* dirty_rect) {
@ -191,6 +192,52 @@ static vgcanvas_t* lcd_mem_get_vgcanvas(lcd_t* lcd) {
return mem->vgcanvas;
}
static ret_t snapshot_destroy(bitmap_t* img) {
MEM_FREE((void*)(img->data));
return RET_OK;
}
static ret_t lcd_mem_take_snapshot(lcd_t* lcd, bitmap_t* img) {
uint32_t size = 0;
void* data = NULL;
lcd_mem_t* mem = (lcd_mem_t*)lcd;
memset(img, 0x00, sizeof(bitmap_t));
img->w = lcd->w;
img->h = lcd->h;
img->format = LCD_FORMAT;
if (img->format == BITMAP_FMT_RGBA) {
uint32_t i = 0;
uint32_t* s = NULL;
uint32_t* d = NULL;
uint32_t nr = img->w * img->h;
size = img->w * img->h * 4;
data = MEM_ALLOC(size);
return_value_if_fail(data != NULL, RET_FAIL);
s = (uint32_t*)(mem->pixels);
d = (uint32_t*)data;
for (i = 0; i < nr; i++, s++, d++) {
uint8_t* ps = (uint8_t*)s;
uint8_t* pd = (uint8_t*)d;
pd[0] = ps[3];
pd[1] = ps[2];
pd[2] = ps[1];
pd[3] = ps[0];
}
} else {
return_value_if_fail(size > 0, RET_FAIL);
}
img->destroy = snapshot_destroy;
img->data = (uint8_t*)data;
return RET_OK;
}
static ret_t lcd_mem_end_frame(lcd_t* lcd) { return RET_OK; }
static ret_t lcd_mem_destroy(lcd_t* lcd) {
@ -217,6 +264,7 @@ lcd_t* lcd_mem_create(wh_t w, wh_t h, bool_t alloc) {
base->draw_points = lcd_mem_draw_points;
base->get_point_color = lcd_mem_get_point_color;
base->get_vgcanvas = lcd_mem_get_vgcanvas;
base->take_snapshot = lcd_mem_take_snapshot;
base->end_frame = lcd_mem_end_frame;
base->destroy = lcd_mem_destroy;

View File

@ -95,7 +95,10 @@ static ret_t lcd_sdl2_end_frame(lcd_t* lcd) {
if (dr->w > 0 && dr->h > 0) {
SDL_RenderCopy(sdl->render, sdl->texture, NULL, NULL);
}
if (lcd->draw_mode != LCD_DRAW_OFFLINE) {
SDL_RenderPresent(sdl->render);
}
return RET_OK;
}
@ -107,6 +110,12 @@ static ret_t lcd_sdl2_destroy(lcd_t* lcd) {
return RET_OK;
}
static ret_t lcd_sdl_take_snapshot(lcd_t* lcd, bitmap_t* img) {
lcd_sdl2_t* mem = (lcd_sdl2_t*)lcd;
return lcd_take_snapshot((lcd_t*)(mem->lcd_mem), img);
}
static vgcanvas_t* lcd_sdl2_get_vgcanvas(lcd_t* lcd) {
lcd_sdl2_t* mem = (lcd_sdl2_t*)lcd;
@ -132,6 +141,7 @@ lcd_t* lcd_sdl2_init(SDL_Renderer* render) {
base->draw_points = lcd_sdl2_draw_points;
base->end_frame = lcd_sdl2_end_frame;
base->get_vgcanvas = lcd_sdl2_get_vgcanvas;
base->take_snapshot = lcd_sdl_take_snapshot;
base->destroy = lcd_sdl2_destroy;
SDL_GetRendererOutputSize(render, &w, &h);

View File

@ -21,6 +21,8 @@
typedef uint16_t pixel_t;
#define LCD_FORMAT BITMAP_FMT_RGB565
#define rgb_to_pixel(r, g, b) ((((r) >> 3) << 11) | (((g) >> 2) << 5) | ((b) >> 3))
static inline pixel_t to_pixel(color_t c) { return rgb_to_pixel(c.rgba.r, c.rgba.g, c.rgba.b); }

View File

@ -21,6 +21,8 @@
typedef uint32_t pixel_t;
#define LCD_FORMAT BITMAP_FMT_RGBA
#define rgb_to_pixel(r, g, b) ((r) << 24) | ((g) << 16) | ((b) << 8) | 0xff
static inline pixel_t to_pixel(color_t c) { return rgb_to_pixel(c.rgba.r, c.rgba.g, c.rgba.b); }

View File

@ -156,7 +156,6 @@ static ret_t main_loop_nanovg_run(main_loop_t* l) {
idle_dispatch();
main_loop_nanovg_paint(loop);
if (!WINDOW_MANAGER(loop->wm)->animating) {
SDL_Delay(30);
}

View File

@ -150,6 +150,9 @@ static ret_t main_loop_sdl2_run(main_loop_t* l) {
idle_dispatch();
main_loop_sdl2_paint(loop);
if (!WINDOW_MANAGER(loop->wm)->animating) {
SDL_Delay(30);
}
}
return RET_OK;

View File

@ -15,7 +15,7 @@ TEST(Canvas, draw_hline) {
canvas_init(&c, lcd, &font_manager);
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
canvas_draw_hline(&c, 10, 20, 100);
@ -59,7 +59,7 @@ TEST(Canvas, draw_vline) {
canvas_init(&c, lcd, &font_manager);
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
canvas_draw_vline(&c, 10, 20, 100);
@ -103,7 +103,7 @@ TEST(Canvas, fill_rect) {
canvas_init(&c, lcd, &font_manager);
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
canvas_fill_rect(&c, 10, 10, 10, 10);
@ -187,7 +187,7 @@ TEST(Canvas, draw_points) {
points[2].x = x3; \
points[2].y = y3;
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
POINTS3(0, 10, 100, 10, 320, 10);
@ -226,7 +226,7 @@ TEST(Canvas, draw_glyph) {
font_manager_add(&font_manager, font_dummy_0("demo0", font_size));
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
canvas_set_font(&c, "demo0", font_size);
lcd_log_reset(lcd);
@ -284,7 +284,7 @@ TEST(Canvas, draw_image) {
img.w = 32;
img.h = 32;
rect_init(r, 100, 100, 200, 200);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(s, 0, 0, img.w, img.h);
@ -356,7 +356,7 @@ TEST(Canvas, draw_image_3patch_x_scale_y) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(d, 0, 0, img.w, img.h);
@ -400,7 +400,7 @@ TEST(Canvas, draw_image_3patch_y_scale_x) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(d, 0, 0, img.w, img.h);
@ -444,7 +444,7 @@ TEST(Canvas, draw_image_9patch) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(d, 0, 0, img.w, img.h);
@ -496,7 +496,7 @@ TEST(Canvas, draw_image_repeat_x) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -541,7 +541,7 @@ TEST(Canvas, draw_image_repeat_y) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -587,7 +587,7 @@ TEST(Canvas, draw_image_repeat) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -634,7 +634,7 @@ TEST(Canvas, draw_image_scale_w) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -678,7 +678,7 @@ TEST(Canvas, draw_image_scale_h) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -722,7 +722,7 @@ TEST(Canvas, draw_image_scale) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);
@ -766,7 +766,7 @@ TEST(Canvas, draw_image_center) {
img.w = 32;
img.h = 32;
rect_init(r, 0, 0, 320, 480);
canvas_begin_frame(&c, &r);
canvas_begin_frame(&c, &r, LCD_DRAW_NORMAL);
lcd_log_reset(lcd);
rect_init(r, 0, 0, img.w, img.h);

View File

@ -66,7 +66,7 @@ TEST(LCDMem, basic) {
canvas_t* c = canvas_init(&canvas, lcd, &font_manager);
ASSERT_EQ(c, &canvas);
ASSERT_EQ(canvas_begin_frame(c, NULL), RET_OK);
ASSERT_EQ(canvas_begin_frame(c, NULL, LCD_DRAW_NORMAL), RET_OK);
test_draw_points(c);
test_fill_rect(c);