mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-19 20:03:09 +08:00
fix(sdl): fix clipped image drawing (#2992)
* fixed clipped image drawing * make sdl blend mode a feature toggle * improved textarea cursor fidelity * added some comment to config * updated config header * updated formatting
This commit is contained in:
@@ -175,7 +175,10 @@
|
||||
#define LV_USE_GPU_SDL 0
|
||||
#if LV_USE_GPU_SDL
|
||||
#define LV_GPU_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
/*Texture cache size, 8MB by default*/
|
||||
#define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8)
|
||||
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
|
||||
#define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
#endif
|
||||
|
||||
/*-------------
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define HAS_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
@@ -81,7 +80,7 @@ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coor
|
||||
if(!_lv_area_intersect(apply_area, &full_coords, clip_in)) return false;
|
||||
bool has_mask = lv_draw_mask_is_any(apply_area);
|
||||
|
||||
const bool draw_mask = has_mask && HAS_CUSTOM_BLEND_MODE;
|
||||
const bool draw_mask = has_mask && LV_GPU_SDL_CUSTOM_BLEND_MODE;
|
||||
const bool draw_blend = blend_mode != LV_BLEND_MODE_NORMAL;
|
||||
if(draw_mask || draw_blend) {
|
||||
lv_draw_sdl_context_internals_t * internals = ctx->internals;
|
||||
@@ -97,7 +96,7 @@ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coor
|
||||
SDL_SetRenderTarget(ctx->renderer, internals->composition);
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 255, 255, 255, 0);
|
||||
SDL_RenderClear(ctx->renderer);
|
||||
#if HAS_CUSTOM_BLEND_MODE
|
||||
#if LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
internals->mask = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0, w, h);
|
||||
dump_masks(internals->mask, apply_area);
|
||||
#endif
|
||||
@@ -126,7 +125,7 @@ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_
|
||||
{
|
||||
lv_draw_sdl_context_internals_t * internals = ctx->internals;
|
||||
SDL_Rect src_rect = {0, 0, lv_area_get_width(apply_area), lv_area_get_height(apply_area)};
|
||||
#if HAS_CUSTOM_BLEND_MODE
|
||||
#if LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
if(internals->mask) {
|
||||
SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE,
|
||||
SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO,
|
||||
@@ -149,7 +148,7 @@ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_
|
||||
case LV_BLEND_MODE_ADDITIVE:
|
||||
SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_ADD);
|
||||
break;
|
||||
#if HAS_CUSTOM_BLEND_MODE
|
||||
#if LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
case LV_BLEND_MODE_SUBTRACTIVE: {
|
||||
SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE,
|
||||
SDL_BLENDOPERATION_SUBTRACT, SDL_BLENDFACTOR_ONE,
|
||||
|
||||
@@ -128,7 +128,7 @@ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t
|
||||
h = header->rect.h;
|
||||
}
|
||||
SDL_IntersectRect(&clip_rect, &coords_rect, &clipped_dst);
|
||||
clipped_src.x = header->rect.x + (clipped_dst.x - coords_rect.x) * w / coords_rect.x;
|
||||
clipped_src.x = header->rect.x + (clipped_dst.x - coords_rect.x) * w / coords_rect.w;
|
||||
clipped_src.y = header->rect.y + (clipped_dst.y - coords_rect.y) * h / coords_rect.h;
|
||||
clipped_src.w = w - (coords_rect.w - clipped_dst.w) * w / coords_rect.w;
|
||||
clipped_src.h = h - (coords_rect.h - clipped_dst.h) * h / coords_rect.h;
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define HAS_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
#ifndef HAVE_SDL_CUSTOM_BLEND_MODE
|
||||
#define HAVE_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
#endif
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
|
||||
@@ -423,8 +423,8 @@ static void draw_border_generic(lv_draw_sdl_ctx_t * ctx, const lv_area_t * outer
|
||||
lv_coord_t frag_size = LV_MAX(radius, max_side);
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
if(texture == NULL) {
|
||||
/* Create a mask texture with size of (frag_size * 2 + 1) */
|
||||
const lv_area_t frag_area = {0, 0, frag_size * 2, frag_size * 2};
|
||||
/* Create a mask texture with size of (frag_size * 2 + 3) */
|
||||
const lv_area_t frag_area = {0, 0, frag_size * 2 + 2, frag_size * 2 + 2};
|
||||
|
||||
/*Create mask for the outer area*/
|
||||
int16_t mask_ids[2] = {LV_MASK_ID_INV, LV_MASK_ID_INV};
|
||||
@@ -493,7 +493,7 @@ static void frag_render_corners(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
if(full) {
|
||||
lv_coord_t sx = (lv_coord_t)(dst_area.x1 - corner_area.x1),
|
||||
sy = (lv_coord_t)(dst_area.y1 - corner_area.y1);
|
||||
SDL_Rect src_rect = {frag_size + 1 + sx, sy, dw, dh};
|
||||
SDL_Rect src_rect = {frag_size + 3 + sx, sy, dw, dh};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -512,7 +512,7 @@ static void frag_render_corners(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
if(full) {
|
||||
lv_coord_t sx = (lv_coord_t)(dst_area.x1 - corner_area.x1),
|
||||
sy = (lv_coord_t)(dst_area.y1 - corner_area.y1);
|
||||
SDL_Rect src_rect = {frag_size + 1 + sx, frag_size + 1 + sy, dw, dh};
|
||||
SDL_Rect src_rect = {frag_size + 3 + sx, frag_size + 3 + sy, dw, dh};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -531,7 +531,7 @@ static void frag_render_corners(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
if(full) {
|
||||
lv_coord_t sx = (lv_coord_t)(dst_area.x1 - corner_area.x1),
|
||||
sy = (lv_coord_t)(dst_area.y1 - corner_area.y1);
|
||||
SDL_Rect src_rect = {sx, frag_size + 1 + sy, dw, dh};
|
||||
SDL_Rect src_rect = {sx, frag_size + 3 + sy, dw, dh};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -556,7 +556,7 @@ static void frag_render_borders(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
|
||||
lv_coord_t sy = (lv_coord_t)(dst_area.y1 - border_area.y1);
|
||||
if(full) {
|
||||
SDL_Rect src_rect = {frag_size, sy, 1, lv_area_get_height(&dst_area)};
|
||||
SDL_Rect src_rect = {frag_size + 1, sy, 1, lv_area_get_height(&dst_area)};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -574,7 +574,7 @@ static void frag_render_borders(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
lv_coord_t dh = lv_area_get_height(&dst_area);
|
||||
if(full) {
|
||||
lv_coord_t sy = (lv_coord_t)(dst_area.y1 - border_area.y1);
|
||||
SDL_Rect src_rect = {frag_size, frag_size + 1 + sy, 1, dh};
|
||||
SDL_Rect src_rect = {frag_size + 1, frag_size + 3 + sy, 1, dh};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -595,7 +595,7 @@ static void frag_render_borders(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
lv_coord_t dw = lv_area_get_width(&dst_area);
|
||||
lv_coord_t sx = (lv_coord_t)(dst_area.x1 - border_area.x1);
|
||||
if(full) {
|
||||
SDL_Rect src_rect = {sx, frag_size, dw, 1};
|
||||
SDL_Rect src_rect = {sx, frag_size + 1, dw, 1};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -613,7 +613,7 @@ static void frag_render_borders(SDL_Renderer * renderer, SDL_Texture * frag, lv_
|
||||
lv_coord_t dw = lv_area_get_width(&dst_area);
|
||||
if(full) {
|
||||
lv_coord_t sx = (lv_coord_t)(dst_area.x1 - border_area.x1);
|
||||
SDL_Rect src_rect = {frag_size + 1 + sx, frag_size, dw, 1};
|
||||
SDL_Rect src_rect = {frag_size + 3 + sx, frag_size + 1, dw, 1};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -430,6 +430,7 @@
|
||||
#define LV_GPU_SDL_INCLUDE_PATH <SDL2/SDL.h>
|
||||
#endif
|
||||
#endif
|
||||
/*Texture cache size, 8MB by default*/
|
||||
#ifndef LV_GPU_SDL_LRU_SIZE
|
||||
#ifdef CONFIG_LV_GPU_SDL_LRU_SIZE
|
||||
#define LV_GPU_SDL_LRU_SIZE CONFIG_LV_GPU_SDL_LRU_SIZE
|
||||
@@ -437,6 +438,14 @@
|
||||
#define LV_GPU_SDL_LRU_SIZE (1024 * 1024 * 8)
|
||||
#endif
|
||||
#endif
|
||||
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
|
||||
#ifndef LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
#ifdef CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
#define LV_GPU_SDL_CUSTOM_BLEND_MODE CONFIG_LV_GPU_SDL_CUSTOM_BLEND_MODE
|
||||
#else
|
||||
#define LV_GPU_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-------------
|
||||
|
||||
Reference in New Issue
Block a user