Update lvgl to v8.4.0
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
|
||||
#include "../../lv_conf_internal.h"
|
||||
|
||||
#if LV_USE_GPU_SDL
|
||||
@@ -15,6 +14,7 @@
|
||||
#include "lv_draw_sdl.h"
|
||||
#include "lv_draw_sdl_utils.h"
|
||||
#include "lv_draw_sdl_texture_cache.h"
|
||||
#include "lv_draw_sdl_layer.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -69,6 +69,10 @@ void lv_draw_sdl_init_ctx(lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx)
|
||||
draw_ctx->draw_arc = lv_draw_sdl_draw_arc;
|
||||
draw_ctx->draw_polygon = lv_draw_sdl_polygon;
|
||||
draw_ctx->draw_bg = lv_draw_sdl_draw_bg;
|
||||
draw_ctx->layer_init = lv_draw_sdl_layer_init;
|
||||
draw_ctx->layer_blend = lv_draw_sdl_layer_blend;
|
||||
draw_ctx->layer_destroy = lv_draw_sdl_layer_destroy;
|
||||
draw_ctx->layer_instance_size = sizeof(lv_draw_sdl_layer_ctx_t);
|
||||
lv_draw_sdl_ctx_t * draw_ctx_sdl = (lv_draw_sdl_ctx_t *) draw_ctx;
|
||||
draw_ctx_sdl->renderer = ((lv_draw_sdl_drv_param_t *) disp_drv->user_data)->renderer;
|
||||
draw_ctx_sdl->internals = lv_mem_alloc(sizeof(lv_draw_sdl_context_internals_t));
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef LV_DRAW_SDL_H
|
||||
#define LV_DRAW_SDL_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@ CSRCS += lv_draw_sdl_rect.c
|
||||
CSRCS += lv_draw_sdl_stack_blur.c
|
||||
CSRCS += lv_draw_sdl_texture_cache.c
|
||||
CSRCS += lv_draw_sdl_utils.c
|
||||
CSRCS += lv_draw_sdl_layer.c
|
||||
|
||||
DEPPATH += --dep-path $(LVGL_DIR)/$(LVGL_DIR_NAME)/src/draw/sdl
|
||||
VPATH += :$(LVGL_DIR)/$(LVGL_DIR_NAME)/src/draw/sdl
|
||||
|
||||
@@ -67,7 +67,6 @@ void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * ds
|
||||
area_in.x2 -= dsc->width;
|
||||
area_in.y2 -= dsc->width;
|
||||
|
||||
|
||||
while(start_angle >= 360) start_angle -= 360;
|
||||
while(end_angle >= 360) end_angle -= 360;
|
||||
|
||||
@@ -104,7 +103,9 @@ void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * ds
|
||||
}
|
||||
|
||||
lv_coord_t w = lv_area_get_width(&draw_area), h = lv_area_get_height(&draw_area);
|
||||
SDL_Texture * texture = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, w, h);
|
||||
bool texture_cached = false;
|
||||
SDL_Texture * texture = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, w, h,
|
||||
&texture_cached);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
dump_masks(texture, &draw_area, mask_ids, mask_ids_count, cap_ids[0] != LV_MASK_ID_INV ? cap_ids : NULL);
|
||||
|
||||
@@ -135,6 +136,11 @@ void lv_draw_sdl_draw_arc(lv_draw_ctx_t * draw_ctx, const lv_draw_arc_dsc_t * ds
|
||||
SDL_SetTextureColorMod(texture, color.r, color.g, color.b);
|
||||
SDL_SetTextureAlphaMod(texture, dsc->opa);
|
||||
SDL_RenderCopy(ctx->renderer, texture, &srcrect, &dstrect);
|
||||
|
||||
if(!texture_cached) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#include "../../misc/lv_gc.h"
|
||||
#include "../../core/lv_refr.h"
|
||||
#include "lv_draw_sdl_composite.h"
|
||||
#include "lv_draw_sdl_mask.h"
|
||||
#include "lv_draw_sdl_utils.h"
|
||||
#include "lv_draw_sdl_priv.h"
|
||||
#include "lv_draw_sdl_texture_cache.h"
|
||||
@@ -84,20 +83,26 @@ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coor
|
||||
const bool draw_blend = blend_mode != LV_BLEND_MODE_NORMAL;
|
||||
if(draw_mask || draw_blend) {
|
||||
lv_draw_sdl_context_internals_t * internals = ctx->internals;
|
||||
LV_ASSERT(internals->mask == NULL && internals->composition == NULL);
|
||||
LV_ASSERT(internals->mask == NULL && internals->composition == NULL && internals->target_backup == NULL);
|
||||
|
||||
lv_coord_t w = lv_area_get_width(apply_area), h = lv_area_get_height(apply_area);
|
||||
internals->composition = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0, w, h);
|
||||
/* Don't need to worry about overflow */
|
||||
internals->composition = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0, w, h,
|
||||
&internals->composition_cached);
|
||||
/* Don't need to worry about integral overflow */
|
||||
lv_coord_t ofs_x = (lv_coord_t) - apply_area->x1, ofs_y = (lv_coord_t) - apply_area->y1;
|
||||
/* Offset draw area to start with (0,0) of coords */
|
||||
lv_area_move(coords_out, ofs_x, ofs_y);
|
||||
lv_area_move(clip_out, ofs_x, ofs_y);
|
||||
internals->target_backup = SDL_GetRenderTarget(ctx->renderer);
|
||||
SDL_SetRenderTarget(ctx->renderer, internals->composition);
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 255, 255, 255, 0);
|
||||
SDL_RenderClear(ctx->renderer);
|
||||
/* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
|
||||
SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
|
||||
SDL_RenderFillRect(ctx->renderer, NULL);
|
||||
SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
|
||||
#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);
|
||||
internals->mask = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM0, w, h,
|
||||
&internals->composition_cached);
|
||||
dump_masks(internals->mask, apply_area);
|
||||
#endif
|
||||
}
|
||||
@@ -140,7 +145,7 @@ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_
|
||||
SDL_Rect dst_rect;
|
||||
lv_area_to_sdl_rect(apply_area, &dst_rect);
|
||||
|
||||
SDL_SetRenderTarget(ctx->renderer, ctx->base_draw.buf);
|
||||
SDL_SetRenderTarget(ctx->renderer, internals->target_backup);
|
||||
switch(blend_mode) {
|
||||
case LV_BLEND_MODE_NORMAL:
|
||||
SDL_SetTextureBlendMode(internals->composition, SDL_BLENDMODE_BLEND);
|
||||
@@ -171,29 +176,47 @@ void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_
|
||||
break;
|
||||
}
|
||||
SDL_RenderCopy(ctx->renderer, internals->composition, &src_rect, &dst_rect);
|
||||
if(!internals->composition_cached) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(internals->composition);
|
||||
}
|
||||
}
|
||||
|
||||
internals->mask = internals->composition = NULL;
|
||||
internals->mask = internals->composition = internals->target_backup = NULL;
|
||||
}
|
||||
|
||||
SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id,
|
||||
lv_coord_t w, lv_coord_t h)
|
||||
lv_coord_t w, lv_coord_t h, bool * texture_in_cache)
|
||||
{
|
||||
lv_point_t * tex_size = NULL;
|
||||
composite_key_t mask_key = mask_key_create(id);
|
||||
SDL_Texture * result = lv_draw_sdl_texture_cache_get_with_userdata(ctx, &mask_key, sizeof(composite_key_t), NULL,
|
||||
(void **) &tex_size);
|
||||
if(!result || tex_size->x < w || tex_size->y < h) {
|
||||
if(result == NULL || tex_size->x < w || tex_size->y < h) {
|
||||
lv_coord_t size = next_pow_of_2(LV_MAX(w, h));
|
||||
int access = SDL_TEXTUREACCESS_STREAMING;
|
||||
if(id >= LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0) {
|
||||
if(id >= LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0) {
|
||||
access = SDL_TEXTUREACCESS_TARGET;
|
||||
}
|
||||
else if(id >= LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0) {
|
||||
access = SDL_TEXTUREACCESS_TARGET;
|
||||
}
|
||||
result = SDL_CreateTexture(ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, access, size, size);
|
||||
tex_size = lv_mem_alloc(sizeof(lv_point_t));
|
||||
tex_size->x = tex_size->y = size;
|
||||
lv_draw_sdl_texture_cache_put_advanced(ctx, &mask_key, sizeof(composite_key_t), result, tex_size, lv_mem_free, 0);
|
||||
bool in_cache = lv_draw_sdl_texture_cache_put_advanced(ctx, &mask_key, sizeof(composite_key_t), result,
|
||||
tex_size, lv_mem_free, 0);
|
||||
if(!in_cache) {
|
||||
lv_mem_free(tex_size);
|
||||
}
|
||||
if(texture_in_cache != NULL) {
|
||||
*texture_in_cache = in_cache;
|
||||
}
|
||||
}
|
||||
else if(texture_in_cache != NULL) {
|
||||
*texture_in_cache = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ typedef enum lv_draw_sdl_composite_texture_id_t {
|
||||
LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1,
|
||||
LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET0,
|
||||
LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TARGET1,
|
||||
LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0,
|
||||
} lv_draw_sdl_composite_texture_id_t;
|
||||
|
||||
/**********************
|
||||
@@ -44,6 +45,7 @@ typedef enum lv_draw_sdl_composite_texture_id_t {
|
||||
/**
|
||||
* Begin drawing with mask. Render target will be switched to a temporary texture,
|
||||
* and drawing coordinates may get clipped or translated
|
||||
* @param ctx Drawing context
|
||||
* @param coords_in Original coordinates
|
||||
* @param clip_in Original clip area
|
||||
* @param extension Useful for shadows or outlines, can be NULL
|
||||
@@ -58,8 +60,18 @@ bool lv_draw_sdl_composite_begin(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coor
|
||||
|
||||
void lv_draw_sdl_composite_end(lv_draw_sdl_ctx_t * ctx, const lv_area_t * apply_area, lv_blend_mode_t blend_mode);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ctx Drawing context
|
||||
* @param id Texture ID
|
||||
* @param w Maximum width needed
|
||||
* @param h Maximum height needed
|
||||
* @param texture_in_cache output to query if the texture is in cache. If it's not in cache, you'll need to destroy it
|
||||
* by yourself
|
||||
* @return Obtained texture
|
||||
*/
|
||||
SDL_Texture * lv_draw_sdl_composite_texture_obtain(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_composite_texture_id_t id,
|
||||
lv_coord_t w, lv_coord_t h);
|
||||
lv_coord_t w, lv_coord_t h, bool * texture_in_cache);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "lv_draw_sdl_texture_cache.h"
|
||||
#include "lv_draw_sdl_composite.h"
|
||||
#include "lv_draw_sdl_rect.h"
|
||||
#include "lv_draw_sdl_layer.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -71,7 +72,8 @@ static void draw_img_rounded(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, con
|
||||
lv_coord_t radius);
|
||||
|
||||
static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture,
|
||||
const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius);
|
||||
const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius,
|
||||
bool * in_cache);
|
||||
|
||||
static lv_draw_img_rounded_key_t rounded_key_create(const SDL_Texture * texture, lv_coord_t w, lv_coord_t h,
|
||||
lv_coord_t radius);
|
||||
@@ -86,7 +88,6 @@ static void calc_draw_part(SDL_Texture * texture, const lv_draw_sdl_img_header_t
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
static void apply_recolor_opa(SDL_Texture * texture, const lv_draw_img_dsc_t * draw_dsc);
|
||||
|
||||
/**********************
|
||||
@@ -105,11 +106,16 @@ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t
|
||||
lv_draw_sdl_img_header_t * header = NULL;
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get_with_userdata(ctx, key, key_size, &texture_found,
|
||||
(void **) &header);
|
||||
bool texture_in_cache = false;
|
||||
if(!texture_found) {
|
||||
lv_draw_sdl_img_load_texture(ctx, key, key_size, src, draw_dsc->frame_id, &texture, &header);
|
||||
lv_draw_sdl_img_load_texture(ctx, key, key_size, src, draw_dsc->frame_id, &texture, &header,
|
||||
&texture_in_cache);
|
||||
}
|
||||
else {
|
||||
texture_in_cache = true;
|
||||
}
|
||||
SDL_free(key);
|
||||
if(!texture) {
|
||||
if(!texture || !header) {
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
@@ -123,11 +129,15 @@ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t
|
||||
/* Coords will be translated so coords will start at (0,0) */
|
||||
lv_area_t t_coords = zoomed_cords, t_clip = *clip, apply_area;
|
||||
|
||||
bool has_composite = false;
|
||||
|
||||
if(!check_mask_simple_radius(&t_coords, &radius)) {
|
||||
lv_draw_sdl_composite_begin(ctx, &zoomed_cords, clip, NULL, draw_dsc->blend_mode,
|
||||
&t_coords, &t_clip, &apply_area);
|
||||
has_composite = lv_draw_sdl_composite_begin(ctx, &zoomed_cords, clip, NULL, draw_dsc->blend_mode,
|
||||
&t_coords, &t_clip, &apply_area);
|
||||
}
|
||||
|
||||
lv_draw_sdl_transform_areas_offset(ctx, has_composite, &apply_area, &t_coords, &t_clip);
|
||||
|
||||
SDL_Rect clip_rect, coords_rect;
|
||||
lv_area_to_sdl_rect(&t_clip, &clip_rect);
|
||||
lv_area_to_sdl_rect(&t_coords, &coords_rect);
|
||||
@@ -143,6 +153,14 @@ lv_res_t lv_draw_sdl_img_core(lv_draw_ctx_t * draw_ctx, const lv_draw_img_dsc_t
|
||||
|
||||
lv_draw_sdl_composite_end(ctx, &apply_area, draw_dsc->blend_mode);
|
||||
|
||||
if(!texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
if(!header->managed) {
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
lv_mem_free(header);
|
||||
}
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
@@ -180,7 +198,7 @@ static void calc_draw_part(SDL_Texture * texture, const lv_draw_sdl_img_header_t
|
||||
|
||||
bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size,
|
||||
const void * src, int32_t frame_id, SDL_Texture ** texture,
|
||||
lv_draw_sdl_img_header_t ** header)
|
||||
lv_draw_sdl_img_header_t ** header, bool * texture_in_cache)
|
||||
{
|
||||
_lv_img_cache_entry_t * cdsc = _lv_img_cache_open(src, lv_color_white(), frame_id);
|
||||
lv_draw_sdl_cache_flag_t tex_flags = 0;
|
||||
@@ -205,16 +223,18 @@ bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key
|
||||
#endif
|
||||
}
|
||||
if(texture && cdsc) {
|
||||
*header = SDL_malloc(sizeof(lv_draw_sdl_img_header_t));
|
||||
*header = lv_mem_alloc(sizeof(lv_draw_sdl_img_header_t));
|
||||
SDL_memcpy(&(*header)->base, &cdsc->dec_dsc.header, sizeof(lv_img_header_t));
|
||||
(*header)->rect = rect;
|
||||
lv_draw_sdl_texture_cache_put_advanced(ctx, key, key_size, *texture, *header, SDL_free, tex_flags);
|
||||
(*header)->managed = (tex_flags & LV_DRAW_SDL_CACHE_FLAG_MANAGED) != 0;
|
||||
*texture_in_cache = lv_draw_sdl_texture_cache_put_advanced(ctx, key, key_size, *texture, *header, SDL_free,
|
||||
tex_flags);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
lv_draw_sdl_texture_cache_put(ctx, key, key_size, NULL);
|
||||
*texture_in_cache = lv_draw_sdl_texture_cache_put(ctx, key, key_size, NULL);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**********************
|
||||
@@ -308,14 +328,14 @@ static void draw_img_simple(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, cons
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_img_rounded(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, const lv_draw_sdl_img_header_t * header,
|
||||
const lv_draw_img_dsc_t * draw_dsc, const lv_area_t * coords, const lv_area_t * clip,
|
||||
lv_coord_t radius)
|
||||
{
|
||||
const int w = lv_area_get_width(coords), h = lv_area_get_height(coords);
|
||||
lv_coord_t real_radius = LV_MIN3(radius, w, h);
|
||||
SDL_Texture * frag = img_rounded_frag_obtain(ctx, texture, header, w, h, real_radius);
|
||||
bool frag_in_cache = false;
|
||||
SDL_Texture * frag = img_rounded_frag_obtain(ctx, texture, header, w, h, real_radius, &frag_in_cache);
|
||||
apply_recolor_opa(frag, draw_dsc);
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, frag, real_radius, coords, clip, true);
|
||||
|
||||
@@ -355,6 +375,11 @@ static void draw_img_rounded(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture, con
|
||||
SDL_RenderCopy(ctx->renderer, texture, &src_rect, &dst_rect);
|
||||
}
|
||||
SDL_RenderSetClipRect(ctx->renderer, NULL);
|
||||
|
||||
if(!frag_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(frag);
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_recolor_opa(SDL_Texture * texture, const lv_draw_img_dsc_t * draw_dsc)
|
||||
@@ -372,22 +397,28 @@ static void apply_recolor_opa(SDL_Texture * texture, const lv_draw_img_dsc_t * d
|
||||
}
|
||||
|
||||
static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Texture * texture,
|
||||
const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius)
|
||||
const lv_draw_sdl_img_header_t * header, int w, int h, lv_coord_t radius,
|
||||
bool * in_cache)
|
||||
{
|
||||
lv_draw_img_rounded_key_t key = rounded_key_create(texture, w, h, radius);
|
||||
SDL_Texture * mask_frag = lv_draw_sdl_rect_bg_frag_obtain(ctx, radius);
|
||||
bool mask_frag_in_cache = false;
|
||||
SDL_Texture * mask_frag = lv_draw_sdl_rect_bg_frag_obtain(ctx, radius, &mask_frag_in_cache);
|
||||
SDL_Texture * img_frag = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
if(img_frag == NULL) {
|
||||
const lv_coord_t full_frag_size = radius * 2 + 3;
|
||||
img_frag = SDL_CreateTexture(ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET,
|
||||
full_frag_size, full_frag_size);
|
||||
SDL_assert(img_frag);
|
||||
SDL_SetTextureBlendMode(img_frag, SDL_BLENDMODE_BLEND);
|
||||
SDL_Texture * old_target = SDL_GetRenderTarget(ctx->renderer);
|
||||
SDL_SetRenderTarget(ctx->renderer, img_frag);
|
||||
SDL_SetRenderDrawColor(ctx->renderer, 0, 0, 0, 0);
|
||||
SDL_RenderClear(ctx->renderer);
|
||||
/* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
|
||||
SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_NONE);
|
||||
SDL_RenderFillRect(ctx->renderer, NULL);
|
||||
SDL_SetRenderDrawBlendMode(ctx->renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
lv_area_t coords = {0, 0, w - 1, h - 1}, clip;
|
||||
lv_area_t coords = {0, 0, w - 1, h - 1};
|
||||
lv_area_t frag_coords = {0, 0, full_frag_size - 1, full_frag_size - 1};
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, mask_frag, radius, &frag_coords, NULL, false);
|
||||
|
||||
@@ -438,7 +469,14 @@ static SDL_Texture * img_rounded_frag_obtain(lv_draw_sdl_ctx_t * ctx, SDL_Textur
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
SDL_SetRenderTarget(ctx->renderer, old_target);
|
||||
lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), img_frag);
|
||||
*in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), img_frag);
|
||||
}
|
||||
else {
|
||||
*in_cache = true;
|
||||
}
|
||||
if(!mask_frag_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(mask_frag);
|
||||
}
|
||||
return img_frag;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef LV_DRAW_SDL_IMG_H
|
||||
#define LV_DRAW_SDL_IMG_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -35,6 +34,7 @@ extern "C" {
|
||||
typedef struct lv_draw_sdl_img_header_t {
|
||||
lv_img_header_t base;
|
||||
SDL_Rect rect;
|
||||
bool managed;
|
||||
} lv_draw_sdl_img_header_t;
|
||||
|
||||
/**********************
|
||||
@@ -56,9 +56,22 @@ typedef struct lv_draw_sdl_img_header_t {
|
||||
/*=====================
|
||||
* Other functions
|
||||
*====================*/
|
||||
/**
|
||||
*
|
||||
* @param ctx Drawing context
|
||||
* @param key Texture cache key
|
||||
* @param key_size Size of texture cache key
|
||||
* @param src Image source pointer
|
||||
* @param frame_id Frame ID for animated image
|
||||
* @param texture Texture for render
|
||||
* @param header Header also holds sdl image info
|
||||
* @param texture_in_cache Whether the texture has been put in the cache. Please note for managed texture,
|
||||
* this will be false too. So you'll need to check header.managed too.
|
||||
* @return Whether the image has been loaded successfully
|
||||
*/
|
||||
bool lv_draw_sdl_img_load_texture(lv_draw_sdl_ctx_t * ctx, lv_draw_sdl_cache_key_head_img_t * key, size_t key_size,
|
||||
const void * src, int32_t frame_id, SDL_Texture ** texture,
|
||||
lv_draw_sdl_img_header_t ** header);
|
||||
lv_draw_sdl_img_header_t ** header, bool * texture_in_cache);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "lv_draw_sdl_utils.h"
|
||||
#include "lv_draw_sdl_texture_cache.h"
|
||||
#include "lv_draw_sdl_composite.h"
|
||||
#include "lv_draw_sdl_layer.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@@ -40,7 +41,6 @@ typedef struct {
|
||||
|
||||
static lv_font_glyph_key_t font_key_glyph_create(const lv_font_t * font_p, uint32_t letter);
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@@ -53,7 +53,7 @@ static lv_font_glyph_key_t font_key_glyph_create(const lv_font_t * font_p, uint3
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
|
||||
void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t * dsc, const lv_point_t * pos_p,
|
||||
uint32_t letter)
|
||||
{
|
||||
const lv_area_t * clip_area = draw_ctx->clip_area;
|
||||
@@ -116,6 +116,7 @@ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t
|
||||
lv_font_glyph_key_t glyph_key = font_key_glyph_create(font_p, letter);
|
||||
bool glyph_found = false;
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &glyph_key, sizeof(glyph_key), &glyph_found);
|
||||
bool in_cache = false;
|
||||
if(!glyph_found) {
|
||||
if(g.resolved_font) {
|
||||
font_p = g.resolved_font;
|
||||
@@ -127,18 +128,27 @@ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t
|
||||
texture = SDL_CreateTextureFromSurface(renderer, mask);
|
||||
SDL_FreeSurface(mask);
|
||||
lv_mem_free(buf);
|
||||
lv_draw_sdl_texture_cache_put(ctx, &glyph_key, sizeof(glyph_key), texture);
|
||||
in_cache = lv_draw_sdl_texture_cache_put(ctx, &glyph_key, sizeof(glyph_key), texture);
|
||||
}
|
||||
else {
|
||||
in_cache = true;
|
||||
}
|
||||
if(!texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
lv_area_t t_letter = letter_area, t_clip = *clip_area, apply_area;
|
||||
bool has_mask = lv_draw_sdl_composite_begin(ctx, &letter_area, clip_area, NULL, dsc->blend_mode, &t_letter, &t_clip,
|
||||
&apply_area);
|
||||
bool has_composite = lv_draw_sdl_composite_begin(ctx, &letter_area, clip_area, NULL, dsc->blend_mode, &t_letter,
|
||||
&t_clip, &apply_area);
|
||||
|
||||
lv_draw_sdl_transform_areas_offset(ctx, has_composite, &apply_area, &t_letter, &t_clip);
|
||||
|
||||
/*If the letter is completely out of mask don't draw it*/
|
||||
if(!_lv_area_intersect(&draw_area, &t_letter, &t_clip)) {
|
||||
if(!in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
return;
|
||||
}
|
||||
SDL_Rect srcrect, dstrect;
|
||||
@@ -153,6 +163,11 @@ void lv_draw_sdl_draw_letter(lv_draw_ctx_t * draw_ctx, const lv_draw_label_dsc_t
|
||||
SDL_RenderCopy(renderer, texture, &srcrect, &dstrect);
|
||||
|
||||
lv_draw_sdl_composite_end(ctx, &apply_area, dsc->blend_mode);
|
||||
|
||||
if(!in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @file lv_draw_sdl_refr.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "../../lv_conf_internal.h"
|
||||
|
||||
#if LV_USE_GPU_SDL
|
||||
|
||||
#include "../../core/lv_refr.h"
|
||||
|
||||
#include "lv_draw_sdl.h"
|
||||
#include "lv_draw_sdl_priv.h"
|
||||
#include "lv_draw_sdl_composite.h"
|
||||
#include "lv_draw_sdl_utils.h"
|
||||
#include "lv_draw_sdl_layer.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
|
||||
lv_draw_layer_flags_t flags)
|
||||
{
|
||||
lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
|
||||
SDL_Renderer * renderer = ctx->renderer;
|
||||
|
||||
lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
|
||||
|
||||
transform_ctx->flags = flags;
|
||||
transform_ctx->orig_target = SDL_GetRenderTarget(renderer);
|
||||
|
||||
lv_coord_t target_w = lv_area_get_width(&layer_ctx->area_full);
|
||||
lv_coord_t target_h = lv_area_get_height(&layer_ctx->area_full);
|
||||
|
||||
enum lv_draw_sdl_composite_texture_id_t texture_id = LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_TRANSFORM0 +
|
||||
ctx->internals->transform_count;
|
||||
transform_ctx->target = lv_draw_sdl_composite_texture_obtain(ctx, texture_id, target_w, target_h,
|
||||
&transform_ctx->target_in_cache);
|
||||
transform_ctx->target_rect.x = 0;
|
||||
transform_ctx->target_rect.y = 0;
|
||||
transform_ctx->target_rect.w = target_w;
|
||||
transform_ctx->target_rect.h = target_h;
|
||||
|
||||
layer_ctx->max_row_with_alpha = target_h;
|
||||
layer_ctx->max_row_with_no_alpha = target_h;
|
||||
|
||||
SDL_SetTextureBlendMode(transform_ctx->target, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderTarget(renderer, transform_ctx->target);
|
||||
|
||||
/* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
||||
SDL_RenderFillRect(renderer, NULL);
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
/* Set proper drawing context for transform layer */
|
||||
ctx->internals->transform_count += 1;
|
||||
draw_ctx->buf_area = &layer_ctx->area_full;
|
||||
draw_ctx->clip_area = &layer_ctx->area_full;
|
||||
|
||||
return layer_ctx;
|
||||
}
|
||||
|
||||
void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
|
||||
const lv_draw_img_dsc_t * draw_dsc)
|
||||
{
|
||||
lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
|
||||
lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
|
||||
|
||||
SDL_Renderer * renderer = ctx->renderer;
|
||||
|
||||
SDL_Rect trans_rect;
|
||||
|
||||
if(transform_ctx->flags & LV_DRAW_LAYER_FLAG_CAN_SUBDIVIDE) {
|
||||
lv_area_zoom_to_sdl_rect(&layer_ctx->area_act, &trans_rect, draw_dsc->zoom, &draw_dsc->pivot);
|
||||
}
|
||||
else {
|
||||
lv_area_zoom_to_sdl_rect(&layer_ctx->area_full, &trans_rect, draw_dsc->zoom, &draw_dsc->pivot);
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, transform_ctx->orig_target);
|
||||
|
||||
/*Render off-screen texture, transformed*/
|
||||
SDL_Rect clip_rect;
|
||||
lv_area_to_sdl_rect(layer_ctx->original.clip_area, &clip_rect);
|
||||
SDL_Point center = {.x = draw_dsc->pivot.x, .y = draw_dsc->pivot.y};
|
||||
SDL_RenderSetClipRect(renderer, &clip_rect);
|
||||
SDL_SetTextureAlphaMod(transform_ctx->target, draw_dsc->opa);
|
||||
SDL_RenderCopyEx(renderer, transform_ctx->target, &transform_ctx->target_rect, &trans_rect,
|
||||
draw_dsc->angle, ¢er, SDL_FLIP_NONE);
|
||||
SDL_RenderSetClipRect(renderer, NULL);
|
||||
}
|
||||
|
||||
void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx)
|
||||
{
|
||||
lv_draw_sdl_ctx_t * ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
|
||||
lv_draw_sdl_layer_ctx_t * transform_ctx = (lv_draw_sdl_layer_ctx_t *) layer_ctx;
|
||||
if(!transform_ctx->target_in_cache && transform_ctx->target != NULL) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(transform_ctx->target);
|
||||
}
|
||||
ctx->internals->transform_count -= 1;
|
||||
}
|
||||
|
||||
void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area,
|
||||
lv_area_t * coords, lv_area_t * clip)
|
||||
{
|
||||
if(ctx->internals->transform_count == 0) {
|
||||
return;
|
||||
}
|
||||
lv_area_t * area = ctx->base_draw.buf_area;
|
||||
lv_area_move(coords, -area->x1, -area->y1);
|
||||
lv_area_move(clip, -area->x1, -area->y1);
|
||||
if(has_composite) {
|
||||
lv_area_move(apply_area, -area->x1, -area->y1);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
#endif /*LV_USE_GPU_SDL*/
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* @file lv_draw_sdl_refr.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_TEMPL_H
|
||||
#define LV_TEMPL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#include "lv_draw_sdl.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
typedef struct _lv_draw_sdl_layer_ctx_t {
|
||||
lv_draw_layer_ctx_t base;
|
||||
|
||||
SDL_Texture * orig_target;
|
||||
SDL_Texture * target;
|
||||
SDL_Rect target_rect;
|
||||
bool target_in_cache;
|
||||
lv_draw_layer_flags_t flags;
|
||||
} lv_draw_sdl_layer_ctx_t;
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
lv_draw_layer_ctx_t * lv_draw_sdl_layer_init(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx,
|
||||
lv_draw_layer_flags_t flags);
|
||||
|
||||
void lv_draw_sdl_layer_blend(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * transform_ctx,
|
||||
const lv_draw_img_dsc_t * draw_dsc);
|
||||
|
||||
void lv_draw_sdl_layer_destroy(lv_draw_ctx_t * draw_ctx, lv_draw_layer_ctx_t * layer_ctx);
|
||||
|
||||
void lv_draw_sdl_transform_areas_offset(lv_draw_sdl_ctx_t * ctx, bool has_composite, lv_area_t * apply_area,
|
||||
lv_area_t * coords, lv_area_t * clip);
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_TEMPL_H*/
|
||||
@@ -53,7 +53,7 @@ static SDL_Texture * line_texture_create(lv_draw_sdl_ctx_t * sdl_ctx, const lv_d
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
void lv_draw_sdl_draw_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t * dsc, const lv_point_t * point1,
|
||||
const lv_point_t * point2)
|
||||
const lv_point_t * point2, bool * in_cache)
|
||||
{
|
||||
lv_draw_sdl_ctx_t * sdl_ctx = (lv_draw_sdl_ctx_t *) draw_ctx;
|
||||
SDL_Renderer * renderer = sdl_ctx->renderer;
|
||||
@@ -68,7 +68,7 @@ void lv_draw_sdl_draw_line(lv_draw_ctx_t * draw_ctx, const lv_draw_line_dsc_t *
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(sdl_ctx, &key, sizeof(key), NULL);
|
||||
if(!texture) {
|
||||
texture = line_texture_create(sdl_ctx, dsc, (lv_coord_t) length);
|
||||
lv_draw_sdl_texture_cache_put(sdl_ctx, &key, sizeof(key), texture);
|
||||
*in_cache = lv_draw_sdl_texture_cache_put(sdl_ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
|
||||
lv_area_t coords = {x1, y1, x2, y2};
|
||||
@@ -126,7 +126,10 @@ static SDL_Texture * line_texture_create(lv_draw_sdl_ctx_t * sdl_ctx, const lv_d
|
||||
SDL_SetRenderTarget(sdl_ctx->renderer, texture);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(sdl_ctx->renderer, 0xFF, 0xFF, 0xFF, 0x0);
|
||||
SDL_RenderClear(sdl_ctx->renderer);
|
||||
/* SDL_RenderClear is not working properly, so we overwrite the target with solid color */
|
||||
SDL_SetRenderDrawBlendMode(sdl_ctx->renderer, SDL_BLENDMODE_NONE);
|
||||
SDL_RenderFillRect(sdl_ctx->renderer, NULL);
|
||||
SDL_SetRenderDrawBlendMode(sdl_ctx->renderer, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetRenderDrawColor(sdl_ctx->renderer, 0xFF, 0xFF, 0xFF, 0xFF);
|
||||
SDL_Rect line_rect = {1 + dsc->width / 2, 1, length, dsc->width};
|
||||
SDL_RenderFillRect(sdl_ctx->renderer, &line_rect);
|
||||
|
||||
@@ -39,7 +39,6 @@ lv_opa_t * lv_draw_sdl_mask_dump_opa(const lv_area_t * coords, const int16_t * i
|
||||
SDL_Texture * lv_draw_sdl_mask_dump_texture(SDL_Renderer * renderer, const lv_area_t * coords, const int16_t * ids,
|
||||
int16_t ids_count);
|
||||
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
@@ -77,7 +77,9 @@ void lv_draw_sdl_polygon(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dr
|
||||
int16_t mask_id = lv_draw_mask_add(&polygon_param, NULL);
|
||||
|
||||
lv_coord_t w = lv_area_get_width(&draw_area), h = lv_area_get_height(&draw_area);
|
||||
SDL_Texture * texture = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, w, h);
|
||||
bool texture_in_cache = false;
|
||||
SDL_Texture * texture = lv_draw_sdl_composite_texture_obtain(ctx, LV_DRAW_SDL_COMPOSITE_TEXTURE_ID_STREAM1, w, h,
|
||||
&texture_in_cache);
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
dump_masks(texture, &draw_area);
|
||||
|
||||
@@ -91,6 +93,10 @@ void lv_draw_sdl_polygon(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t * dr
|
||||
SDL_SetTextureColorMod(texture, color.r, color.g, color.b);
|
||||
SDL_SetTextureAlphaMod(texture, draw_dsc->bg_opa);
|
||||
SDL_RenderCopy(ctx->renderer, texture, &srcrect, &dstrect);
|
||||
if(!texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef LV_DRAW_SDL_PRIV_H
|
||||
#define LV_DRAW_SDL_PRIV_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -35,6 +34,9 @@ typedef struct lv_draw_sdl_context_internals_t {
|
||||
lv_lru_t * texture_cache;
|
||||
SDL_Texture * mask;
|
||||
SDL_Texture * composition;
|
||||
bool composition_cached;
|
||||
SDL_Texture * target_backup;
|
||||
uint8_t transform_count;
|
||||
} lv_draw_sdl_context_internals_t;
|
||||
|
||||
/**********************
|
||||
|
||||
@@ -21,12 +21,14 @@
|
||||
#include "lv_draw_sdl_composite.h"
|
||||
#include "lv_draw_sdl_mask.h"
|
||||
#include "lv_draw_sdl_stack_blur.h"
|
||||
#include "lv_draw_sdl_img.h"
|
||||
#include "lv_draw_sdl_layer.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
#define FRAG_SPACING 3
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
@@ -37,6 +39,23 @@ typedef struct {
|
||||
lv_coord_t size;
|
||||
} lv_draw_rect_bg_key_t;
|
||||
|
||||
typedef struct {
|
||||
lv_sdl_cache_key_magic_t magic;
|
||||
lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS];
|
||||
uint8_t stops_count;
|
||||
lv_grad_dir_t dir;
|
||||
} lv_draw_rect_grad_strip_key_t;
|
||||
|
||||
typedef struct {
|
||||
lv_sdl_cache_key_magic_t magic;
|
||||
lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS];
|
||||
uint8_t stops_count;
|
||||
lv_grad_dir_t dir;
|
||||
lv_coord_t w;
|
||||
lv_coord_t h;
|
||||
lv_coord_t radius;
|
||||
} lv_draw_rect_grad_frag_key_t;
|
||||
|
||||
typedef struct {
|
||||
lv_sdl_cache_key_magic_t magic;
|
||||
lv_coord_t radius;
|
||||
@@ -57,6 +76,12 @@ typedef struct {
|
||||
static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc);
|
||||
|
||||
static void draw_bg_grad_simple(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_grad_dsc_t * grad, bool blend_mod);
|
||||
|
||||
static void draw_bg_grad_radius(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc);
|
||||
|
||||
static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc);
|
||||
|
||||
@@ -81,6 +106,11 @@ static void frag_render_center(SDL_Renderer * renderer, SDL_Texture * frag, lv_c
|
||||
|
||||
static lv_draw_rect_bg_key_t rect_bg_key_create(lv_coord_t radius, lv_coord_t size);
|
||||
|
||||
static lv_draw_rect_grad_frag_key_t rect_grad_frag_key_create(const lv_grad_dsc_t * grad, lv_coord_t w, lv_coord_t h,
|
||||
lv_coord_t radius);
|
||||
|
||||
static lv_draw_rect_grad_strip_key_t rect_grad_strip_key_create(const lv_grad_dsc_t * grad);
|
||||
|
||||
static lv_draw_rect_shadow_key_t rect_shadow_key_create(lv_coord_t radius, lv_coord_t size, lv_coord_t blur);
|
||||
|
||||
static lv_draw_rect_border_key_t rect_border_key_create(lv_coord_t rout, lv_coord_t rin, const lv_area_t * outer_area,
|
||||
@@ -124,7 +154,11 @@ void lv_draw_sdl_draw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t *
|
||||
}
|
||||
/* Coords will be translated so coords will start at (0,0) */
|
||||
lv_area_t t_coords = *coords, t_clip = *clip, apply_area, t_area;
|
||||
lv_draw_sdl_composite_begin(ctx, coords, clip, &extension, dsc->blend_mode, &t_coords, &t_clip, &apply_area);
|
||||
bool has_composite = lv_draw_sdl_composite_begin(ctx, coords, clip, &extension, dsc->blend_mode, &t_coords, &t_clip,
|
||||
&apply_area);
|
||||
|
||||
lv_draw_sdl_transform_areas_offset(ctx, has_composite, &apply_area, &t_coords, &t_clip);
|
||||
|
||||
bool has_content = _lv_area_intersect(&t_area, &t_coords, &t_clip);
|
||||
|
||||
SDL_Rect clip_rect;
|
||||
@@ -141,20 +175,106 @@ void lv_draw_sdl_draw_rect(lv_draw_ctx_t * draw_ctx, const lv_draw_rect_dsc_t *
|
||||
lv_draw_sdl_composite_end(ctx, &apply_area, dsc->blend_mode);
|
||||
}
|
||||
|
||||
SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius)
|
||||
SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius, bool * in_cache)
|
||||
{
|
||||
lv_draw_rect_bg_key_t key = rect_bg_key_create(radius, radius);
|
||||
lv_area_t coords = {0, 0, radius * 2 - 1, radius * 2 - 1};
|
||||
lv_area_t coords_frag = {0, 0, radius - 1, radius - 1};
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
if(texture == NULL) {
|
||||
lv_area_t coords = {0, 0, radius * 2 - 1, radius * 2 - 1};
|
||||
lv_area_t coords_frag = {0, 0, radius - 1, radius - 1};
|
||||
lv_draw_mask_radius_param_t mask_rout_param;
|
||||
lv_draw_mask_radius_init(&mask_rout_param, &coords, radius, false);
|
||||
int16_t mask_id = lv_draw_mask_add(&mask_rout_param, NULL);
|
||||
texture = lv_draw_sdl_mask_dump_texture(ctx->renderer, &coords_frag, &mask_id, 1);
|
||||
SDL_assert(texture != NULL);
|
||||
lv_draw_mask_remove_id(mask_id);
|
||||
SDL_assert(texture);
|
||||
lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
*in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
else {
|
||||
*in_cache = true;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
SDL_Texture * lv_draw_sdl_rect_grad_frag_obtain(lv_draw_sdl_ctx_t * ctx, const lv_grad_dsc_t * grad, lv_coord_t w,
|
||||
lv_coord_t h, lv_coord_t radius, bool * in_cache)
|
||||
{
|
||||
lv_draw_rect_grad_frag_key_t key = rect_grad_frag_key_create(grad, w, h, radius);
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
if(texture == NULL) {
|
||||
lv_area_t coords = {0, 0, radius * 2 + FRAG_SPACING - 1, radius * 2 + FRAG_SPACING - 1};
|
||||
texture = SDL_CreateTexture(ctx->renderer, LV_DRAW_SDL_TEXTURE_FORMAT, SDL_TEXTUREACCESS_TARGET,
|
||||
lv_area_get_width(&coords), lv_area_get_height(&coords));
|
||||
SDL_assert(texture != NULL);
|
||||
|
||||
lv_draw_mask_radius_param_t mask_rout_param;
|
||||
lv_draw_mask_radius_init(&mask_rout_param, &coords, radius, false);
|
||||
int16_t mask_id = lv_draw_mask_add(&mask_rout_param, NULL);
|
||||
SDL_Texture * mask = lv_draw_sdl_mask_dump_texture(ctx->renderer, &coords, &mask_id, 1);
|
||||
SDL_assert(mask != NULL);
|
||||
SDL_SetTextureBlendMode(mask, SDL_BLENDMODE_NONE);
|
||||
lv_draw_mask_remove_id(mask_id);
|
||||
|
||||
SDL_Texture * target_backup = SDL_GetRenderTarget(ctx->renderer);
|
||||
SDL_SetRenderTarget(ctx->renderer, texture);
|
||||
SDL_RenderCopy(ctx->renderer, mask, NULL, NULL);
|
||||
SDL_DestroyTexture(mask);
|
||||
|
||||
lv_area_t blend_coords = {.x1 = 0, .y1 = 0, .x2 = w - 1, .y2 = h - 1};
|
||||
lv_area_t draw_area = {.x1 = 0, .y1 = 0, .x2 = radius - 1, .y2 = radius - 1};
|
||||
/* Align to top left */
|
||||
lv_area_align(&coords, &draw_area, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
lv_area_align(&coords, &blend_coords, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||
draw_bg_grad_simple(ctx, &blend_coords, &draw_area, grad, true);
|
||||
|
||||
/* Align to top right */
|
||||
lv_area_align(&coords, &draw_area, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
lv_area_align(&coords, &blend_coords, LV_ALIGN_TOP_RIGHT, 0, 0);
|
||||
draw_bg_grad_simple(ctx, &blend_coords, &draw_area, grad, true);
|
||||
|
||||
/* Align to bottom right */
|
||||
lv_area_align(&coords, &draw_area, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
|
||||
lv_area_align(&coords, &blend_coords, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
|
||||
draw_bg_grad_simple(ctx, &blend_coords, &draw_area, grad, true);
|
||||
|
||||
/* Align to bottom left */
|
||||
lv_area_align(&coords, &draw_area, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
||||
lv_area_align(&coords, &blend_coords, LV_ALIGN_BOTTOM_LEFT, 0, 0);
|
||||
draw_bg_grad_simple(ctx, &blend_coords, &draw_area, grad, true);
|
||||
|
||||
SDL_SetRenderTarget(ctx->renderer, target_backup);
|
||||
*in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
else {
|
||||
*in_cache = true;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
SDL_Texture * lv_draw_sdl_rect_grad_strip_obtain(lv_draw_sdl_ctx_t * ctx, const lv_grad_dsc_t * grad, bool * in_cache)
|
||||
{
|
||||
lv_draw_rect_grad_strip_key_t key = rect_grad_strip_key_create(grad);
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
if(texture == NULL) {
|
||||
Uint32 amask = 0xFF000000;
|
||||
Uint32 rmask = 0x00FF0000;
|
||||
Uint32 gmask = 0x0000FF00;
|
||||
Uint32 bmask = 0x000000FF;
|
||||
lv_color_t pixels[256];
|
||||
for(int i = 0; i < 256; i++) {
|
||||
pixels[i] = lv_gradient_calculate(grad, 256, i);
|
||||
}
|
||||
int width = grad->dir == LV_GRAD_DIR_VER ? 1 : 256;
|
||||
int height = grad->dir == LV_GRAD_DIR_VER ? 256 : 1;
|
||||
SDL_Surface * surface = SDL_CreateRGBSurfaceFrom(pixels, width, height, LV_COLOR_DEPTH, width * LV_COLOR_DEPTH / 8,
|
||||
rmask, gmask, bmask, amask);
|
||||
texture = SDL_CreateTextureFromSurface(ctx->renderer, surface);
|
||||
SDL_assert(texture != NULL);
|
||||
SDL_FreeSurface(surface);
|
||||
*in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
else {
|
||||
*in_cache = true;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
@@ -189,7 +309,7 @@ void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture
|
||||
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 + 3 + sx, sy, dw, dh};
|
||||
SDL_Rect src_rect = {frag_size + FRAG_SPACING + sx, sy, dw, dh};
|
||||
SDL_RenderCopy(ctx->renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -208,7 +328,7 @@ void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture
|
||||
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 + 3 + sx, frag_size + 3 + sy, dw, dh};
|
||||
SDL_Rect src_rect = {frag_size + FRAG_SPACING + sx, frag_size + FRAG_SPACING + sy, dw, dh};
|
||||
SDL_RenderCopy(ctx->renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -216,7 +336,7 @@ void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture
|
||||
SDL_RenderCopyEx(ctx->renderer, frag, &src_rect, &dst_rect, 0, NULL, SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL);
|
||||
}
|
||||
}
|
||||
/* Lower left, right edge should not be clip */
|
||||
/* Lower left, right edge should not be clipped */
|
||||
corner_area.x1 = coords->x1;
|
||||
corner_area.x2 = coords->x1 + frag_size - 1;
|
||||
if(_lv_area_intersect(&dst_area, &corner_area, clip)) {
|
||||
@@ -227,7 +347,7 @@ void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture
|
||||
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 + 3 + sy, dw, dh};
|
||||
SDL_Rect src_rect = {sx, frag_size + FRAG_SPACING + sy, dw, dh};
|
||||
SDL_RenderCopy(ctx->renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -237,7 +357,6 @@ void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
@@ -248,9 +367,23 @@ static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, con
|
||||
if(dsc->bg_opa == 0) {
|
||||
return;
|
||||
}
|
||||
SDL_Color bg_color;
|
||||
lv_color_to_sdl_color(&dsc->bg_color, &bg_color);
|
||||
lv_coord_t radius = dsc->radius;
|
||||
SDL_Color bg_color;
|
||||
if(dsc->bg_grad.dir == LV_GRAD_DIR_NONE) {
|
||||
lv_color_to_sdl_color(&dsc->bg_color, &bg_color);
|
||||
}
|
||||
else if(dsc->bg_grad.stops_count == 1) {
|
||||
lv_color_to_sdl_color(&dsc->bg_grad.stops[0].color, &bg_color);
|
||||
}
|
||||
else {
|
||||
if(radius <= 0) {
|
||||
draw_bg_grad_simple(ctx, coords, draw_area, &dsc->bg_grad, false);
|
||||
}
|
||||
else {
|
||||
draw_bg_grad_radius(ctx, coords, draw_area, dsc);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if(radius <= 0) {
|
||||
SDL_Rect rect;
|
||||
lv_area_to_sdl_rect(draw_area, &rect);
|
||||
@@ -263,7 +396,8 @@ static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, con
|
||||
/*A small texture with a quarter of the rect is enough*/
|
||||
lv_coord_t bg_w = lv_area_get_width(coords), bg_h = lv_area_get_height(coords);
|
||||
lv_coord_t real_radius = LV_MIN3(bg_w / 2, bg_h / 2, radius);
|
||||
SDL_Texture * texture = lv_draw_sdl_rect_bg_frag_obtain(ctx, real_radius);
|
||||
bool texture_in_cache = false;
|
||||
SDL_Texture * texture = lv_draw_sdl_rect_bg_frag_obtain(ctx, real_radius, &texture_in_cache);
|
||||
|
||||
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureAlphaMod(texture, dsc->bg_opa);
|
||||
@@ -271,11 +405,131 @@ static void draw_bg_color(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, con
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, texture, real_radius, coords, draw_area, false);
|
||||
frag_render_borders(ctx->renderer, texture, real_radius, coords, draw_area, false);
|
||||
frag_render_center(ctx->renderer, texture, real_radius, coords, draw_area, false);
|
||||
|
||||
if(!texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_bg_grad_simple(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_grad_dsc_t * grad, bool blend_mod)
|
||||
{
|
||||
SDL_Rect dstrect;
|
||||
lv_area_to_sdl_rect(draw_area, &dstrect);
|
||||
SDL_Rect srcrect;
|
||||
if(grad->dir == LV_GRAD_DIR_VER) {
|
||||
lv_coord_t coords_h = lv_area_get_height(coords);
|
||||
srcrect.x = 0;
|
||||
srcrect.y = (draw_area->y1 - coords->y1) * 255 / coords_h;
|
||||
srcrect.w = 1;
|
||||
srcrect.h = dstrect.h * 256 / coords_h;
|
||||
|
||||
if(srcrect.y < 0 || srcrect.y > 255) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lv_coord_t coords_w = lv_area_get_width(coords);
|
||||
srcrect.x = (draw_area->x1 - coords->x1) * 255 / coords_w;
|
||||
srcrect.y = 0;
|
||||
srcrect.w = dstrect.w * 256 / coords_w;
|
||||
srcrect.h = 1;
|
||||
|
||||
if(srcrect.x < 0 || srcrect.x > 255) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool grad_texture_in_cache = false;
|
||||
SDL_Texture * grad_texture = lv_draw_sdl_rect_grad_strip_obtain(ctx, grad, &grad_texture_in_cache);
|
||||
if(blend_mod) {
|
||||
SDL_SetTextureBlendMode(grad_texture, SDL_BLENDMODE_MOD);
|
||||
}
|
||||
else {
|
||||
SDL_SetTextureBlendMode(grad_texture, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
SDL_RenderCopy(ctx->renderer, grad_texture, &srcrect, &dstrect);
|
||||
|
||||
if(!grad_texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(grad_texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_bg_grad_radius(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc)
|
||||
{
|
||||
lv_coord_t radius = dsc->radius;
|
||||
/*A small texture with a quarter of the rect is enough*/
|
||||
lv_coord_t bg_w = lv_area_get_width(coords), bg_h = lv_area_get_height(coords);
|
||||
lv_coord_t real_radius = LV_MIN3(bg_w / 2, bg_h / 2, radius);
|
||||
bool grad_texture_in_cache = false;
|
||||
SDL_Texture * grad_texture = lv_draw_sdl_rect_grad_frag_obtain(ctx, &dsc->bg_grad, bg_w, bg_h, radius,
|
||||
&grad_texture_in_cache);
|
||||
SDL_SetTextureBlendMode(grad_texture, SDL_BLENDMODE_BLEND);
|
||||
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, grad_texture, real_radius, coords, draw_area, true);
|
||||
lv_area_t part_coords;
|
||||
lv_area_t part_area;
|
||||
if(bg_w > radius * 2) {
|
||||
/*Draw left, middle, right*/
|
||||
part_coords.x1 = 0;
|
||||
part_coords.x2 = radius - 1;
|
||||
part_coords.y1 = radius;
|
||||
part_coords.y2 = bg_h - radius - 1;
|
||||
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_LEFT_MID, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_RIGHT_MID, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
|
||||
part_coords.x1 = radius;
|
||||
part_coords.x2 = bg_w - radius - 1;
|
||||
part_coords.y1 = 0;
|
||||
part_coords.y2 = bg_h - 1;
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_CENTER, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
}
|
||||
else if(bg_h > radius * 2) {
|
||||
/*Draw top, middle, bottom*/
|
||||
part_coords.x1 = radius;
|
||||
part_coords.x2 = bg_w - radius - 1;
|
||||
part_coords.y1 = 0;
|
||||
part_coords.y2 = radius - 1;
|
||||
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_TOP_MID, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
|
||||
part_coords.x1 = 0;
|
||||
part_coords.x2 = bg_w - 1;
|
||||
part_coords.y1 = radius;
|
||||
part_coords.y2 = bg_h - radius - 1;
|
||||
lv_area_align(coords, &part_coords, LV_ALIGN_CENTER, 0, 0);
|
||||
_lv_area_intersect(&part_area, &part_coords, draw_area);
|
||||
draw_bg_grad_simple(ctx, coords, &part_area, &dsc->bg_grad, false);
|
||||
}
|
||||
|
||||
if(!grad_texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(grad_texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_bg_img(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc)
|
||||
{
|
||||
LV_UNUSED(draw_area);
|
||||
if(SKIP_IMAGE(dsc)) return;
|
||||
|
||||
lv_img_src_t src_type = lv_img_src_get_type(dsc->bg_img_src);
|
||||
@@ -405,6 +659,7 @@ static void draw_shadow(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
|
||||
lv_draw_rect_shadow_key_t key = rect_shadow_key_create(radius, frag_size, sw);
|
||||
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
bool texture_in_cache = false;
|
||||
if(texture == NULL) {
|
||||
lv_area_t mask_area = {blur_growth, blur_growth}, mask_area_blurred = {0, 0};
|
||||
lv_area_set_width(&mask_area, frag_size * 2);
|
||||
@@ -423,7 +678,10 @@ static void draw_shadow(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
|
||||
lv_mem_buf_release(mask_buf);
|
||||
lv_draw_mask_remove_id(mask_id);
|
||||
SDL_assert(texture);
|
||||
lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
texture_in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
else {
|
||||
texture_in_cache = true;
|
||||
}
|
||||
|
||||
SDL_Color shadow_color;
|
||||
@@ -435,8 +693,12 @@ static void draw_shadow(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, texture, blur_frag_size, &shadow_area, clip, false);
|
||||
frag_render_borders(ctx->renderer, texture, blur_frag_size, &shadow_area, clip, false);
|
||||
frag_render_center(ctx->renderer, texture, blur_frag_size, &shadow_area, clip, false);
|
||||
}
|
||||
|
||||
if(!texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_border(lv_draw_sdl_ctx_t * ctx, const lv_area_t * coords, const lv_area_t * draw_area,
|
||||
const lv_draw_rect_dsc_t * dsc)
|
||||
@@ -516,9 +778,10 @@ static void draw_border_generic(lv_draw_sdl_ctx_t * ctx, const lv_area_t * outer
|
||||
lv_coord_t max_side = LV_MAX4(key.offsets.x1, key.offsets.y1, -key.offsets.x2, -key.offsets.y2);
|
||||
lv_coord_t frag_size = LV_MAX(radius, max_side);
|
||||
SDL_Texture * texture = lv_draw_sdl_texture_cache_get(ctx, &key, sizeof(key), NULL);
|
||||
bool texture_in_cache;
|
||||
if(texture == NULL) {
|
||||
/* 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 a mask texture with size of (frag_size * 2 + FRAG_SPACING) */
|
||||
const lv_area_t frag_area = {0, 0, frag_size * 2 + FRAG_SPACING - 1, frag_size * 2 + FRAG_SPACING - 1};
|
||||
|
||||
/*Create mask for the outer area*/
|
||||
int16_t mask_ids[2] = {LV_MASK_ID_INV, LV_MASK_ID_INV};
|
||||
@@ -542,7 +805,10 @@ static void draw_border_generic(lv_draw_sdl_ctx_t * ctx, const lv_area_t * outer
|
||||
lv_draw_mask_remove_id(mask_ids[1]);
|
||||
lv_draw_mask_remove_id(mask_ids[0]);
|
||||
SDL_assert(texture);
|
||||
lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
texture_in_cache = lv_draw_sdl_texture_cache_put(ctx, &key, sizeof(key), texture);
|
||||
}
|
||||
else {
|
||||
texture_in_cache = true;
|
||||
}
|
||||
|
||||
SDL_Rect outer_rect;
|
||||
@@ -556,6 +822,11 @@ static void draw_border_generic(lv_draw_sdl_ctx_t * ctx, const lv_area_t * outer
|
||||
|
||||
lv_draw_sdl_rect_bg_frag_draw_corners(ctx, texture, frag_size, outer_area, clip, true);
|
||||
frag_render_borders(renderer, texture, frag_size, outer_area, clip, true);
|
||||
|
||||
if(!texture_in_cache) {
|
||||
LV_LOG_WARN("Texture is not cached, this will impact performance.");
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
|
||||
static void frag_render_borders(SDL_Renderer * renderer, SDL_Texture * frag, lv_coord_t frag_size,
|
||||
@@ -591,7 +862,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 + 1, frag_size + 3 + sy, 1, dh};
|
||||
SDL_Rect src_rect = {frag_size + 1, frag_size + FRAG_SPACING + sy, 1, dh};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -630,7 +901,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 + 3 + sx, frag_size + 1, dw, 1};
|
||||
SDL_Rect src_rect = {frag_size + FRAG_SPACING + sx, frag_size + 1, dw, 1};
|
||||
SDL_RenderCopy(renderer, frag, &src_rect, &dst_rect);
|
||||
}
|
||||
else {
|
||||
@@ -678,6 +949,38 @@ static lv_draw_rect_bg_key_t rect_bg_key_create(lv_coord_t radius, lv_coord_t si
|
||||
return key;
|
||||
}
|
||||
|
||||
static lv_draw_rect_grad_frag_key_t rect_grad_frag_key_create(const lv_grad_dsc_t * grad, lv_coord_t w, lv_coord_t h,
|
||||
lv_coord_t radius)
|
||||
{
|
||||
lv_draw_rect_grad_frag_key_t key;
|
||||
SDL_memset(&key, 0, sizeof(key));
|
||||
key.magic = LV_GPU_CACHE_KEY_MAGIC_RECT_GRAD;
|
||||
key.stops_count = grad->stops_count;
|
||||
key.dir = grad->dir;
|
||||
for(uint8_t i = 0; i < grad->stops_count; i++) {
|
||||
key.stops[i].frac = grad->stops[i].frac;
|
||||
key.stops[i].color = grad->stops[i].color;
|
||||
}
|
||||
key.w = w;
|
||||
key.h = h;
|
||||
key.radius = radius;
|
||||
return key;
|
||||
}
|
||||
|
||||
static lv_draw_rect_grad_strip_key_t rect_grad_strip_key_create(const lv_grad_dsc_t * grad)
|
||||
{
|
||||
lv_draw_rect_grad_strip_key_t key;
|
||||
SDL_memset(&key, 0, sizeof(key));
|
||||
key.magic = LV_GPU_CACHE_KEY_MAGIC_RECT_GRAD;
|
||||
key.stops_count = grad->stops_count;
|
||||
key.dir = grad->dir;
|
||||
for(uint8_t i = 0; i < grad->stops_count; i++) {
|
||||
key.stops[i].frac = grad->stops[i].frac;
|
||||
key.stops[i].color = grad->stops[i].color;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
static lv_draw_rect_shadow_key_t rect_shadow_key_create(lv_coord_t radius, lv_coord_t size, lv_coord_t blur)
|
||||
{
|
||||
lv_draw_rect_shadow_key_t key;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#ifndef LV_DRAW_SDL_RECT_H
|
||||
#define LV_DRAW_SDL_RECT_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -57,7 +56,36 @@ typedef struct lv_draw_sdl_rect_header_t {
|
||||
* Other functions
|
||||
*====================*/
|
||||
|
||||
SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius);
|
||||
/**
|
||||
*
|
||||
* @param ctx Drawing context
|
||||
* @param radius Corner radius of the rectangle
|
||||
* @param in_cache Whether the texture has been put in the cache
|
||||
* @return Background fragment texture
|
||||
*/
|
||||
SDL_Texture * lv_draw_sdl_rect_bg_frag_obtain(lv_draw_sdl_ctx_t * ctx, lv_coord_t radius, bool * in_cache);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ctx Drawing context
|
||||
* @param grad Gradient info
|
||||
* @param w Width of the rectangle
|
||||
* @param h Height of the rectangle
|
||||
* @param radius Corner radius of the rectangle
|
||||
* @param in_cache Whether the texture has been put in the cache
|
||||
* @return Gradient fragment texture
|
||||
*/
|
||||
SDL_Texture * lv_draw_sdl_rect_grad_frag_obtain(lv_draw_sdl_ctx_t * ctx, const lv_grad_dsc_t * grad, lv_coord_t w,
|
||||
lv_coord_t h, lv_coord_t radius, bool * in_cache);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ctx Drawing context
|
||||
* @param grad Gradient info
|
||||
* @param in_cache Whether the texture has been put in the cache
|
||||
* @return Gradient strip texture
|
||||
*/
|
||||
SDL_Texture * lv_draw_sdl_rect_grad_strip_obtain(lv_draw_sdl_ctx_t * ctx, const lv_grad_dsc_t * grad, bool * in_cache);
|
||||
|
||||
void lv_draw_sdl_rect_bg_frag_draw_corners(lv_draw_sdl_ctx_t * ctx, SDL_Texture * frag, lv_coord_t frag_size,
|
||||
const lv_area_t * coords, const lv_area_t * clip, bool full);
|
||||
|
||||
@@ -122,8 +122,8 @@ static void stack_blur_job(lv_opa_t * src, unsigned int w, unsigned int h, unsig
|
||||
|
||||
for(y = minY; y < maxY; y++) {
|
||||
sum_r =
|
||||
sum_in_r =
|
||||
sum_out_r = 0;
|
||||
sum_in_r =
|
||||
sum_out_r = 0;
|
||||
|
||||
src_ptr = src + stride * y; // start of line (0,y)
|
||||
|
||||
@@ -134,7 +134,6 @@ static void stack_blur_job(lv_opa_t * src, unsigned int w, unsigned int h, unsig
|
||||
sum_out_r += src_ptr[0];
|
||||
}
|
||||
|
||||
|
||||
for(i = 1; i <= radius; i++) {
|
||||
if(i <= wm) src_ptr += 1;
|
||||
stack_ptr = &stack[i + radius];
|
||||
@@ -143,7 +142,6 @@ static void stack_blur_job(lv_opa_t * src, unsigned int w, unsigned int h, unsig
|
||||
sum_in_r += src_ptr[0];
|
||||
}
|
||||
|
||||
|
||||
sp = radius;
|
||||
xp = radius;
|
||||
if(xp > wm) xp = wm;
|
||||
@@ -189,8 +187,8 @@ static void stack_blur_job(lv_opa_t * src, unsigned int w, unsigned int h, unsig
|
||||
|
||||
for(x = minX; x < maxX; x++) {
|
||||
sum_r =
|
||||
sum_in_r =
|
||||
sum_out_r = 0;
|
||||
sum_in_r =
|
||||
sum_out_r = 0;
|
||||
|
||||
src_ptr = src + x; // x,0
|
||||
for(i = 0; i <= radius; i++) {
|
||||
|
||||
@@ -81,12 +81,12 @@ SDL_Texture * lv_draw_sdl_texture_cache_get_with_userdata(lv_draw_sdl_ctx_t * ct
|
||||
return value->texture;
|
||||
}
|
||||
|
||||
void lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture)
|
||||
bool lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture)
|
||||
{
|
||||
lv_draw_sdl_texture_cache_put_advanced(ctx, key, key_length, texture, NULL, NULL, 0);
|
||||
return lv_draw_sdl_texture_cache_put_advanced(ctx, key, key_length, texture, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
void lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
|
||||
bool lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
|
||||
SDL_Texture * texture, void * userdata, void userdata_free(void *),
|
||||
lv_draw_sdl_cache_flag_t flags)
|
||||
{
|
||||
@@ -97,22 +97,20 @@ void lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void
|
||||
value->userdata_free = userdata_free;
|
||||
value->flags = flags;
|
||||
if(!texture) {
|
||||
lv_lru_set(lru, key, key_length, value, 1);
|
||||
return;
|
||||
return lv_lru_set(lru, key, key_length, value, 1) == LV_LRU_OK;
|
||||
}
|
||||
if(flags & LV_DRAW_SDL_CACHE_FLAG_MANAGED) {
|
||||
/* Managed texture doesn't count into cache size */
|
||||
LV_LOG_INFO("cache texture %p", texture);
|
||||
lv_lru_set(lru, key, key_length, value, 1);
|
||||
return;
|
||||
return lv_lru_set(lru, key, key_length, value, 1) == LV_LRU_OK;
|
||||
}
|
||||
Uint32 format;
|
||||
int access, width, height;
|
||||
if(SDL_QueryTexture(texture, &format, &access, &width, &height) != 0) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
LV_LOG_INFO("cache texture %p, %d*%d@%dbpp", texture, width, height, SDL_BITSPERPIXEL(format));
|
||||
lv_lru_set(lru, key, key_length, value, width * height * SDL_BITSPERPIXEL(format) / 8);
|
||||
return lv_lru_set(lru, key, key_length, value, width * height * SDL_BITSPERPIXEL(format) / 8) == LV_LRU_OK;
|
||||
}
|
||||
|
||||
lv_draw_sdl_cache_key_head_img_t * lv_draw_sdl_texture_img_key_create(const void * src, int32_t frame_id, size_t * size)
|
||||
|
||||
@@ -50,6 +50,7 @@ typedef enum {
|
||||
LV_GPU_CACHE_KEY_MAGIC_RECT_BG = 0x31,
|
||||
LV_GPU_CACHE_KEY_MAGIC_RECT_SHADOW = 0x32,
|
||||
LV_GPU_CACHE_KEY_MAGIC_RECT_BORDER = 0x33,
|
||||
LV_GPU_CACHE_KEY_MAGIC_RECT_GRAD = 0x34,
|
||||
LV_GPU_CACHE_KEY_MAGIC_FONT_GLYPH = 0x41,
|
||||
LV_GPU_CACHE_KEY_MAGIC_MASK = 0x51,
|
||||
} lv_sdl_cache_key_magic_t;
|
||||
@@ -81,9 +82,15 @@ SDL_Texture * lv_draw_sdl_texture_cache_get(lv_draw_sdl_ctx_t * ctx, const void
|
||||
SDL_Texture * lv_draw_sdl_texture_cache_get_with_userdata(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
|
||||
bool * found, void ** userdata);
|
||||
|
||||
void lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture);
|
||||
/**
|
||||
* @return Whether the texture has been put in the cache
|
||||
*/
|
||||
bool lv_draw_sdl_texture_cache_put(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length, SDL_Texture * texture);
|
||||
|
||||
void lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
|
||||
/**
|
||||
* @return Whether the texture has been put in the cache
|
||||
*/
|
||||
bool lv_draw_sdl_texture_cache_put_advanced(lv_draw_sdl_ctx_t * ctx, const void * key, size_t key_length,
|
||||
SDL_Texture * texture, void * userdata, void userdata_free(void *),
|
||||
lv_draw_sdl_cache_flag_t flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user