1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-14 06:42:58 +08:00

fix(SDL): fix typos and other minor issues (#3517)

* fix(sdl): wrong coords for transformed backgrounds

* fix(sdl): fixed typo

* fix(sdl): fixed typo
This commit is contained in:
Mariotaku 2022-07-26 04:00:48 +09:00 committed by GitHub
parent efa34d00d7
commit 03b04a45b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 53 additions and 35 deletions

View File

@ -191,11 +191,11 @@
/*Use SDL renderer API*/
#define LV_USE_DRAW_SDL 0
#if LV_USE_DRAW_SDL
#define LV_DARW_SDL_INCLUDE_PATH <SDL2/SDL.h>
#define LV_DRAW_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Texture cache size, 8MB by default*/
#define LV_DARW_SDL_LRU_SIZE (1024 * 1024 * 8)
#define LV_DRAW_SDL_LRU_SIZE (1024 * 1024 * 8)
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
#define LV_DARW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#define LV_DRAW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#endif
/*-------------

View File

@ -149,11 +149,11 @@
/*Use SDL renderer API*/
#define LV_USE_DRAW_SDL 0
#if LV_USE_DRAW_SDL
#define LV_DARW_SDL_INCLUDE_PATH <SDL2/SDL.h>
#define LV_DRAW_SDL_INCLUDE_PATH <SDL2/SDL.h>
/*Texture cache size, 8MB by default*/
#define LV_DARW_SDL_LRU_SIZE (1024 * 1024 * 8)
#define LV_DRAW_SDL_LRU_SIZE (1024 * 1024 * 8)
/*Custom blend mode for mask drawing, disable if you need to link with older SDL2 lib*/
#define LV_DARW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#define LV_DRAW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#endif
/*=====================

View File

@ -18,7 +18,7 @@ extern "C" {
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "../lv_draw.h"
#include "../../core/lv_disp.h"

View File

@ -79,7 +79,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 && LV_DARW_SDL_CUSTOM_BLEND_MODE;
const bool draw_mask = has_mask && LV_DRAW_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;
@ -96,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 LV_DARW_SDL_CUSTOM_BLEND_MODE
#if LV_DRAW_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
@ -125,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 LV_DARW_SDL_CUSTOM_BLEND_MODE
#if LV_DRAW_SDL_CUSTOM_BLEND_MODE
if(internals->mask) {
SDL_BlendMode mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE,
SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_ZERO,
@ -148,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_SetTextureBlendMode(internals->composition, SDL_BLENDMODE_ADD);
break;
#if LV_DARW_SDL_CUSTOM_BLEND_MODE
#if LV_DRAW_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,

View File

@ -16,7 +16,7 @@ extern "C" {
#include "../../lv_conf_internal.h"
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "lv_draw_sdl.h"
#include "../../misc/lv_area.h"

View File

@ -398,7 +398,7 @@ static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Textur
SDL_SetTextureAlphaMod(texture, 0xFF);
SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
#if LV_DARW_SDL_CUSTOM_BLEND_MODE
#if LV_DRAW_SDL_CUSTOM_BLEND_MODE
SDL_BlendMode blend_mode = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO,
SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_DST_ALPHA,
SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD);

View File

@ -18,7 +18,7 @@ extern "C" {
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "../lv_draw.h"

View File

@ -11,7 +11,7 @@
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "../lv_draw_label.h"
#include "../../misc/lv_utils.h"

View File

@ -16,7 +16,7 @@ extern "C" {
#include "../../lv_conf_internal.h"
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "lv_draw_sdl.h"
#include "../../misc/lv_area.h"

View File

@ -18,7 +18,7 @@ extern "C" {
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "../lv_draw.h"
#include "../../misc/lv_lru.h"

View File

@ -297,7 +297,12 @@ static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
label_draw_dsc.font = dsc->bg_img_symbol_font;
label_draw_dsc.color = dsc->bg_img_recolor;
label_draw_dsc.opa = dsc->bg_img_opa;
/* Reset transform state temporarilly, so the label will be drawn in desinated position */
uint8_t transform_count = ctx->internals->transform_count;
ctx->internals->transform_count = 0;
lv_draw_label((lv_draw_ctx_t *) ctx, &label_draw_dsc, &a, dsc->bg_img_src, NULL);
ctx->internals->transform_count = transform_count;
}
else {
lv_img_header_t header;
@ -340,7 +345,12 @@ static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
area.x2 = area.x1 + header.w - 1;
area.y2 = area.y1 + header.h - 1;
/* Reset transform state temporarilly, so the image will be drawn in desinated position */
uint8_t transform_count = ctx->internals->transform_count;
ctx->internals->transform_count = 0;
lv_draw_img((lv_draw_ctx_t *) ctx, &img_dsc, &area, dsc->bg_img_src);
ctx->internals->transform_count = transform_count;
}
else {
lv_area_t area;
@ -351,9 +361,14 @@ static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
area.x1 = coords->x1;
area.x2 = area.x1 + header.w - 1;
/* Reset transform state temporarilly, so the image will be drawn in desinated position */
uint8_t transform_count = ctx->internals->transform_count;
ctx->internals->transform_count = 0;
for(; area.x1 <= coords->x2; area.x1 += header.w, area.x2 += header.w) {
lv_draw_img((lv_draw_ctx_t *) ctx, &img_dsc, &area, dsc->bg_img_src);
}
ctx->internals->transform_count = transform_count;
}
}
@ -452,9 +467,12 @@ static void draw_border(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
lv_coord_t coords_w = lv_area_get_width(coords), coords_h = lv_area_get_height(coords);
lv_coord_t short_side = LV_MIN(coords_w, coords_h);
lv_coord_t rout = LV_MIN(dsc->radius, short_side / 2);/*Get the inner area*/
lv_coord_t rout = LV_MIN(dsc->radius, short_side / 2);
/*Get the inner area*/
lv_area_t area_inner;
lv_area_copy(&area_inner, coords);// lv_area_increase(&area_inner, 1, 1);
lv_area_copy(&area_inner, coords);
area_inner.x1 += ((dsc->border_side & LV_BORDER_SIDE_LEFT) ? dsc->border_width : -(dsc->border_width + rout));
area_inner.x2 -= ((dsc->border_side & LV_BORDER_SIDE_RIGHT) ? dsc->border_width : -(dsc->border_width + rout));
area_inner.y1 += ((dsc->border_side & LV_BORDER_SIDE_TOP) ? dsc->border_width : -(dsc->border_width + rout));

View File

@ -18,7 +18,7 @@ extern "C" {
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "../lv_draw.h"

View File

@ -56,7 +56,7 @@ static draw_cache_value_t * draw_cache_get_entry(lv_draw_sdl_ctx_t * ctx, const
void lv_draw_sdl_texture_cache_init(lv_draw_sdl_ctx_t * ctx)
{
ctx->internals->texture_cache = lv_lru_create(LV_DARW_SDL_LRU_SIZE, 65536,
ctx->internals->texture_cache = lv_lru_create(LV_DRAW_SDL_LRU_SIZE, 65536,
(lv_lru_free_t *) draw_cache_free_value, NULL);
}

View File

@ -18,7 +18,7 @@ extern "C" {
#if LV_USE_DRAW_SDL
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
#include "lv_draw_sdl.h"
#include "lv_draw_sdl_priv.h"
#include "../../draw/lv_img_decoder.h"

View File

@ -20,7 +20,7 @@ extern "C" {
#include "../../misc/lv_color.h"
#include "../../misc/lv_area.h"
#include LV_DARW_SDL_INCLUDE_PATH
#include LV_DRAW_SDL_INCLUDE_PATH
/*********************
* DEFINES

View File

@ -433,27 +433,27 @@
#endif
#endif
#if LV_USE_DRAW_SDL
#ifndef LV_DARW_SDL_INCLUDE_PATH
#ifdef CONFIG_LV_DARW_SDL_INCLUDE_PATH
#define LV_DARW_SDL_INCLUDE_PATH CONFIG_LV_DARW_SDL_INCLUDE_PATH
#ifndef LV_DRAW_SDL_INCLUDE_PATH
#ifdef CONFIG_LV_DRAW_SDL_INCLUDE_PATH
#define LV_DRAW_SDL_INCLUDE_PATH CONFIG_LV_DRAW_SDL_INCLUDE_PATH
#else
#define LV_DARW_SDL_INCLUDE_PATH <SDL2/SDL.h>
#define LV_DRAW_SDL_INCLUDE_PATH <SDL2/SDL.h>
#endif
#endif
/*Texture cache size, 8MB by default*/
#ifndef LV_DARW_SDL_LRU_SIZE
#ifdef CONFIG_LV_DARW_SDL_LRU_SIZE
#define LV_DARW_SDL_LRU_SIZE CONFIG_LV_DARW_SDL_LRU_SIZE
#ifndef LV_DRAW_SDL_LRU_SIZE
#ifdef CONFIG_LV_DRAW_SDL_LRU_SIZE
#define LV_DRAW_SDL_LRU_SIZE CONFIG_LV_DRAW_SDL_LRU_SIZE
#else
#define LV_DARW_SDL_LRU_SIZE (1024 * 1024 * 8)
#define LV_DRAW_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_DARW_SDL_CUSTOM_BLEND_MODE
#ifdef CONFIG_LV_DARW_SDL_CUSTOM_BLEND_MODE
#define LV_DARW_SDL_CUSTOM_BLEND_MODE CONFIG_LV_DARW_SDL_CUSTOM_BLEND_MODE
#ifndef LV_DRAW_SDL_CUSTOM_BLEND_MODE
#ifdef CONFIG_LV_DRAW_SDL_CUSTOM_BLEND_MODE
#define LV_DRAW_SDL_CUSTOM_BLEND_MODE CONFIG_LV_DRAW_SDL_CUSTOM_BLEND_MODE
#else
#define LV_DARW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#define LV_DRAW_SDL_CUSTOM_BLEND_MODE (SDL_VERSION_ATLEAST(2, 0, 6))
#endif
#endif
#endif