mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-01 03:28:53 +08:00
refactor lcd
This commit is contained in:
parent
04c1d29b52
commit
8eb50125dd
@ -146,7 +146,9 @@ static asset_info_t* try_load_image(assets_manager_t* am, const char* name,
|
||||
subpath = "assets/raw/images/svg";
|
||||
break;
|
||||
}
|
||||
default: { return NULL; }
|
||||
default: {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return_value_if_fail(build_path(am, path, MAX_PATH, ratio, subpath, name, extname) == RET_OK,
|
||||
@ -195,7 +197,9 @@ static asset_info_t* try_load_assets(assets_manager_t* am, const char* name, con
|
||||
subpath = "assets/raw/data";
|
||||
break;
|
||||
}
|
||||
default: { return NULL; }
|
||||
default: {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return_value_if_fail(build_path(am, path, MAX_PATH, FALSE, subpath, name, extname) == RET_OK,
|
||||
@ -212,19 +216,19 @@ static uint16_t subtype_from_extname(const char* extname) {
|
||||
uint16_t subtype = 0;
|
||||
return_value_if_fail(extname != NULL, 0);
|
||||
|
||||
if(tk_str_ieq(extname, ".gif")) {
|
||||
if (tk_str_ieq(extname, ".gif")) {
|
||||
subtype = ASSET_TYPE_IMAGE_GIF;
|
||||
} else if(tk_str_ieq(extname, ".png")) {
|
||||
} else if (tk_str_ieq(extname, ".png")) {
|
||||
subtype = ASSET_TYPE_IMAGE_PNG;
|
||||
} else if(tk_str_ieq(extname, ".bmp")) {
|
||||
} else if (tk_str_ieq(extname, ".bmp")) {
|
||||
subtype = ASSET_TYPE_IMAGE_BMP;
|
||||
} else if(tk_str_ieq(extname, ".bsvg")) {
|
||||
} else if (tk_str_ieq(extname, ".bsvg")) {
|
||||
subtype = ASSET_TYPE_IMAGE_BSVG;
|
||||
} else if(tk_str_ieq(extname, ".jpg")) {
|
||||
} else if (tk_str_ieq(extname, ".jpg")) {
|
||||
subtype = ASSET_TYPE_IMAGE_JPG;
|
||||
} else if(tk_str_ieq(extname, ".jpeg")) {
|
||||
} else if (tk_str_ieq(extname, ".jpeg")) {
|
||||
subtype = ASSET_TYPE_IMAGE_JPG;
|
||||
} else if(tk_str_ieq(extname, "ttf")) {
|
||||
} else if (tk_str_ieq(extname, "ttf")) {
|
||||
subtype = ASSET_TYPE_FONT_TTF;
|
||||
} else {
|
||||
log_debug("not supported %s\n", extname);
|
||||
@ -342,7 +346,7 @@ asset_info_t* assets_manager_load_asset(assets_manager_t* am, asset_type_t type,
|
||||
}
|
||||
|
||||
asset_info_t* assets_manager_load(assets_manager_t* am, asset_type_t type, const char* name) {
|
||||
if(strncmp(name, STR_SCHEMA_FILE, strlen(STR_SCHEMA_FILE)) == 0) {
|
||||
if (strncmp(name, STR_SCHEMA_FILE, strlen(STR_SCHEMA_FILE)) == 0) {
|
||||
return assets_manager_load_file(am, type, name + strlen(STR_SCHEMA_FILE));
|
||||
} else {
|
||||
return assets_manager_load_asset(am, type, name);
|
||||
|
@ -45,7 +45,7 @@ BEGIN_C_DECLS
|
||||
* > 本类是一个抽象类,不能进行实例化。请在应用程序中使用具体的类,如image\_t。
|
||||
*
|
||||
* 如果需要显示文件系统中的图片,只需将图片名称换成实际的文件名,并加上"file://"前缀即可。如:
|
||||
*
|
||||
*
|
||||
*```
|
||||
* <image draw_type="center" image="file://./demos/assets/raw/images/xx/flag_CN.png" />
|
||||
* <gif image="file://./demos/assets/raw/images/x2/bee.gif" />
|
||||
@ -114,9 +114,9 @@ typedef struct _image_base_t {
|
||||
/**
|
||||
* @method image_base_set_image
|
||||
* 设置控件的图片名称。
|
||||
*
|
||||
*
|
||||
*> 如果需要显示文件系统中的图片,只需将图片名称换成实际的文件名,并加上"file://"前缀即可。
|
||||
*
|
||||
*
|
||||
* @annotation ["scriptable"]
|
||||
* @param {widget_t*} widget image对象。
|
||||
* @param {char*} name 图片名称,该图片必须存在于资源管理器。
|
||||
|
4
src/base/line_break.c
Executable file → Normal file
4
src/base/line_break.c
Executable file → Normal file
@ -46,7 +46,9 @@ break_type_t line_break_check(wchar_t c1, wchar_t c2) {
|
||||
case LINEBREAK_NOBREAK: {
|
||||
return word_break_check(c1, c2);
|
||||
}
|
||||
default: { return LINE_BREAK_ALLOW; }
|
||||
default: {
|
||||
return LINE_BREAK_ALLOW;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -290,8 +290,8 @@ typedef struct _assets_manager_t assets_manager_t;
|
||||
struct _system_info_t;
|
||||
typedef struct _system_info_t system_info_t;
|
||||
|
||||
#define STR_SCHEMA_FILE "file://"
|
||||
#define STR_SCHEMA_HTTP "http://"
|
||||
#define STR_SCHEMA_FILE "file://"
|
||||
#define STR_SCHEMA_HTTP "http://"
|
||||
#define STR_SCHEMA_HTTPS "https://"
|
||||
|
||||
#endif /*TK_TYPES_DEF_H*/
|
||||
|
231
src/lcd/lcd_mem_special.c
Normal file
231
src/lcd/lcd_mem_special.c
Normal file
@ -0,0 +1,231 @@
|
||||
/**
|
||||
* File: lcd_mem_special.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: lcd_mem_special
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* 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:
|
||||
* ================================================================
|
||||
* 2019-06-17 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tkc/mem.h"
|
||||
#include "lcd/lcd_mem_special.h"
|
||||
#include "lcd/lcd_mem_rgb565.h"
|
||||
#include "lcd/lcd_mem_bgr565.h"
|
||||
#include "lcd/lcd_mem_rgba8888.h"
|
||||
#include "lcd/lcd_mem_bgra8888.h"
|
||||
|
||||
static ret_t lcd_mem_special_begin_frame(lcd_t* lcd, rect_t* dr) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_hline(mem, x, y, w);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_vline(mem, x, y, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_points(mem, points, nr);
|
||||
}
|
||||
|
||||
static color_t lcd_mem_special_get_point_color(lcd_t* lcd, xy_t x, xy_t y) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
|
||||
return lcd_get_point_color(mem, x, y);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_fill_rect(mem, x, y, w, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
mem->text_color = lcd->text_color;
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_draw_glyph(mem, glyph, src, x, y);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_image_matrix(lcd_t* lcd, draw_image_info_t* info) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
|
||||
return lcd_draw_image_matrix(mem, info);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
|
||||
return lcd_draw_image(mem, img, src, dst);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_end_frame(lcd_t* lcd) {
|
||||
if (lcd->draw_mode == LCD_DRAW_OFFLINE) {
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
return lcd_flush(lcd);
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_flush(lcd_t* lcd) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
if (special->on_flush != NULL) {
|
||||
special->on_flush(lcd);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_destroy(lcd_t* lcd) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
lcd_destroy((lcd_t*)(special->lcd_mem));
|
||||
if (special->on_destroy != NULL) {
|
||||
special->on_destroy(lcd);
|
||||
}
|
||||
|
||||
memset(special, 0x00, sizeof(lcd_mem_special_t));
|
||||
TKMEM_FREE(special);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_take_snapshot(lcd_t* lcd, bitmap_t* img, bool_t auto_rotate) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
return lcd_take_snapshot((lcd_t*)(special->lcd_mem), img, auto_rotate);
|
||||
}
|
||||
|
||||
static bitmap_format_t lcd_mem_special_get_desired_bitmap_format(lcd_t* lcd) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
return lcd_get_desired_bitmap_format((lcd_t*)(special->lcd_mem));
|
||||
}
|
||||
|
||||
static vgcanvas_t* lcd_mem_special_get_vgcanvas(lcd_t* lcd) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
return lcd_get_vgcanvas((lcd_t*)(special->lcd_mem));
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_set_global_alpha(lcd_t* lcd, uint8_t alpha) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(special->lcd_mem);
|
||||
|
||||
lcd->global_alpha = alpha;
|
||||
mem->global_alpha = alpha;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static lcd_mem_t* lcd_mem_special_create_lcd_mem(wh_t w, wh_t h, bitmap_format_t fmt) {
|
||||
switch (fmt) {
|
||||
case BITMAP_FMT_RGBA8888: {
|
||||
return (lcd_mem_t*)lcd_mem_rgba8888_create(w, h, TRUE);
|
||||
}
|
||||
case BITMAP_FMT_BGRA8888: {
|
||||
return (lcd_mem_t*)lcd_mem_bgra8888_create(w, h, TRUE);
|
||||
}
|
||||
case BITMAP_FMT_BGR565: {
|
||||
return (lcd_mem_t*)lcd_mem_bgr565_create(w, h, TRUE);
|
||||
}
|
||||
case BITMAP_FMT_RGB565: {
|
||||
return (lcd_mem_t*)lcd_mem_rgb565_create(w, h, TRUE);
|
||||
}
|
||||
default: {
|
||||
log_debug("not supported: w=%d h=%d fmt=%d\n", w, h, fmt);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ret_t lcd_mem_special_resize(lcd_t* lcd, wh_t w, wh_t h, uint32_t line_length) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
return_value_if_fail(special != NULL, RET_BAD_PARAMS);
|
||||
|
||||
lcd_destroy((lcd_t*)(special->lcd_mem));
|
||||
special->lcd_mem = lcd_mem_special_create_lcd_mem(w, h, special->format);
|
||||
|
||||
if (special->on_resize != NULL) {
|
||||
special->on_resize(lcd, w, h, line_length);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
lcd_t* lcd_mem_special_create(wh_t w, wh_t h, bitmap_format_t fmt, lcd_flush_t on_flush,
|
||||
lcd_resize_t on_resize, lcd_destroy_t on_destroy, void* ctx) {
|
||||
lcd_mem_special_t* special = TKMEM_ZALLOC(lcd_mem_special_t);
|
||||
lcd_t* lcd = (lcd_t*)special;
|
||||
return_value_if_fail(special != NULL, NULL);
|
||||
|
||||
memset(special, 0x00, sizeof(lcd_mem_special_t));
|
||||
|
||||
lcd->w = w;
|
||||
lcd->h = h;
|
||||
lcd->ratio = 1;
|
||||
lcd->type = LCD_FRAMEBUFFER;
|
||||
lcd->support_dirty_rect = TRUE;
|
||||
|
||||
special->ctx = ctx;
|
||||
special->format = fmt;
|
||||
special->on_flush = on_flush;
|
||||
special->on_resize = on_resize;
|
||||
special->on_destroy = on_destroy;
|
||||
special->lcd_mem = lcd_mem_special_create_lcd_mem(w, h, fmt);
|
||||
ENSURE(special->lcd_mem != NULL);
|
||||
|
||||
lcd->begin_frame = lcd_mem_special_begin_frame;
|
||||
lcd->draw_vline = lcd_mem_special_draw_vline;
|
||||
lcd->draw_hline = lcd_mem_special_draw_hline;
|
||||
lcd->fill_rect = lcd_mem_special_fill_rect;
|
||||
lcd->draw_image = lcd_mem_special_draw_image;
|
||||
lcd->draw_image_matrix = lcd_mem_special_draw_image_matrix;
|
||||
lcd->draw_glyph = lcd_mem_special_draw_glyph;
|
||||
lcd->draw_points = lcd_mem_special_draw_points;
|
||||
lcd->get_point_color = lcd_mem_special_get_point_color;
|
||||
lcd->end_frame = lcd_mem_special_end_frame;
|
||||
lcd->get_vgcanvas = lcd_mem_special_get_vgcanvas;
|
||||
lcd->take_snapshot = lcd_mem_special_take_snapshot;
|
||||
lcd->set_global_alpha = lcd_mem_special_set_global_alpha;
|
||||
lcd->get_desired_bitmap_format = lcd_mem_special_get_desired_bitmap_format;
|
||||
lcd->resize = lcd_mem_special_resize;
|
||||
lcd->flush = lcd_mem_special_flush;
|
||||
lcd->destroy = lcd_mem_special_destroy;
|
||||
|
||||
return lcd;
|
||||
}
|
47
src/lcd/lcd_mem_special.h
Normal file
47
src/lcd/lcd_mem_special.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* File: lcd_mem_special.h
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: lcd_mem_special
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* 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:
|
||||
* ================================================================
|
||||
* 2019-06-17 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_MEM_SPECIAL_H
|
||||
#define LCD_MEM_SPECIAL_H
|
||||
|
||||
#include "base/lcd.h"
|
||||
#include "lcd/lcd_mem.h"
|
||||
|
||||
BEGIN_C_DECLS
|
||||
|
||||
typedef struct _lcd_mem_special_t {
|
||||
lcd_t base;
|
||||
lcd_mem_t* lcd_mem;
|
||||
bitmap_format_t format;
|
||||
|
||||
/*custom info*/
|
||||
void* ctx;
|
||||
lcd_flush_t on_flush;
|
||||
lcd_resize_t on_resize;
|
||||
lcd_destroy_t on_destroy;
|
||||
} lcd_mem_special_t;
|
||||
|
||||
lcd_t* lcd_mem_special_create(wh_t w, wh_t h, bitmap_format_t fmt, lcd_flush_t on_flush,
|
||||
lcd_resize_t on_resize, lcd_destroy_t on_destroy, void* ctx);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*LCD_MEM_SPECIAL_H*/
|
@ -19,169 +19,105 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "tkc/mem.h"
|
||||
#include "lcd/lcd_sdl2.h"
|
||||
#include "lcd/lcd_mem_bgr565.h"
|
||||
#include "lcd/lcd_mem_bgr888.h"
|
||||
#include "lcd/lcd_mem_bgra8888.h"
|
||||
#include "blend/image_g2d.h"
|
||||
#include "lcd/lcd_mem_special.h"
|
||||
|
||||
typedef struct _lcd_sdl2_t {
|
||||
lcd_t base;
|
||||
typedef struct _special_info_t {
|
||||
SDL_Renderer* render;
|
||||
lcd_mem_t* lcd_mem;
|
||||
SDL_Texture* texture;
|
||||
} lcd_sdl2_t;
|
||||
bitmap_format_t format;
|
||||
} special_info_t;
|
||||
|
||||
static ret_t lcd_sdl2_begin_frame(lcd_t* lcd, rect_t* dr) {
|
||||
int pitch = 0;
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
static special_info_t* special_info_create(SDL_Renderer* render) {
|
||||
special_info_t* info = TKMEM_ZALLOC(special_info_t);
|
||||
return_value_if_fail(info != NULL, NULL);
|
||||
|
||||
SDL_LockTexture(sdl->texture, NULL, (void**)&(sdl->lcd_mem->offline_fb), &pitch);
|
||||
lcd_mem_set_line_length(sdl->lcd_mem, pitch);
|
||||
info->render = render;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static ret_t special_info_create_texture(special_info_t* info, wh_t w, wh_t h) {
|
||||
int flags = SDL_TEXTUREACCESS_STREAMING;
|
||||
|
||||
#ifdef WITH_FB_BGRA8888
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
info->format = BITMAP_FMT_BGRA8888;
|
||||
info->texture = SDL_CreateTexture(info->render, SDL_PIXELFORMAT_ARGB8888, flags, w, h);
|
||||
log_debug("WITH_FB_BGRA8888\n");
|
||||
#else
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
info->format = BITMAP_FMT_BGR565;
|
||||
info->texture = SDL_CreateTexture(info->render, SDL_PIXELFORMAT_RGB565, flags, w, h);
|
||||
log_debug("WITH_FB_BGR565\n");
|
||||
#endif
|
||||
|
||||
return info->texture != NULL ? RET_OK : RET_FAIL;
|
||||
}
|
||||
|
||||
static ret_t special_info_destroy(special_info_t* info) {
|
||||
return_value_if_fail(info != NULL, RET_BAD_PARAMS);
|
||||
|
||||
SDL_DestroyTexture(info->texture);
|
||||
TKMEM_FREE(info);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_hline(lcd_t* lcd, xy_t x, xy_t y, wh_t w) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_hline(mem, x, y, w);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_vline(lcd_t* lcd, xy_t x, xy_t y, wh_t h) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_vline(mem, x, y, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_points(lcd_t* lcd, point_t* points, uint32_t nr) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
mem->stroke_color = lcd->stroke_color;
|
||||
|
||||
return lcd_draw_points(mem, points, nr);
|
||||
}
|
||||
|
||||
static color_t lcd_sdl2_get_point_color(lcd_t* lcd, xy_t x, xy_t y) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
|
||||
return lcd_get_point_color(mem, x, y);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_fill_rect(lcd_t* lcd, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_fill_rect(mem, x, y, w, h);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_glyph(lcd_t* lcd, glyph_t* glyph, rect_t* src, xy_t x, xy_t y) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
mem->text_color = lcd->text_color;
|
||||
mem->fill_color = lcd->fill_color;
|
||||
|
||||
return lcd_draw_glyph(mem, glyph, src, x, y);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_image_matrix(lcd_t* lcd, draw_image_info_t* info) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
|
||||
return lcd_draw_image_matrix(mem, info);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_draw_image(lcd_t* lcd, bitmap_t* img, rect_t* src, rect_t* dst) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
|
||||
return lcd_draw_image(mem, img, src, dst);
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_end_frame(lcd_t* lcd) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
static ret_t lcd_sdl2_flush(lcd_t* lcd) {
|
||||
bitmap_t src;
|
||||
bitmap_t dst;
|
||||
int pitch = 0;
|
||||
void* addr = NULL;
|
||||
rect_t* dr = &(lcd->dirty_rect);
|
||||
rect_t* fps_r = &(lcd->fps_rect);
|
||||
rect_t r = rect_init(0, 0, lcd->w, lcd->h);
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
special_info_t* info = (special_info_t*)(special->ctx);
|
||||
|
||||
memset(&src, 0x00, sizeof(src));
|
||||
memset(&dst, 0x00, sizeof(dst));
|
||||
|
||||
SDL_UnlockTexture(sdl->texture);
|
||||
if ((dr->w > 0 && dr->h > 0) || (fps_r->w > 0 && fps_r->h > 0)) {
|
||||
SDL_Rect sr = {0, 0, lcd->w, lcd->h};
|
||||
|
||||
SDL_RenderCopy(sdl->render, sdl->texture, &sr, &sr);
|
||||
SDL_LockTexture(info->texture, NULL, (void**)&(addr), &pitch);
|
||||
bitmap_init(&dst, lcd->w, lcd->h, special->format, addr);
|
||||
bitmap_set_line_length(&dst, pitch);
|
||||
bitmap_init(&src, lcd->w, lcd->h, special->format, special->lcd_mem->offline_fb);
|
||||
image_copy(&dst, &src, dr, dr->x, dr->y);
|
||||
SDL_UnlockTexture(info->texture);
|
||||
log_debug("dirty_rect: %d %d %d %d\n", dr->x, dr->y, dr->w, dr->h);
|
||||
|
||||
SDL_RenderCopy(info->render, info->texture, &sr, &sr);
|
||||
}
|
||||
|
||||
if (lcd->draw_mode != LCD_DRAW_OFFLINE) {
|
||||
SDL_RenderPresent(sdl->render);
|
||||
SDL_RenderPresent(info->render);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_destroy(lcd_t* lcd) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
|
||||
lcd_destroy((lcd_t*)(sdl->lcd_mem));
|
||||
SDL_DestroyTexture(sdl->texture);
|
||||
memset(sdl, 0x00, sizeof(lcd_sdl2_t));
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_resize(lcd_t* lcd, wh_t w, wh_t h, uint32_t line_length) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
if (w <= sdl->lcd_mem->base.w && h <= sdl->lcd_mem->base.h) return RET_OK;
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
special_info_t* info = (special_info_t*)(special->ctx);
|
||||
|
||||
SDL_DestroyTexture(info->texture);
|
||||
|
||||
info->texture = NULL;
|
||||
special_info_create_texture(info, w, h);
|
||||
|
||||
SDL_DestroyTexture(sdl->texture);
|
||||
sdl->lcd_mem->base.w = w;
|
||||
sdl->lcd_mem->base.h = h;
|
||||
#ifdef WITH_FB_BGRA8888
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
sdl->texture =
|
||||
SDL_CreateTexture(sdl->render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGRA8888\n");
|
||||
#elif defined(WITH_FB_BGR888)
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
sdl->texture =
|
||||
SDL_CreateTexture(sdl->render, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGR888\n");
|
||||
#else
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
sdl->texture =
|
||||
SDL_CreateTexture(sdl->render, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGR565\n");
|
||||
#endif
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_take_snapshot(lcd_t* lcd, bitmap_t* img, bool_t auto_rotate) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
static ret_t lcd_sdl2_destroy(lcd_t* lcd) {
|
||||
lcd_mem_special_t* special = (lcd_mem_special_t*)lcd;
|
||||
|
||||
return lcd_take_snapshot((lcd_t*)(sdl->lcd_mem), img, auto_rotate);
|
||||
}
|
||||
|
||||
static bitmap_format_t lcd_sdl2_get_desired_bitmap_format(lcd_t* lcd) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
|
||||
return lcd_get_desired_bitmap_format((lcd_t*)(sdl->lcd_mem));
|
||||
}
|
||||
|
||||
static vgcanvas_t* lcd_sdl2_get_vgcanvas(lcd_t* lcd) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
|
||||
return lcd_get_vgcanvas((lcd_t*)(sdl->lcd_mem));
|
||||
}
|
||||
|
||||
static ret_t lcd_sdl2_set_global_alpha(lcd_t* lcd, uint8_t alpha) {
|
||||
lcd_sdl2_t* sdl = (lcd_sdl2_t*)lcd;
|
||||
lcd_t* mem = (lcd_t*)(sdl->lcd_mem);
|
||||
|
||||
lcd->global_alpha = alpha;
|
||||
mem->global_alpha = alpha;
|
||||
special_info_destroy((special_info_t*)(special->ctx));
|
||||
special->ctx = NULL;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
@ -189,58 +125,15 @@ static ret_t lcd_sdl2_set_global_alpha(lcd_t* lcd, uint8_t alpha) {
|
||||
lcd_t* lcd_sdl2_init(SDL_Renderer* render) {
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
static lcd_sdl2_t lcd;
|
||||
lcd_t* base = &(lcd.base);
|
||||
special_info_t* info = NULL;
|
||||
return_value_if_fail(render != NULL, NULL);
|
||||
|
||||
memset(&lcd, 0x00, sizeof(lcd_sdl2_t));
|
||||
|
||||
lcd.render = render;
|
||||
base->begin_frame = lcd_sdl2_begin_frame;
|
||||
base->draw_vline = lcd_sdl2_draw_vline;
|
||||
base->draw_hline = lcd_sdl2_draw_hline;
|
||||
base->fill_rect = lcd_sdl2_fill_rect;
|
||||
base->draw_image = lcd_sdl2_draw_image;
|
||||
base->draw_image_matrix = lcd_sdl2_draw_image_matrix;
|
||||
base->draw_glyph = lcd_sdl2_draw_glyph;
|
||||
base->draw_points = lcd_sdl2_draw_points;
|
||||
base->get_point_color = lcd_sdl2_get_point_color;
|
||||
base->end_frame = lcd_sdl2_end_frame;
|
||||
base->get_vgcanvas = lcd_sdl2_get_vgcanvas;
|
||||
base->take_snapshot = lcd_sdl2_take_snapshot;
|
||||
base->get_desired_bitmap_format = lcd_sdl2_get_desired_bitmap_format;
|
||||
base->set_global_alpha = lcd_sdl2_set_global_alpha;
|
||||
base->resize = lcd_sdl2_resize;
|
||||
base->destroy = lcd_sdl2_destroy;
|
||||
|
||||
SDL_GetRendererOutputSize(render, &w, &h);
|
||||
info = special_info_create(render);
|
||||
return_value_if_fail(info != NULL, NULL);
|
||||
|
||||
base->ratio = 1;
|
||||
base->w = (wh_t)w;
|
||||
base->h = (wh_t)h;
|
||||
ENSURE(special_info_create_texture(info, w, h) == RET_OK);
|
||||
|
||||
#ifdef WITH_FB_BGRA8888
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
lcd.lcd_mem = (lcd_mem_t*)lcd_mem_bgra8888_create(w, h, FALSE);
|
||||
lcd.texture =
|
||||
SDL_CreateTexture(render, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGRA8888\n");
|
||||
#elif defined(WITH_FB_BGR888)
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
lcd.lcd_mem = (lcd_mem_t*)lcd_mem_bgr888_create(w, h, FALSE);
|
||||
lcd.texture =
|
||||
SDL_CreateTexture(render, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGR888\n");
|
||||
#else
|
||||
/*SDL ABGR is rgba from low address to high address*/
|
||||
lcd.lcd_mem = (lcd_mem_t*)lcd_mem_bgr565_create(w, h, FALSE);
|
||||
lcd.texture =
|
||||
SDL_CreateTexture(render, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||
log_debug("WITH_FB_BGR565\n");
|
||||
#endif
|
||||
|
||||
base->type = lcd.lcd_mem->base.type;
|
||||
base->support_dirty_rect = FALSE;
|
||||
|
||||
return base;
|
||||
return lcd_mem_special_create(w, h, info->format, lcd_sdl2_flush, lcd_sdl2_resize,
|
||||
lcd_sdl2_destroy, info);
|
||||
}
|
||||
|
@ -229,7 +229,9 @@ ret_t bsvg_draw_path(draw_ctx_t* ctx, const svg_path_t* path) {
|
||||
break;
|
||||
}
|
||||
case SVG_PATH_NULL:
|
||||
default: { break; }
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
|
@ -132,7 +132,9 @@ ret_t bsvg_to_svg_path(str_t* str, const svg_path_t* path) {
|
||||
break;
|
||||
}
|
||||
case SVG_PATH_NULL:
|
||||
default: { break; }
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str_append(str, buff);
|
||||
|
@ -248,7 +248,9 @@ static ret_t svg_path_parser_parse_cmd(svg_path_parser_t* parser, char c) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: { assert(!"not supported path!"); } break;
|
||||
default: {
|
||||
assert(!"not supported path!");
|
||||
} break;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
|
@ -163,7 +163,9 @@ ret_t path_normalize(const char* path, char* result, int32_t size) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: { *d++ = *s++; }
|
||||
default: {
|
||||
*d++ = *s++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,9 @@ bool_t value_bool(const value_t* v) {
|
||||
case VALUE_TYPE_WSTRING: {
|
||||
return tk_watob(v->value.wstr);
|
||||
}
|
||||
default: { return value_int(v) ? TRUE : FALSE; }
|
||||
default: {
|
||||
return value_int(v) ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,7 +450,9 @@ int value_int(const value_t* v) {
|
||||
case VALUE_TYPE_WSTRING: {
|
||||
return tk_watoi(v->value.wstr);
|
||||
}
|
||||
default: { assert(!"not supported type"); }
|
||||
default: {
|
||||
assert(!"not supported type");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -410,7 +410,9 @@ static cairo_surface_t* create_surface(uint32_t w, uint32_t h, bitmap_format_t f
|
||||
cairo_format = CAIRO_FORMAT_RGB16_565;
|
||||
break;
|
||||
}
|
||||
default: { return NULL; }
|
||||
default: {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return cairo_image_surface_create_for_data(fbuff, cairo_format, w, h, w * bpp);
|
||||
|
@ -111,7 +111,9 @@ static int vgcanvas_nanovg_ensure_image(vgcanvas_nanovg_t* canvas, bitmap_t* img
|
||||
f = NVG_TEXTURE_RGB;
|
||||
break;
|
||||
}
|
||||
default: { assert(!"not supported format"); }
|
||||
default: {
|
||||
assert(!"not supported format");
|
||||
}
|
||||
}
|
||||
|
||||
i = nvgCreateImageRaw(canvas->vg, img->w, img->h, f, NVG_IMAGE_NEAREST, img->data);
|
||||
|
Loading…
Reference in New Issue
Block a user