feat(draw_buf): add option to select draw_buf implementation

This commit is contained in:
Gabor Kiss-Vamosi
2023-08-18 23:01:43 +02:00
parent ae3567cb46
commit 1f807ae714
5 changed files with 146 additions and 43 deletions
+11 -5
View File
@@ -86,12 +86,18 @@
/*========================
* RENDERING CONFIGURATION
*========================*/
/* Select a draw buffer implementation. Possible values:
* - LV_DRAW_BUF_BASIC: LVGL's built in implementation
* - LV_DRAW_BUF_CUSTOM: Implement teh function of lv_draw_buf.h externally
*/
#define LV_USE_DRAW_BUF LV_DRAW_BUF_BASIC
/*Align the stride of all layers and images to this bytes*/
#define LV_DRAW_BUF_STRIDE_ALIGN 1
/*Align the start address of draw_buf addresses to this bytes*/
#define LV_DRAW_BUF_ALIGN 4
#if LV_USE_DRAW_BUF == LV_DRAW_BUF_BASIC
/*Align the stride of all layers and images to this bytes*/
#define LV_DRAW_BUF_STRIDE_ALIGN 1 /*Multiple of these Bytes*/
/*Align the start address of draw_buf addresses to this bytes*/
#define LV_DRAW_BUF_ALIGN 4
#endif
/* Max. memory to be used for layers */
#define LV_LAYER_MAX_MEMORY_USAGE 150 /*[kB]*/
+90 -20
View File
@@ -25,36 +25,106 @@ extern "C" {
**********************/
typedef struct {
void * buf;
lv_coord_t width;
lv_coord_t height;
lv_color_format_t color_format;
uint32_t usage_cnt;
uint32_t flags;
} lv_draw_buf_t;
void lv_draw_buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format);
void lv_draw_buf_malloc(lv_draw_buf_t * draw_buf);
void lv_draw_buf_realloc(lv_draw_buf_t * buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format);
void lv_draw_buf_free(lv_draw_buf_t * buf);
void * lv_draw_buf_get_buf(lv_draw_buf_t * draw_buf);
void lv_draw_buf_invalidate_cache(lv_draw_buf_t * buf);
uint32_t lv_draw_buf_get_stride(const lv_draw_buf_t * draw_buf);
void * lv_draw_buf_go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y);
void lv_draw_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a);
void lv_draw_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area, lv_color_format_t color_format);
static inline uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
{
uint32_t width_byte = w * lv_color_format_get_size(color_format);
return (width_byte + LV_DRAW_BUF_STRIDE_ALIGN - 1) & ~(LV_DRAW_BUF_STRIDE_ALIGN - 1);
}
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Initialize a draw buffer object. The buffer won't be allocated
* @param draw_buf pointer to a draw buffer
* @param w the width of the buffer in pixel
* @param h the height of the buffer in pixel
* @param color_format the color format of the buffer
*/
void lv_draw_buf_init(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format);
/**
* Allocate a buffer in the draw_buf, considering the set width, height and color format
* @param draw_buf pointer to a draw buffer
*/
void lv_draw_buf_malloc(lv_draw_buf_t * draw_buf);
/**
* Realloacte the buffer with a new width, height and color format
* @param draw_buf pointer to a draw buffer
* @param w the new width of the buffer in pixel
* @param h the new height of the buffer in pixel
* @param color_format the new color format of the buffer
*/
void lv_draw_buf_realloc(lv_draw_buf_t * draw_buf, lv_coord_t w, lv_coord_t h, lv_color_format_t color_format);
/**
* Free the allocated buffer
* @param draw_buf pointer to draw buffer
*/
void lv_draw_buf_free(lv_draw_buf_t * draw_buf);
/**
* Get the buffer of the draw_buf.
* Never get the buffer as draw_buf->buf adn this function might align the buffer
* @param draw_buf pointer to a draw buffer
* @return pointer to the buffer
*/
void * lv_draw_buf_get_buf(lv_draw_buf_t * draw_buf);
/**
* Invalidate the cache of the buffer
* @param draw_buf pointer to a draw buffer
*/
void lv_draw_buf_invalidate_cache(lv_draw_buf_t * draw_buf);
/**
* Calculate the stride in bytes based on a width and color format
* @param w the width in pixels
* @param color_format the color format
* @return the stride in bytes
*/
uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format);
/**
* Get the stride of a draw buffer using the set width and color format
* @param draw_buf pointer to draw buffer
* @return the stride in bytes
*/
uint32_t lv_draw_buf_get_stride(const lv_draw_buf_t * draw_buf);
/**
* Go to the X, Y coordinate on the buffer.
* @param draw_buf pointer to draw buffer
* @param x the X coordinate to seek
* @param y the Y coordinate to seek
*/
void * lv_draw_buf_go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y);
/**
* Clear an area on the buffer
* @param draw_buf pointer to draw buffer
* @param a the area to clear, or NULL to clear the whole buffer
*/
void lv_draw_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a);
/**
* Copy an area from a buffer to an other
* @param dest_buf pointer to the destination buffer (not draw_buf)
* @param dest_stride the stride of the destination buffer in bytes
* @param dest_area pointer to the destination area
* @param src_buf pointer to the source buffer (not draw_buf)
* @param src_stride the stride of the source buffer in bytes
* @param src_area pointer to the source area
* @param color_format the color format (should be the same for the source and destination)
*/
void lv_draw_buf_copy(void * dest_buf, uint32_t dest_stride, const lv_area_t * dest_area,
void * src_buf, uint32_t src_stride, const lv_area_t * src_area, lv_color_format_t color_format);
/**********************
* MACROS
**********************/
@@ -1,14 +1,18 @@
/**
* @file lv_draw_buf.c
* @file lv_draw_buf_basic.c
*
*/
/*********************
* INCLUDES
*********************/
#include "../../misc/lv_types.h"
#include "lv_draw_buf.h"
#if LV_USE_DRAW_BUF == LV_DRAW_BUF_BASIC
#include "../../stdlib/lv_string.h"
/*********************
* DEFINES
*********************/
@@ -74,7 +78,12 @@ void * lv_draw_buf_get_buf(lv_draw_buf_t * draw_buf)
void lv_draw_buf_invalidate_cache(lv_draw_buf_t * draw_buf)
{
LV_UNUSED(draw_buf);
}
uint32_t lv_draw_buf_width_to_stride(uint32_t w, lv_color_format_t color_format)
{
uint32_t width_byte = w * lv_color_format_get_size(color_format);
return (width_byte + LV_DRAW_BUF_STRIDE_ALIGN - 1) & ~(LV_DRAW_BUF_STRIDE_ALIGN - 1);
}
uint32_t lv_draw_buf_get_stride(const lv_draw_buf_t * draw_buf)
@@ -93,9 +102,9 @@ void * lv_draw_buf_go_to_xy(lv_draw_buf_t * draw_buf, lv_coord_t x, lv_coord_t y
return buf_tmp;
}
void lv_draw_buf_clear(lv_draw_buf_t * draw_buf, const lv_area_t * a)
{
//TODO clear the area
LV_UNUSED(a);
uint32_t stride = lv_draw_buf_get_stride(draw_buf);
uint8_t * buf = lv_draw_buf_get_buf(draw_buf);
@@ -139,3 +148,6 @@ static uint8_t * buf_alloc(void * old_buf, lv_coord_t w, lv_coord_t h)
return buf;
}
#endif /*LV_USE DRAW_BUF == LV_DRAW_BUF_BASIC*/
+28 -16
View File
@@ -214,26 +214,38 @@
/*========================
* RENDERING CONFIGURATION
*========================*/
/*Align the stride of all layers and images to this bytes*/
#ifndef LV_DRAW_BUF_STRIDE_ALIGN
#ifdef _LV_KCONFIG_PRESENT
#ifdef CONFIG_LV_DRAW_BUF_STRIDE_ALIGN
#define LV_DRAW_BUF_STRIDE_ALIGN CONFIG_LV_DRAW_BUF_STRIDE_ALIGN
#else
#define LV_DRAW_BUF_STRIDE_ALIGN 0
#endif
/* Select a draw buffer implementation. Possible values:
* - LV_DRAW_BUF_BASIC: LVGL's built in implementation
* - LV_DRAW_BUF_CUSTOM: Implement teh function of lv_draw_buf.h externally
*/
#ifndef LV_USE_DRAW_BUF
#ifdef CONFIG_LV_USE_DRAW_BUF
#define LV_USE_DRAW_BUF CONFIG_LV_USE_DRAW_BUF
#else
#define LV_DRAW_BUF_STRIDE_ALIGN 1
#define LV_USE_DRAW_BUF LV_DRAW_BUF_BASIC
#endif
#endif
/*Align the start address of draw_buf addresses to this bytes*/
#ifndef LV_DRAW_BUF_ALIGN
#ifdef CONFIG_LV_DRAW_BUF_ALIGN
#define LV_DRAW_BUF_ALIGN CONFIG_LV_DRAW_BUF_ALIGN
#else
#define LV_DRAW_BUF_ALIGN 4
#if LV_USE_DRAW_BUF == LV_DRAW_BUF_BASIC
/*Align the stride of all layers and images to this bytes*/
#ifndef LV_DRAW_BUF_STRIDE_ALIGN
#ifdef _LV_KCONFIG_PRESENT
#ifdef CONFIG_LV_DRAW_BUF_STRIDE_ALIGN
#define LV_DRAW_BUF_STRIDE_ALIGN CONFIG_LV_DRAW_BUF_STRIDE_ALIGN
#else
#define LV_DRAW_BUF_STRIDE_ALIGN 0
#endif
#else
#define LV_DRAW_BUF_STRIDE_ALIGN 1 /*Multiple of these Bytes*/
#endif
#endif
/*Align the start address of draw_buf addresses to this bytes*/
#ifndef LV_DRAW_BUF_ALIGN
#ifdef CONFIG_LV_DRAW_BUF_ALIGN
#define LV_DRAW_BUF_ALIGN CONFIG_LV_DRAW_BUF_ALIGN
#else
#define LV_DRAW_BUF_ALIGN 4
#endif
#endif
#endif
+3
View File
@@ -44,6 +44,9 @@ extern "C" {
#define LV_STDLIB_MICROPYTHON 2
#define LV_STDLIB_CUSTOM 255
#define LV_DRAW_BUF_BASIC 0
#define LV_DRAW_BUF_CUSTOM 255
/**********************
* TYPEDEFS
**********************/