refact(draw_vector): standardized draw gradient API (#6344)

Signed-off-by: FASTSHIFT <vifextech@foxmail.com>
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com>
Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
VIFEX
2024-06-20 18:31:21 +08:00
committed by GitHub
co-authored by pengyiqiang
parent 37e4e4b4d0
commit e1547a126f
43 changed files with 767 additions and 574 deletions
+46 -27
View File
@@ -85,18 +85,7 @@ static void _multiply_matrix(lv_matrix_t * matrix, const lv_matrix_t * mul)
static void _copy_draw_dsc(lv_vector_draw_dsc_t * dst, const lv_vector_draw_dsc_t * src)
{
dst->fill_dsc.style = src->fill_dsc.style;
dst->fill_dsc.color = src->fill_dsc.color;
dst->fill_dsc.opa = src->fill_dsc.opa;
dst->fill_dsc.fill_rule = src->fill_dsc.fill_rule;
dst->fill_dsc.gradient.style = src->fill_dsc.gradient.style;
dst->fill_dsc.gradient.cx = src->fill_dsc.gradient.cx;
dst->fill_dsc.gradient.cy = src->fill_dsc.gradient.cy;
dst->fill_dsc.gradient.cr = src->fill_dsc.gradient.cr;
dst->fill_dsc.gradient.spread = src->fill_dsc.gradient.spread;
lv_memcpy(&(dst->fill_dsc.gradient.grad), &(src->fill_dsc.gradient.grad), sizeof(lv_grad_dsc_t));
lv_memcpy(&(dst->fill_dsc.img_dsc), &(src->fill_dsc.img_dsc), sizeof(lv_draw_image_dsc_t));
lv_memcpy(&(dst->fill_dsc.matrix), &(src->fill_dsc.matrix), sizeof(lv_matrix_t));
lv_memcpy(&(dst->fill_dsc), &(src->fill_dsc), sizeof(lv_vector_fill_dsc_t));
dst->stroke_dsc.style = src->stroke_dsc.style;
dst->stroke_dsc.color = src->stroke_dsc.color;
@@ -111,7 +100,7 @@ static void _copy_draw_dsc(lv_vector_draw_dsc_t * dst, const lv_vector_draw_dsc_
dst->stroke_dsc.gradient.cy = src->stroke_dsc.gradient.cy;
dst->stroke_dsc.gradient.cr = src->stroke_dsc.gradient.cr;
dst->stroke_dsc.gradient.spread = src->fill_dsc.gradient.spread;
lv_memcpy(&(dst->stroke_dsc.gradient.grad), &(src->stroke_dsc.gradient.grad), sizeof(lv_grad_dsc_t));
lv_memcpy(&(dst->stroke_dsc.gradient), &(src->stroke_dsc.gradient), sizeof(lv_vector_gradient_t));
lv_memcpy(&(dst->stroke_dsc.matrix), &(src->stroke_dsc.matrix), sizeof(lv_matrix_t));
dst->blend_mode = src->blend_mode;
@@ -666,25 +655,40 @@ void lv_vector_dsc_set_fill_image(lv_vector_dsc_t * dsc, const lv_draw_image_dsc
lv_memcpy(&(dsc->current_dsc.fill_dsc.img_dsc), img_dsc, sizeof(lv_draw_image_dsc_t));
}
void lv_vector_dsc_set_fill_linear_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad,
lv_vector_gradient_spread_t spread)
void lv_vector_dsc_set_fill_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2)
{
dsc->current_dsc.fill_dsc.style = LV_VECTOR_DRAW_STYLE_GRADIENT;
dsc->current_dsc.fill_dsc.gradient.style = LV_VECTOR_GRADIENT_STYLE_LINEAR;
dsc->current_dsc.fill_dsc.gradient.spread = spread;
lv_memcpy(&(dsc->current_dsc.fill_dsc.gradient.grad), grad, sizeof(lv_grad_dsc_t));
dsc->current_dsc.fill_dsc.gradient.x1 = x1;
dsc->current_dsc.fill_dsc.gradient.y1 = y1;
dsc->current_dsc.fill_dsc.gradient.x2 = x2;
dsc->current_dsc.fill_dsc.gradient.y2 = y2;
}
void lv_vector_dsc_set_fill_radial_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad, float cx, float cy,
float radius, lv_vector_gradient_spread_t spread)
void lv_vector_dsc_set_fill_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius)
{
dsc->current_dsc.fill_dsc.style = LV_VECTOR_DRAW_STYLE_GRADIENT;
dsc->current_dsc.fill_dsc.gradient.style = LV_VECTOR_GRADIENT_STYLE_RADIAL;
dsc->current_dsc.fill_dsc.gradient.cx = cx;
dsc->current_dsc.fill_dsc.gradient.cy = cy;
dsc->current_dsc.fill_dsc.gradient.cr = radius;
}
void lv_vector_dsc_set_fill_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread)
{
dsc->current_dsc.fill_dsc.gradient.spread = spread;
lv_memcpy(&(dsc->current_dsc.fill_dsc.gradient.grad), grad, sizeof(lv_grad_dsc_t));
}
void lv_vector_dsc_set_fill_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count)
{
if(count > LV_GRADIENT_MAX_STOPS) {
LV_LOG_WARN("Too many gradient stops. Truncating to %d", LV_GRADIENT_MAX_STOPS);
count = LV_GRADIENT_MAX_STOPS;
}
lv_memcpy(&(dsc->current_dsc.fill_dsc.gradient.stops), stops, sizeof(lv_gradient_stop_t) * count);
dsc->current_dsc.fill_dsc.gradient.stops_count = count;
}
void lv_vector_dsc_set_fill_transform(lv_vector_dsc_t * dsc, const lv_matrix_t * matrix)
@@ -754,25 +758,40 @@ void lv_vector_dsc_set_stroke_miter_limit(lv_vector_dsc_t * dsc, uint16_t miter_
dsc->current_dsc.stroke_dsc.miter_limit = miter_limit;
}
void lv_vector_dsc_set_stroke_linear_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad,
lv_vector_gradient_spread_t spread)
void lv_vector_dsc_set_stroke_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2)
{
dsc->current_dsc.stroke_dsc.style = LV_VECTOR_DRAW_STYLE_GRADIENT;
dsc->current_dsc.stroke_dsc.gradient.style = LV_VECTOR_GRADIENT_STYLE_LINEAR;
dsc->current_dsc.stroke_dsc.gradient.spread = spread;
lv_memcpy(&(dsc->current_dsc.stroke_dsc.gradient.grad), grad, sizeof(lv_grad_dsc_t));
dsc->current_dsc.stroke_dsc.gradient.x1 = x1;
dsc->current_dsc.stroke_dsc.gradient.y1 = y1;
dsc->current_dsc.stroke_dsc.gradient.x2 = x2;
dsc->current_dsc.stroke_dsc.gradient.y2 = y2;
}
void lv_vector_dsc_set_stroke_radial_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad, float cx, float cy,
float radius, lv_vector_gradient_spread_t spread)
void lv_vector_dsc_set_stroke_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius)
{
dsc->current_dsc.stroke_dsc.style = LV_VECTOR_DRAW_STYLE_GRADIENT;
dsc->current_dsc.stroke_dsc.gradient.style = LV_VECTOR_GRADIENT_STYLE_RADIAL;
dsc->current_dsc.stroke_dsc.gradient.cx = cx;
dsc->current_dsc.stroke_dsc.gradient.cy = cy;
dsc->current_dsc.stroke_dsc.gradient.cr = radius;
}
void lv_vector_dsc_set_stroke_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread)
{
dsc->current_dsc.stroke_dsc.gradient.spread = spread;
lv_memcpy(&(dsc->current_dsc.stroke_dsc.gradient.grad), grad, sizeof(lv_grad_dsc_t));
}
void lv_vector_dsc_set_stroke_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count)
{
if(count > LV_GRADIENT_MAX_STOPS) {
LV_LOG_WARN("Too many gradient stops. Truncating to %d", LV_GRADIENT_MAX_STOPS);
count = LV_GRADIENT_MAX_STOPS;
}
lv_memcpy(&(dsc->current_dsc.stroke_dsc.gradient.stops), stops, sizeof(lv_gradient_stop_t) * count);
dsc->current_dsc.stroke_dsc.gradient.stops_count = count;
}
/* draw functions */
+57 -22
View File
@@ -107,7 +107,12 @@ typedef struct {
typedef struct {
lv_vector_gradient_style_t style;
lv_grad_dsc_t grad;
lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS]; /**< A gradient stop array */
uint16_t stops_count; /**< The number of used stops in the array */
float x1;
float y1;
float x2;
float y2;
float cx;
float cy;
float cr;
@@ -391,24 +396,39 @@ void lv_vector_dsc_set_fill_image(lv_vector_dsc_t * dsc, const lv_draw_image_dsc
/**
* Set fill linear gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param grad pointer to a `lv_grad_dsc_t` variable
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
* @param dsc pointer to a vector graphic descriptor
* @param x1 the x for start point
* @param y1 the y for start point
* @param x2 the x for end point
* @param y2 the y for end point
*/
void lv_vector_dsc_set_fill_linear_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad,
lv_vector_gradient_spread_t spread);
void lv_vector_dsc_set_fill_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2);
/**
* Set fill radial gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param grad pointer to a `lv_grad_dsc_t` variable
* @param cx the x for center of the circle
* @param cy the y for center of the circle
* @param radius the radius for circle
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
* Set fill radial gradient radius for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param cx the x for center of the circle
* @param cy the y for center of the circle
* @param radius the radius for circle
*/
void lv_vector_dsc_set_fill_radial_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad, float cx, float cy,
float radius, lv_vector_gradient_spread_t spread);
void lv_vector_dsc_set_fill_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius);
/**
* Set fill radial gradient spread for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
*/
void lv_vector_dsc_set_fill_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread);
/**
* Set fill gradient color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param stops an array of `lv_gradient_stop_t` variables
* @param count the number of stops in the array
*/
void lv_vector_dsc_set_fill_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count);
/**
* Set a matrix to current fill transformation matrix
@@ -477,22 +497,37 @@ void lv_vector_dsc_set_stroke_miter_limit(lv_vector_dsc_t * dsc, uint16_t miter_
/**
* Set stroke linear gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param grad pointer to a `lv_grad_dsc_t` variable
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
* @param x1 the x for start point
* @param y1 the y for start point
* @param x2 the x for end point
* @param y2 the y for end point
*/
void lv_vector_dsc_set_stroke_linear_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad,
lv_vector_gradient_spread_t spread);
void lv_vector_dsc_set_stroke_linear_gradient(lv_vector_dsc_t * dsc, float x1, float y1, float x2, float y2);
/**
* Set stroke radial gradient for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param grad pointer to a `lv_grad_dsc_t` variable
* @param cx the x for center of the circle
* @param cy the y for center of the circle
* @param radius the radius for circle
*/
void lv_vector_dsc_set_stroke_radial_gradient(lv_vector_dsc_t * dsc, float cx, float cy, float radius);
/**
* Set stroke color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param spread the gradient spread to be set in lv_vector_gradient_spread_t format
*/
void lv_vector_dsc_set_stroke_radial_gradient(lv_vector_dsc_t * dsc, const lv_grad_dsc_t * grad, float cx, float cy,
float radius, lv_vector_gradient_spread_t spread);
void lv_vector_dsc_set_stroke_gradient_spread(lv_vector_dsc_t * dsc, lv_vector_gradient_spread_t spread);
/**
* Set stroke color stops for descriptor
* @param dsc pointer to a vector graphic descriptor
* @param stops an array of `lv_gradient_stop_t` variables
* @param count the number of stops in the array
*/
void lv_vector_dsc_set_stroke_gradient_color_stops(lv_vector_dsc_t * dsc, const lv_gradient_stop_t * stops,
uint16_t count);
/**
* Set a matrix to current stroke transformation matrix
* @param dsc pointer to a vector graphic descriptor
+9 -29
View File
@@ -180,10 +180,10 @@ static Tvg_Stroke_Fill _lv_spread_to_tvg(lv_vector_gradient_spread_t sp)
static void _setup_gradient(Tvg_Gradient * gradient, const lv_vector_gradient_t * grad,
const lv_matrix_t * matrix)
{
const lv_grad_dsc_t * g = &grad->grad;
Tvg_Color_Stop * stops = (Tvg_Color_Stop *)lv_malloc(sizeof(Tvg_Color_Stop) * g->stops_count);
for(uint8_t i = 0; i < g->stops_count; i++) {
const lv_gradient_stop_t * s = &(g->stops[i]);
Tvg_Color_Stop * stops = (Tvg_Color_Stop *)lv_malloc(sizeof(Tvg_Color_Stop) * grad->stops_count);
LV_ASSERT_MALLOC(stops);
for(uint16_t i = 0; i < grad->stops_count; i++) {
const lv_gradient_stop_t * s = &(grad->stops[i]);
stops[i].offset = s->frac / 255.0f;
stops[i].r = s->color.red;
@@ -192,7 +192,7 @@ static void _setup_gradient(Tvg_Gradient * gradient, const lv_vector_gradient_t
stops[i].a = s->opa;
}
tvg_gradient_set_color_stops(gradient, stops, g->stops_count);
tvg_gradient_set_color_stops(gradient, stops, grad->stops_count);
tvg_gradient_set_spread(gradient, _lv_spread_to_tvg(grad->spread));
Tvg_Matrix mtx;
_lv_matrix_to_tvg(&mtx, matrix);
@@ -202,26 +202,16 @@ static void _setup_gradient(Tvg_Gradient * gradient, const lv_vector_gradient_t
static void _set_paint_stroke_gradient(Tvg_Paint * obj, const lv_vector_gradient_t * g, const lv_matrix_t * m)
{
float x, y, w, h;
tvg_paint_get_bounds(obj, &x, &y, &w, &h, false);
Tvg_Gradient * grad = NULL;
if(g->style == LV_VECTOR_GRADIENT_STYLE_RADIAL) {
grad = tvg_radial_gradient_new();
tvg_radial_gradient_set(grad, g->cx + x, g->cy + y, g->cr);
tvg_radial_gradient_set(grad, g->cx, g->cy, g->cr);
_setup_gradient(grad, g, m);
tvg_shape_set_stroke_radial_gradient(obj, grad);
}
else {
grad = tvg_linear_gradient_new();
if(g->grad.dir == LV_GRAD_DIR_VER) {
tvg_linear_gradient_set(grad, x, y, x, y + h);
}
else {
tvg_linear_gradient_set(grad, x, y, x + w, y);
}
tvg_linear_gradient_set(grad, g->x1, g->y1, g->x2, g->y2);
_setup_gradient(grad, g, m);
tvg_shape_set_stroke_linear_gradient(obj, grad);
}
@@ -263,26 +253,16 @@ static Tvg_Fill_Rule _lv_fill_rule_to_tvg(lv_vector_fill_t rule)
static void _set_paint_fill_gradient(Tvg_Paint * obj, const lv_vector_gradient_t * g, const lv_matrix_t * m)
{
float x, y, w, h;
tvg_paint_get_bounds(obj, &x, &y, &w, &h, false);
Tvg_Gradient * grad = NULL;
if(g->style == LV_VECTOR_GRADIENT_STYLE_RADIAL) {
grad = tvg_radial_gradient_new();
tvg_radial_gradient_set(grad, g->cx + x, g->cy + y, g->cr);
tvg_radial_gradient_set(grad, g->cx, g->cy, g->cr);
_setup_gradient(grad, g, m);
tvg_shape_set_radial_gradient(obj, grad);
}
else {
grad = tvg_linear_gradient_new();
if(g->grad.dir == LV_GRAD_DIR_VER) {
tvg_linear_gradient_set(grad, x, y, x, y + h);
}
else {
tvg_linear_gradient_set(grad, x, y, x + w, y);
}
tvg_linear_gradient_set(grad, g->x1, g->y1, g->x2, g->y2);
_setup_gradient(grad, g, m);
tvg_shape_set_linear_gradient(obj, grad);
}
+5 -1
View File
@@ -72,7 +72,9 @@ void lv_draw_vg_lite_init(void)
unit->base_unit.delete_cb = draw_delete;
lv_vg_lite_image_dsc_init(unit);
lv_vg_lite_grad_init(unit, LV_VG_LITE_LINEAR_GRAD_CACHE_CNT, LV_VG_LITE_RADIAL_GRAD_CACHE_CNT);
#if LV_USE_VECTOR_GRAPHIC
lv_vg_lite_grad_init(unit, LV_VG_LITE_GRAD_CACHE_CNT);
#endif
lv_vg_lite_path_init(unit);
lv_vg_lite_decoder_init();
}
@@ -250,7 +252,9 @@ static int32_t draw_delete(lv_draw_unit_t * draw_unit)
lv_draw_vg_lite_unit_t * unit = (lv_draw_vg_lite_unit_t *)draw_unit;
lv_vg_lite_image_dsc_deinit(unit);
#if LV_USE_VECTOR_GRAPHIC
lv_vg_lite_grad_deinit(unit);
#endif
lv_vg_lite_path_deinit(unit);
lv_vg_lite_decoder_deinit();
return 1;
+6 -4
View File
@@ -81,17 +81,19 @@ void lv_draw_vg_lite_fill(lv_draw_unit_t * draw_unit, const lv_draw_fill_dsc_t *
LV_VG_LITE_ASSERT_MATRIX(&matrix);
if(dsc->grad.dir != LV_GRAD_DIR_NONE) {
vg_lite_matrix_t grad_matrix;
lv_vg_lite_grad_area_to_matrix(&grad_matrix, coords, dsc->grad.dir);
lv_vg_lite_draw_linear_grad(
#if LV_USE_VECTOR_GRAPHIC
lv_vg_lite_draw_grad_helper(
u,
&u->target_buffer,
vg_lite_path,
coords,
&dsc->grad,
&grad_matrix,
&matrix,
VG_LITE_FILL_EVEN_ODD,
VG_LITE_BLEND_SRC_OVER);
#else
LV_LOG_WARN("Gradient fill is not supported without VECTOR_GRAPHIC");
#endif
}
else { /* normal fill */
vg_lite_color_t color = lv_vg_lite_color(dsc->color, dsc->opa, true);
+6 -4
View File
@@ -76,17 +76,19 @@ void lv_draw_vg_lite_triangle(lv_draw_unit_t * draw_unit, const lv_draw_triangle
LV_VG_LITE_ASSERT_MATRIX(&matrix);
if(dsc->bg_grad.dir != LV_GRAD_DIR_NONE) {
vg_lite_matrix_t grad_matrix;
lv_vg_lite_grad_area_to_matrix(&grad_matrix, &tri_area, dsc->bg_grad.dir);
lv_vg_lite_draw_linear_grad(
#if LV_USE_VECTOR_GRAPHIC
lv_vg_lite_draw_grad_helper(
u,
&u->target_buffer,
vg_lite_path,
&tri_area,
&dsc->bg_grad,
&grad_matrix,
&matrix,
VG_LITE_FILL_EVEN_ODD,
VG_LITE_BLEND_SRC_OVER);
#else
LV_LOG_WARN("Gradient fill is not supported without VECTOR_GRAPHIC");
#endif
}
else { /* normal fill */
vg_lite_color_t color = lv_vg_lite_color(dsc->bg_color, dsc->bg_opa, true);
+2 -5
View File
@@ -43,11 +43,8 @@ struct _lv_draw_vg_lite_unit_t {
struct _lv_vg_lite_pending_t * image_dsc_pending;
lv_cache_t * linear_grad_cache;
struct _lv_vg_lite_pending_t * linear_grad_pending;
lv_cache_t * radial_grad_cache;
struct _lv_vg_lite_pending_t * radial_grad_pending;
lv_cache_t * grad_cache;
struct _lv_vg_lite_pending_t * grad_pending;
uint16_t flush_count;
vg_lite_buffer_t target_buffer;
+11 -41
View File
@@ -203,48 +203,18 @@ static void task_draw_cb(void * ctx, const lv_vector_path_t * path, const lv_vec
}
break;
case LV_VECTOR_DRAW_STYLE_GRADIENT: {
/* draw gradient */
lv_vector_gradient_style_t style = dsc->fill_dsc.gradient.style;
vg_lite_matrix_t grad_matrix;
lv_matrix_to_vg(&grad_matrix, &dsc->fill_dsc.matrix);
if(style == LV_VECTOR_GRADIENT_STYLE_LINEAR) {
vg_lite_matrix_t grad_matrix, fill_matrix;
lv_area_t grad_area;
lv_area_set(&grad_area, (int32_t)min_x, (int32_t)min_y, (int32_t)max_x, (int32_t)max_y);
lv_vg_lite_grad_area_to_matrix(&grad_matrix, &grad_area, LV_GRAD_DIR_HOR);
lv_matrix_to_vg(&fill_matrix, &dsc->fill_dsc.matrix);
lv_vg_lite_matrix_multiply(&grad_matrix, &matrix);
lv_vg_lite_matrix_multiply(&grad_matrix, &fill_matrix);
lv_vg_lite_draw_linear_grad(
u,
&u->target_buffer,
vg_path,
&dsc->fill_dsc.gradient.grad,
&grad_matrix,
&matrix,
fill,
blend);
}
else if(style == LV_VECTOR_GRADIENT_STYLE_RADIAL) {
vg_lite_matrix_t grad_matrix;
lv_matrix_to_vg(&grad_matrix, &dsc->fill_dsc.matrix);
/* add min_x, min_y to gradient center */
lv_vector_gradient_t new_grad = dsc->fill_dsc.gradient;
new_grad.cx += min_x;
new_grad.cy += min_y;
lv_vg_lite_draw_radial_grad(
u,
&u->target_buffer,
vg_path,
&new_grad,
&grad_matrix,
&matrix,
fill,
blend);
}
lv_vg_lite_draw_grad(
u,
&u->target_buffer,
vg_path,
&dsc->fill_dsc.gradient,
&grad_matrix,
&matrix,
fill,
blend);
}
break;
default:
File diff suppressed because it is too large Load Diff
+13 -22
View File
@@ -16,7 +16,7 @@ extern "C" {
#include "../../lvgl.h"
#if LV_USE_DRAW_VG_LITE
#if LV_USE_DRAW_VG_LITE && LV_USE_VECTOR_GRAPHIC
#include "lv_vg_lite_utils.h"
@@ -32,28 +32,11 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
void lv_vg_lite_grad_init(
struct _lv_draw_vg_lite_unit_t * u,
uint32_t linear_grad_cache_cnt,
uint32_t radial_grad_cache_cnt);
void lv_vg_lite_grad_init(struct _lv_draw_vg_lite_unit_t * u, uint32_t cache_cnt);
void lv_vg_lite_grad_deinit(struct _lv_draw_vg_lite_unit_t * u);
void lv_vg_lite_grad_area_to_matrix(vg_lite_matrix_t * grad_matrix, const lv_area_t * area, lv_grad_dir_t dir);
void lv_vg_lite_draw_linear_grad(
struct _lv_draw_vg_lite_unit_t * u,
vg_lite_buffer_t * buffer,
vg_lite_path_t * path,
const lv_grad_dsc_t * grad,
const vg_lite_matrix_t * grad_matrix,
const vg_lite_matrix_t * matrix,
vg_lite_fill_t fill,
vg_lite_blend_t blend);
#if LV_USE_VECTOR_GRAPHIC
void lv_vg_lite_draw_radial_grad(
bool lv_vg_lite_draw_grad(
struct _lv_draw_vg_lite_unit_t * u,
vg_lite_buffer_t * buffer,
vg_lite_path_t * path,
@@ -63,13 +46,21 @@ void lv_vg_lite_draw_radial_grad(
vg_lite_fill_t fill,
vg_lite_blend_t blend);
#endif /* LV_USE_VECTOR_GRAPHIC */
bool lv_vg_lite_draw_grad_helper(
struct _lv_draw_vg_lite_unit_t * u,
vg_lite_buffer_t * buffer,
vg_lite_path_t * path,
const lv_area_t * area,
const lv_grad_dsc_t * grad_dsc,
const vg_lite_matrix_t * matrix,
vg_lite_fill_t fill,
vg_lite_blend_t blend);
/**********************
* MACROS
**********************/
#endif /*LV_USE_DRAW_VG_LITE*/
#endif /*LV_USE_DRAW_VG_LITE && LV_USE_VECTOR_GRAPHIC*/
#ifdef __cplusplus
} /*extern "C"*/
+2 -4
View File
@@ -1079,10 +1079,8 @@ void lv_vg_lite_finish(struct _lv_draw_vg_lite_unit_t * u)
LV_VG_LITE_CHECK_ERROR(vg_lite_finish());
/* Clear all gradient caches reference */
lv_vg_lite_pending_remove_all(u->linear_grad_pending);
if(u->radial_grad_pending) {
lv_vg_lite_pending_remove_all(u->radial_grad_pending);
if(u->grad_pending) {
lv_vg_lite_pending_remove_all(u->grad_pending);
}
/* Clear image decoder dsc reference */
+14 -16
View File
@@ -657,25 +657,14 @@
#endif
#endif
/* VG-Lite linear gradient image maximum cache number.
/* VG-Lite gradient maximum cache number.
* NOTE: The memory usage of a single gradient image is 4K bytes.
*/
#ifndef LV_VG_LITE_LINEAR_GRAD_CACHE_CNT
#ifdef CONFIG_LV_VG_LITE_LINEAR_GRAD_CACHE_CNT
#define LV_VG_LITE_LINEAR_GRAD_CACHE_CNT CONFIG_LV_VG_LITE_LINEAR_GRAD_CACHE_CNT
#ifndef LV_VG_LITE_GRAD_CACHE_CNT
#ifdef CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
#define LV_VG_LITE_GRAD_CACHE_CNT CONFIG_LV_VG_LITE_GRAD_CACHE_CNT
#else
#define LV_VG_LITE_LINEAR_GRAD_CACHE_CNT 32
#endif
#endif
/* VG-Lite radial gradient image maximum cache size.
* NOTE: The memory usage of a single gradient image is radial grad radius * 4 bytes.
*/
#ifndef LV_VG_LITE_RADIAL_GRAD_CACHE_CNT
#ifdef CONFIG_LV_VG_LITE_RADIAL_GRAD_CACHE_CNT
#define LV_VG_LITE_RADIAL_GRAD_CACHE_CNT CONFIG_LV_VG_LITE_RADIAL_GRAD_CACHE_CNT
#else
#define LV_VG_LITE_RADIAL_GRAD_CACHE_CNT 32
#define LV_VG_LITE_GRAD_CACHE_CNT 32
#endif
#endif
@@ -1121,6 +1110,15 @@
#endif
#endif
/*Enable Linear gradient extension support*/
#ifndef LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT
#ifdef CONFIG_LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT
#define LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT CONFIG_LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT
#else
#define LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT 0
#endif
#endif
/*Enable 16 pixels alignment*/
#ifndef LV_VG_LITE_THORVG_16PIXELS_ALIGN
#ifdef _LV_KCONFIG_PRESENT
+54 -4
View File
@@ -463,10 +463,13 @@ extern "C" {
vg_lite_uint32_t stride = VG_LITE_ALIGN((buffer->width * mul / div), align);
buffer->stride = stride;
/* Size must be multiple of align, See: https://en.cppreference.com/w/c/memory/aligned_alloc */
size_t size = VG_LITE_ALIGN(buffer->height * stride, LV_VG_LITE_THORVG_BUF_ADDR_ALIGN);
#ifndef _WIN32
buffer->memory = aligned_alloc(LV_VG_LITE_THORVG_BUF_ADDR_ALIGN, stride * buffer->height);
buffer->memory = aligned_alloc(LV_VG_LITE_THORVG_BUF_ADDR_ALIGN, size);
#else
buffer->memory = _aligned_malloc(stride * buffer->height, LV_VG_LITE_THORVG_BUF_ADDR_ALIGN);
buffer->memory = _aligned_malloc(size, LV_VG_LITE_THORVG_BUF_ADDR_ALIGN);
#endif
LV_ASSERT(buffer->memory);
buffer->address = (vg_lite_uint32_t)(uintptr_t)buffer->memory;
@@ -829,6 +832,10 @@ extern "C" {
case gcFEATURE_BIT_VG_YUV_INPUT:
#endif
#if LV_VG_LITE_THORVG_LINEAR_GRADIENT_EXT_SUPPORT
case gcFEATURE_BIT_VG_LINEAR_GRADIENT_EXT:
#endif
#if LV_VG_LITE_THORVG_16PIXELS_ALIGN
case gcFEATURE_BIT_VG_16PIXELS_ALIGN:
#endif
@@ -1264,6 +1271,49 @@ Empty_sequence_handler:
return VG_LITE_SUCCESS;
}
vg_lite_error_t vg_lite_draw_linear_grad(vg_lite_buffer_t * target,
vg_lite_path_t * path,
vg_lite_fill_t fill_rule,
vg_lite_matrix_t * path_matrix,
vg_lite_ext_linear_gradient_t * grad,
vg_lite_color_t paint_color,
vg_lite_blend_t blend,
vg_lite_filter_t filter)
{
LV_UNUSED(paint_color);
LV_UNUSED(filter);
auto ctx = vg_lite_ctx::get_instance();
TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target));
auto shape = Shape::gen();
TVG_CHECK_RETURN_VG_ERROR(shape_append_path(shape, path, path_matrix));
TVG_CHECK_RETURN_VG_ERROR(shape->transform(matrix_conv(path_matrix)));
TVG_CHECK_RETURN_VG_ERROR(shape->fill(fill_rule_conv(fill_rule)););
TVG_CHECK_RETURN_VG_ERROR(shape->blend(blend_method_conv(blend)));
auto linearGrad = LinearGradient::gen();
TVG_CHECK_RETURN_VG_ERROR(linearGrad->linear(grad->linear_grad.X0, grad->linear_grad.Y0, grad->linear_grad.X1,
grad->linear_grad.Y1));
TVG_CHECK_RETURN_VG_ERROR(linearGrad->transform(matrix_conv(&grad->matrix)));
TVG_CHECK_RETURN_VG_ERROR(linearGrad->spread(fill_spread_conv(grad->spread_mode)));
tvg::Fill::ColorStop colorStops[VLC_MAX_COLOR_RAMP_STOPS];
for(vg_lite_uint32_t i = 0; i < grad->ramp_length; i++) {
colorStops[i].offset = grad->color_ramp[i].stop;
colorStops[i].r = grad->color_ramp[i].red * 255.0f;
colorStops[i].g = grad->color_ramp[i].green * 255.0f;
colorStops[i].b = grad->color_ramp[i].blue * 255.0f;
colorStops[i].a = grad->color_ramp[i].alpha * 255.0f;
}
TVG_CHECK_RETURN_VG_ERROR(linearGrad->colorStops(colorStops, grad->ramp_length));
TVG_CHECK_RETURN_VG_ERROR(shape->fill(std::move(linearGrad)));
TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(shape)));
return VG_LITE_SUCCESS;
}
vg_lite_error_t vg_lite_set_radial_grad(vg_lite_radial_gradient_t * grad,
vg_lite_uint32_t count,
vg_lite_color_ramp_t * color_ramp,
@@ -1720,8 +1770,8 @@ Empty_sequence_handler:
float y_max = y_min + dlen * sinf(angle);
LV_LOG_TRACE("linear gradient {%.2f, %.2f} ~ {%.2f, %.2f}", x_min, y_min, x_max, y_max);
auto linearGrad = LinearGradient::gen();
linearGrad->linear(x_min, y_min, x_max, y_max);
linearGrad->spread(FillSpread::Pad);
TVG_CHECK_RETURN_VG_ERROR(linearGrad->linear(x_min, y_min, x_max, y_max));
TVG_CHECK_RETURN_VG_ERROR(linearGrad->spread(FillSpread::Pad));
tvg::Fill::ColorStop colorStops[VLC_MAX_GRADIENT_STOPS];
for(vg_lite_uint32_t i = 0; i < grad->count; i++) {