LVGL 库提交

This commit is contained in:
2026-08-30 08:57:07 +08:00
parent 26c9098630
commit e2f199c6bf
1056 changed files with 556743 additions and 45 deletions
@@ -0,0 +1,405 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx.c
*
*/
/*********************
* INCLUDES
*********************/
#include "../../core/lv_refr.h"
#if LV_USE_NEMA_GFX
#include "lv_draw_nema_gfx.h"
#include "../../font/lv_font.h"
#include "../../font/lv_font_fmt_txt.h"
/*********************
* DEFINES
*********************/
#define DRAW_UNIT_ID_NEMA_GFX 7
/**********************
* TYPEDEFS
**********************/
#if LV_USE_OS
/**
* Structure of pending nema_gfx draw task
*/
typedef struct _nema_gfx_draw_task_t {
lv_draw_task_t * task;
bool flushed;
} nema_gfx_draw_task_t;
#endif
/**********************
* STATIC PROTOTYPES
**********************/
#if LV_USE_OS
static void nema_gfx_render_thread_cb(void * ptr);
#endif
static void nema_gfx_execute_drawing(lv_draw_nema_gfx_unit_t * u);
static int32_t nema_gfx_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer);
static int32_t nema_gfx_evaluate(lv_draw_unit_t * draw_unit, lv_draw_task_t * task);
static int32_t nema_gfx_delete(lv_draw_unit_t * draw_unit);
static int32_t nema_gfx_wait_for_finish(lv_draw_unit_t * draw_unit);
/**********************
* STATIC VARIABLES
**********************/
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_init(void)
{
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = lv_draw_create_unit(sizeof(lv_draw_nema_gfx_unit_t));
/*Initialize NemaGFX*/
nema_init();
draw_nema_gfx_unit->base_unit.dispatch_cb = nema_gfx_dispatch;
draw_nema_gfx_unit->base_unit.evaluate_cb = nema_gfx_evaluate;
draw_nema_gfx_unit->base_unit.delete_cb = nema_gfx_delete;
draw_nema_gfx_unit->base_unit.wait_for_finish_cb = nema_gfx_wait_for_finish;
draw_nema_gfx_unit->base_unit.name = "NEMA_GFX";
#if LV_USE_NEMA_VG
/*Initialize NemaVG */
nema_vg_init(LV_NEMA_GFX_MAX_RESX, LV_NEMA_GFX_MAX_RESY);
/* Allocate VG Buffers*/
draw_nema_gfx_unit->paint = nema_vg_paint_create();
draw_nema_gfx_unit->gradient = nema_vg_grad_create();
draw_nema_gfx_unit->path = nema_vg_path_create();
/*Initialize Freetype Support*/
lv_draw_nema_gfx_label_init(&(draw_nema_gfx_unit->base_unit));
#endif
/*Create GPU Command List*/
draw_nema_gfx_unit->cl = nema_cl_create();
/*Bind Command List*/
nema_cl_bind_circular(&(draw_nema_gfx_unit->cl));
#if LV_USE_OS
lv_thread_init(&draw_nema_gfx_unit->thread, "nemagfx", LV_DRAW_THREAD_PRIO, nema_gfx_render_thread_cb, 2 * 1024,
draw_nema_gfx_unit);
#endif
}
void lv_draw_nema_gfx_deinit(void)
{
return;
}
/**********************
* STATIC FUNCTIONS
**********************/
static int32_t nema_gfx_wait_for_finish(lv_draw_unit_t * draw_unit)
{
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)draw_unit;
nema_cl_submit(&(draw_nema_gfx_unit->cl));
nema_cl_wait(&(draw_nema_gfx_unit->cl));
return 1;
}
static int32_t nema_gfx_evaluate(lv_draw_unit_t * draw_unit, lv_draw_task_t * task)
{
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)draw_unit;
switch(task->type) {
case LV_DRAW_TASK_TYPE_LAYER: {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
#if LV_USE_NEMA_VG
case LV_DRAW_TASK_TYPE_TRIANGLE:
case LV_DRAW_TASK_TYPE_ARC:
case LV_DRAW_TASK_TYPE_FILL: {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
#else
case LV_DRAW_TASK_TYPE_FILL: {
lv_draw_fill_dsc_t * draw_fill_dsc = (lv_draw_fill_dsc_t *) task->draw_dsc;
if((draw_fill_dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE)) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
case LV_DRAW_TASK_TYPE_TRIANGLE: {
lv_draw_triangle_dsc_t * draw_triangle_dsc = (lv_draw_triangle_dsc_t *) task->draw_dsc;
if((draw_triangle_dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE)) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
#endif
case LV_DRAW_TASK_TYPE_IMAGE: {
lv_draw_image_dsc_t * draw_image_dsc = (lv_draw_image_dsc_t *) task->draw_dsc;
/*Guard for previous NemaGFX Version*/
#ifndef NEMA_BLOP_RECOLOR
if(draw_image_dsc->recolor_opa > LV_OPA_MIN)
break;
#endif
const lv_image_dsc_t * img_dsc = draw_image_dsc->src;
if(!lv_nemagfx_is_cf_supported(img_dsc->header.cf))
break;
if(draw_image_dsc->blend_mode != LV_BLEND_MODE_SUBTRACTIVE) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
case LV_DRAW_TASK_TYPE_LABEL: {
lv_draw_label_dsc_t * draw_label_dsc = (lv_draw_label_dsc_t *) task->draw_dsc;
lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *)(draw_label_dsc->font->dsc);
if(fdsc->bitmap_format != LV_FONT_FMT_TXT_COMPRESSED) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
case LV_DRAW_TASK_TYPE_LINE: {
lv_draw_line_dsc_t * draw_line_dsc = (lv_draw_line_dsc_t *) task->draw_dsc;
bool is_dashed = (draw_line_dsc->dash_width && draw_line_dsc->dash_gap);
if(!is_dashed && !(draw_line_dsc->round_end || draw_line_dsc->round_start)) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
case LV_DRAW_TASK_TYPE_BORDER: {
const lv_draw_border_dsc_t * draw_dsc = (lv_draw_border_dsc_t *) task->draw_dsc;
if((!(draw_dsc->side != (lv_border_side_t)LV_BORDER_SIDE_FULL && draw_dsc->radius > 0)) &&
(draw_dsc->radius > draw_dsc->width)) {
if(task->preference_score > 80) {
task->preference_score = 80;
task->preferred_draw_unit_id = DRAW_UNIT_ID_NEMA_GFX;
}
return 1;
}
break;
}
case LV_DRAW_TASK_TYPE_BOX_SHADOW:
case LV_DRAW_TASK_TYPE_MASK_RECTANGLE:
case LV_DRAW_TASK_TYPE_MASK_BITMAP:
#if LV_USE_VECTOR_GRAPHIC
case LV_DRAW_TASK_TYPE_VECTOR:
#endif
default:
break;
}
nema_cl_wait(&(draw_nema_gfx_unit->cl));
return 0;
}
static int32_t nema_gfx_dispatch(lv_draw_unit_t * draw_unit, lv_layer_t * layer)
{
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *) draw_unit;
/* Return immediately if it's busy with draw task. */
if(draw_nema_gfx_unit->task_act)
return 0;
/* Try to get an ready to draw. */
lv_draw_task_t * t = lv_draw_get_available_task(layer, NULL, DRAW_UNIT_ID_NEMA_GFX);
/* Return 0 is no selection, some tasks can be supported by other units. */
if(t == NULL || t->preferred_draw_unit_id != DRAW_UNIT_ID_NEMA_GFX)
return LV_DRAW_UNIT_IDLE;
void * buf = lv_draw_layer_alloc_buf(layer);
if(buf == NULL)
return LV_DRAW_UNIT_IDLE;
t->state = LV_DRAW_TASK_STATE_IN_PROGRESS;
draw_nema_gfx_unit->task_act = t;
#if LV_USE_OS
/* Let the render thread work. */
if(draw_nema_gfx_unit->inited)
lv_thread_sync_signal(&draw_nema_gfx_unit->sync);
#else
nema_gfx_execute_drawing(draw_nema_gfx_unit);
draw_nema_gfx_unit->task_act->state = LV_DRAW_TASK_STATE_READY;
draw_nema_gfx_unit->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
#endif
return 1;
}
static void nema_gfx_execute_drawing(lv_draw_nema_gfx_unit_t * u)
{
lv_draw_task_t * t = u->task_act;
/* remember draw unit for access to unit's context */
t->draw_unit = (lv_draw_unit_t *)u;
switch(t->type) {
case LV_DRAW_TASK_TYPE_FILL:
lv_draw_nema_gfx_fill(t, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_IMAGE:
lv_draw_nema_gfx_img(t, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_TRIANGLE:
lv_draw_nema_gfx_triangle(t, t->draw_dsc);
break;
case LV_DRAW_TASK_TYPE_LABEL:
lv_draw_nema_gfx_label(t, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_LAYER:
lv_draw_nema_gfx_layer(t, t->draw_dsc, &t->area);
break;
case LV_DRAW_TASK_TYPE_LINE:
lv_draw_nema_gfx_line(t, t->draw_dsc);
break;
#if LV_USE_NEMA_VG
case LV_DRAW_TASK_TYPE_ARC:
lv_draw_nema_gfx_arc(t, t->draw_dsc, &t->area);
break;
#endif
case LV_DRAW_TASK_TYPE_BORDER:
lv_draw_nema_gfx_border(t, t->draw_dsc, &t->area);
break;
default:
break;
}
}
static int32_t nema_gfx_delete(lv_draw_unit_t * draw_unit)
{
#if LV_USE_NEMA_VG
/*Free VG Buffers*/
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *) draw_unit;
nema_vg_paint_destroy(draw_nema_gfx_unit->paint);
nema_vg_path_destroy(draw_nema_gfx_unit->path);
nema_vg_grad_destroy(draw_nema_gfx_unit->gradient);
#endif
#if LV_USE_OS
lv_draw_nema_gfx_unit_t * _draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *) draw_unit;
LV_LOG_INFO("Cancel NemaGFX draw thread.");
_draw_nema_gfx_unit->exit_status = true;
if(_draw_nema_gfx_unit->inited)
lv_thread_sync_signal(&_draw_nema_gfx_unit->sync);
lv_result_t res = lv_thread_delete(&_draw_nema_gfx_unit->thread);
return res;
#endif
#if LV_USE_NEMA_VG == 0 && LV_USE_OS == LV_OS_NONE
LV_UNUSED(draw_unit);
#endif
return 0;
}
#if LV_USE_OS
static void nema_gfx_render_thread_cb(void * ptr)
{
lv_draw_nema_gfx_unit_t * u = ptr;
lv_thread_sync_init(&u->sync);
u->inited = true;
while(1) {
/* Wait for sync if there is no task set. */
while(u->task_act == NULL) {
if(u->exit_status)
break;
lv_thread_sync_wait(&u->sync);
}
if(u->exit_status) {
LV_LOG_INFO("Ready to exit NemaGFX draw thread.");
break;
}
if(u->task_act) {
nema_gfx_execute_drawing(u);
}
/* Signal the ready state to dispatcher. */
u->task_act->state = LV_DRAW_TASK_STATE_READY;
/* Cleanup. */
u->task_act = NULL;
/* The draw unit is free now. Request a new dispatching as it can get a new task. */
lv_draw_dispatch_request();
}
u->inited = false;
lv_thread_sync_delete(&u->sync);
LV_LOG_INFO("Exit NemaGFX draw thread.");
}
#endif
#endif
@@ -0,0 +1,124 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx.h
*
*/
#ifndef LV_DRAW_NEMA_GFX_H
#define LV_DRAW_NEMA_GFX_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../lv_conf_internal.h"
#if LV_USE_NEMA_GFX
#include "lv_draw_nema_gfx_utils.h"
#include "../lv_draw_private.h"
#include "../lv_draw_buf_private.h"
#include "../lv_draw_image_private.h"
#include "../lv_image_decoder_private.h"
#include "../lv_draw_label_private.h"
#include "../lv_draw_mask_private.h"
#include "../lv_draw_rect_private.h"
#include "../lv_draw_triangle_private.h"
#include "../lv_draw_vector_private.h"
#include "../../misc/lv_area_private.h"
/**********************
* TYPEDEFS
**********************/
typedef struct {
lv_draw_unit_t base_unit;
lv_draw_task_t * task_act;
#if LV_USE_OS
lv_thread_sync_t sync;
lv_thread_t thread;
volatile bool inited;
volatile bool exit_status;
#endif
uint32_t idx;
nema_cmdlist_t cl;
#if LV_USE_NEMA_VG
NEMA_VG_PAINT_HANDLE paint;
NEMA_VG_GRAD_HANDLE gradient;
NEMA_VG_PATH_HANDLE path;
#endif
} lv_draw_nema_gfx_unit_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_draw_nema_gfx_init(void);
void lv_draw_nema_gfx_deinit(void);
void lv_draw_nema_gfx_fill(lv_draw_task_t * t,
const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords);
void lv_draw_nema_gfx_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * dsc);
void lv_draw_nema_gfx_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_nema_gfx_label(lv_draw_task_t * t, const lv_draw_label_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_nema_gfx_label_init(lv_draw_unit_t * draw_unit);
void lv_draw_nema_gfx_layer(lv_draw_task_t * t, const lv_draw_image_dsc_t * draw_dsc,
const lv_area_t * coords);
void lv_draw_nema_gfx_line(lv_draw_task_t * t, const lv_draw_line_dsc_t * dsc);
void lv_draw_nema_gfx_border(lv_draw_task_t * t, const lv_draw_border_dsc_t * dsc,
const lv_area_t * coords);
void lv_draw_nema_gfx_arc(lv_draw_task_t * t, const lv_draw_arc_dsc_t * dsc,
const lv_area_t * coords);
/**********************
* MACROS
**********************/
#endif /*LV_USE_NEMA_GFX*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_DRAW_NEMA_GFX_H*/
@@ -0,0 +1,105 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_arc.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX && LV_USE_NEMA_VG
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_arc(lv_draw_task_t * t, const lv_draw_arc_dsc_t * dsc, const lv_area_t * coords)
{
LV_UNUSED(coords);
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
if(dsc->width == 0)
return;
if(dsc->start_angle == dsc->end_angle)
return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
lv_point_t center = {dsc->center.x - layer->buf_area.x1, dsc->center.y - layer->buf_area.y1};
lv_area_t clip_area;
lv_area_copy(&clip_area, &t->clip_area);
lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
lv_value_precise_t start_angle = dsc->start_angle;
lv_value_precise_t end_angle = dsc->end_angle;
if(start_angle >= end_angle) {
end_angle += 360.0f;
}
if(end_angle - start_angle > 360.0f) {
start_angle = 0.0f;
end_angle = 360.0f;
}
else {
while(end_angle > 360.0f) {
start_angle -= 360.0f;
end_angle -= 360.0f;
}
}
nema_vg_paint_clear(draw_nema_gfx_unit->paint);
nema_vg_paint_set_type(draw_nema_gfx_unit->paint, NEMA_VG_PAINT_COLOR);
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
nema_vg_paint_set_paint_color(draw_nema_gfx_unit->paint, bg_color); // green
nema_vg_paint_set_stroke_width(draw_nema_gfx_unit->paint, dsc->width);
nema_vg_set_blend(NEMA_BL_SRC_OVER | NEMA_BLOP_SRC_PREMULT);
if(dsc->rounded == 1) {
nema_vg_draw_ring(center.x, center.y, (float)dsc->radius - (float)dsc->width * 0.5f, start_angle, end_angle,
draw_nema_gfx_unit->paint);
}
else {
nema_vg_draw_ring_generic(center.x, center.y, (float)dsc->radius - (float)dsc->width * 0.5f, start_angle,
end_angle, draw_nema_gfx_unit->paint, 0U);
}
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
#endif
@@ -0,0 +1,226 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
#include <math.h>
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_border(lv_draw_task_t * t, const lv_draw_border_dsc_t * dsc, const lv_area_t * coords)
{
if(dsc->opa <= LV_OPA_MIN)
return;
if(dsc->width == 0)
return;
if(dsc->side == LV_BORDER_SIDE_NONE)
return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
lv_area_t inward_coords;
int32_t width = dsc->width;
/* Move border inwards to align with software rendered border */
inward_coords.x1 = coords->x1 + ceil(width / 2.0f);
inward_coords.x2 = coords->x2 - floor(width / 2.0f);
inward_coords.y1 = coords->y1 + ceil(width / 2.0f);
inward_coords.y2 = coords->y2 - floor(width / 2.0f);
lv_area_move(&inward_coords, -layer->buf_area.x1, -layer->buf_area.y1);
lv_area_t clip_area;
lv_area_copy(&clip_area, &t->clip_area);
lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
lv_area_t clipped_coords;
if(!lv_area_intersect(&clipped_coords, &inward_coords, &clip_area))
return; /*Fully clipped, nothing to do*/
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
/* the stride should be computed internally for NEMA_TSC images and images missing a stride value */
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
/* Recalculate float Dimensions */
float x1 = (float)coords->x1 + ((float)width / 2.0f) - (float)layer->buf_area.x1;
float x2 = (float)coords->x2 - ((float)width / 2.0f) - (float)layer->buf_area.x1;
float y1 = (float)coords->y1 + ((float)width / 2.0f) - (float)layer->buf_area.y1;
float y2 = (float)coords->y2 - ((float)width / 2.0f) - (float)layer->buf_area.y1;
float coords_bg_w = x2 - x1 + 1;
float coords_bg_h = y2 - y1 + 1;
int32_t short_side = LV_MIN(coords_bg_w, coords_bg_h);
float radius = (float)LV_MIN(dsc->radius, short_side >> 1);
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
if(col32.alpha < 255U) {
nema_set_blend_fill(NEMA_BL_SRC_OVER);
bg_color = nema_premultiply_rgba(bg_color);
}
else {
nema_set_blend_fill(NEMA_BL_SRC);
}
if(radius > 0.0f) {
nema_draw_rounded_rect_aa(x1, y1, coords_bg_w, coords_bg_h, radius, width, bg_color);
}
else {
lv_area_t rect_coords = *coords;
lv_area_move(&rect_coords, -layer->buf_area.x1, -layer->buf_area.y1);
int32_t border_width = lv_area_get_width(&rect_coords);
int32_t border_height = lv_area_get_height(&rect_coords);
if(dsc->side & LV_BORDER_SIDE_TOP) {
float x = rect_coords.x1 + width;
float y = rect_coords.y1;
float w = border_width - 2 * width;
float h = width;
nema_enable_aa(1, 0, 1, 0);
nema_fill_rect_f(x, y, w, h, bg_color);
}
if(dsc->side & LV_BORDER_SIDE_BOTTOM) {
float x = rect_coords.x1 + width;
float y = rect_coords.y1 + border_height - width;
float w = border_width - 2 * width;
float h = width;
nema_enable_aa(1, 0, 1, 0);
nema_fill_rect_f(x, y, w, h, bg_color);
}
if(dsc->side & LV_BORDER_SIDE_LEFT) {
float x = rect_coords.x1;
float y = rect_coords.y1 + width;
float w = width;
float h = border_height - 2 * width;
nema_enable_aa(0, 1, 0, 1);
nema_fill_rect_f(x, y, w, h, bg_color);
}
if(dsc->side & LV_BORDER_SIDE_RIGHT) {
float x = rect_coords.x1 + border_width - width;
float y = rect_coords.y1 + width;
float w = width;
float h = border_height - 2 * width;
nema_enable_aa(0, 1, 0, 1);
nema_fill_rect_f(x, y, w, h, bg_color);
}
/*Draw small corner rectangles
Top Left*/
if(dsc->side & LV_BORDER_SIDE_TOP || dsc->side & LV_BORDER_SIDE_LEFT) {
float x = rect_coords.x1;
float y = rect_coords.y1;
float w = width;
float h = width;
if(!(dsc->side & LV_BORDER_SIDE_TOP))
nema_enable_aa(1, 1, 0, 1);
else if(!(dsc->side & LV_BORDER_SIDE_LEFT))
nema_enable_aa(1, 0, 1, 1);
else
nema_enable_aa(1, 0, 0, 1);
nema_fill_rect_f(x, y, w, h, bg_color);
}
/*Top Right*/
if(dsc->side & LV_BORDER_SIDE_TOP || dsc->side & LV_BORDER_SIDE_RIGHT) {
float x = rect_coords.x1 + border_width - width;
float y = rect_coords.y1;
float w = width;
float h = width;
if(!(dsc->side & LV_BORDER_SIDE_TOP))
nema_enable_aa(1, 1, 0, 1);
else if(!(dsc->side & LV_BORDER_SIDE_RIGHT))
nema_enable_aa(1, 1, 1, 0);
else
nema_enable_aa(1, 1, 0, 0);
nema_fill_rect_f(x, y, w, h, bg_color);
}
/*Bottom Right*/
if(dsc->side & LV_BORDER_SIDE_BOTTOM || dsc->side & LV_BORDER_SIDE_RIGHT) {
float x = rect_coords.x1 + border_width - width;
float y = rect_coords.y1 + border_height - width;
float w = width;
float h = width;
if(!(dsc->side & LV_BORDER_SIDE_BOTTOM))
nema_enable_aa(0, 1, 1, 1);
else if(!(dsc->side & LV_BORDER_SIDE_RIGHT))
nema_enable_aa(1, 1, 1, 0);
else
nema_enable_aa(0, 1, 1, 0);
nema_fill_rect_f(x, y, w, h, bg_color);
}
/*Bottom Left*/
if(dsc->side & LV_BORDER_SIDE_BOTTOM || dsc->side & LV_BORDER_SIDE_LEFT) {
float x = rect_coords.x1;
float y = rect_coords.y1 + border_height - width;
float w = width;
float h = width;
if(!(dsc->side & LV_BORDER_SIDE_BOTTOM))
nema_enable_aa(0, 1, 1, 1);
else if(!(dsc->side & LV_BORDER_SIDE_LEFT))
nema_enable_aa(1, 0, 1, 1);
else
nema_enable_aa(0, 0, 1, 1);
nema_fill_rect_f(x, y, w, h, bg_color);
}
}
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
#endif
@@ -0,0 +1,149 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_fill(lv_draw_task_t * t, const lv_draw_fill_dsc_t * dsc, const lv_area_t * coords)
{
if(dsc->opa <= LV_OPA_MIN) return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, coords);
lv_area_move(&rel_coords, -layer->buf_area.x1, -layer->buf_area.y1);
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, &t->clip_area);
lv_area_move(&rel_clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
nema_set_clip(rel_clip_area.x1, rel_clip_area.y1, lv_area_get_width(&rel_clip_area),
lv_area_get_height(&rel_clip_area));
lv_area_t clipped_coords;
if(!lv_area_intersect(&clipped_coords, &rel_coords, &rel_clip_area))
return; /*Fully clipped, nothing to do*/
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
/* the stride should be computed internally for NEMA_TSC images and images missing a stride value */
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
int32_t coords_bg_w = lv_area_get_width(&rel_coords);
int32_t coords_bg_h = lv_area_get_height(&rel_coords);
int32_t short_side = LV_MIN(coords_bg_w, coords_bg_h);
int32_t radius = LV_MIN(dsc->radius, short_side >> 1);
if((dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE)) {
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
if(col32.alpha < 255U) {
nema_set_blend_fill(NEMA_BL_SRC_OVER);
bg_color = nema_premultiply_rgba(bg_color);
}
else {
nema_set_blend_fill(NEMA_BL_SRC);
}
if(radius > 0.f)
nema_fill_rounded_rect_aa(rel_coords.x1, rel_coords.y1, coords_bg_w, coords_bg_h, radius, bg_color);
else
nema_fill_rect(rel_coords.x1, rel_coords.y1, coords_bg_w, coords_bg_h, bg_color);
}
#if LV_USE_NEMA_VG
else {
nema_vg_paint_clear(draw_nema_gfx_unit->paint);
nema_vg_paint_set_type(draw_nema_gfx_unit->paint, NEMA_VG_PAINT_GRAD_LINEAR);
nema_vg_set_blend(NEMA_BL_SRC_OVER | NEMA_BLOP_SRC_PREMULT);
float stops[LV_GRADIENT_MAX_STOPS];
color_var_t colors[LV_GRADIENT_MAX_STOPS];
uint32_t cnt = LV_MAX(dsc->grad.stops_count, LV_GRADIENT_MAX_STOPS);
for(uint8_t i = 0; i < cnt; i++) {
stops[i] = (float)(dsc->grad.stops[i].frac) / 255.f;
colors[i].a = LV_OPA_MIX2(dsc->grad.stops[i].opa, dsc->opa);
colors[i].r = dsc->grad.stops[i].color.red;
colors[i].g = dsc->grad.stops[i].color.green;
colors[i].b = dsc->grad.stops[i].color.blue;
}
nema_vg_grad_set(draw_nema_gfx_unit->gradient, cnt, stops, colors);
float x0, y0, x1, y1;
if(dsc->grad.dir == LV_GRAD_DIR_HOR) {
x0 = rel_coords.x1;
x1 = rel_coords.x2;
y0 = rel_coords.y1;
y1 = rel_coords.y1;
}
else {
x0 = rel_coords.x1;
x1 = rel_coords.x1;
y0 = rel_coords.y1;
y1 = rel_coords.y2;
}
nema_vg_paint_set_grad_linear(draw_nema_gfx_unit->paint, draw_nema_gfx_unit->gradient, x0, y0, x1, y1,
NEMA_TEX_CLAMP | NEMA_FILTER_BL);
if(radius > 0.f)
nema_vg_draw_rounded_rect(rel_coords.x1, rel_coords.y1, coords_bg_w, coords_bg_h, radius, radius, NULL,
draw_nema_gfx_unit->paint);
else
nema_vg_draw_rect(rel_coords.x1, rel_coords.y1, coords_bg_w, coords_bg_h, NULL, draw_nema_gfx_unit->paint);
}
#endif
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
#endif
@@ -0,0 +1,283 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* STATIC PROTOTYPES
**********************/
static void _draw_nema_gfx_tile(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords);
static void _draw_nema_gfx_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords);
static uint32_t lv_nemagfx_mask_cf_to_nema(lv_color_format_t cf);
/**********************
* STATIC FUNCTIONS
**********************/
static void _draw_nema_gfx_tile(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords)
{
lv_image_decoder_dsc_t decoder_dsc;
lv_result_t res = lv_image_decoder_open(&decoder_dsc, dsc->src, NULL);
if(res != LV_RESULT_OK) {
LV_LOG_ERROR("Failed to open image");
return;
}
int32_t img_w = dsc->header.w;
int32_t img_h = dsc->header.h;
lv_area_t tile_area;
if(lv_area_get_width(&dsc->image_area) >= 0) {
tile_area = dsc->image_area;
}
else {
tile_area = *coords;
}
lv_area_set_width(&tile_area, img_w);
lv_area_set_height(&tile_area, img_h);
int32_t tile_x_start = tile_area.x1;
while(tile_area.y1 <= t->clip_area.y2) {
while(tile_area.x1 <= t->clip_area.x2) {
lv_area_t clipped_img_area;
if(lv_area_intersect(&clipped_img_area, &tile_area, &t->clip_area)) {
_draw_nema_gfx_img(t, dsc, &tile_area);
}
tile_area.x1 += img_w;
tile_area.x2 += img_w;
}
tile_area.y1 += img_h;
tile_area.y2 += img_h;
tile_area.x1 = tile_x_start;
tile_area.x2 = tile_x_start + img_w - 1;
}
lv_image_decoder_close(&decoder_dsc);
}
static void _draw_nema_gfx_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords)
{
if(dsc->opa <= LV_OPA_MIN) return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
const lv_image_dsc_t * img_dsc = dsc->src;
bool masked = dsc->bitmap_mask_src != NULL;
lv_area_t blend_area;
/*Let's get the blend area which is the intersection of the area to fill and the clip area.*/
if(!lv_area_intersect(&blend_area, coords, &t->clip_area))
return; /*Fully clipped, nothing to do*/
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, &t->clip_area);
lv_area_move(&rel_clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
bool has_transform = (dsc->rotation != 0 || dsc->scale_x != LV_SCALE_NONE || dsc->scale_y != LV_SCALE_NONE);
bool recolor = (dsc->recolor_opa > LV_OPA_MIN);
/*Make the blend area relative to the buffer*/
lv_area_move(&blend_area, -layer->buf_area.x1, -layer->buf_area.y1);
uint32_t tex_w = lv_area_get_width(coords);
uint32_t tex_h = lv_area_get_height(coords);
nema_set_clip(rel_clip_area.x1, rel_clip_area.y1, lv_area_get_width(&rel_clip_area),
lv_area_get_height(&rel_clip_area));
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
const void * src_buf = img_dsc->data;
uint32_t blending_mode = lv_nemagfx_blending_mode(dsc->blend_mode);
lv_color_format_t src_cf = img_dsc->header.cf;
/*Image contains Alpha*/
if(src_cf == LV_COLOR_FORMAT_ARGB8888 || src_cf == LV_COLOR_FORMAT_XRGB8888) {
blending_mode |= NEMA_BLOP_SRC_PREMULT;
}
uint32_t src_nema_cf = lv_nemagfx_cf_to_nema(src_cf);
/* the stride should be computed internally for NEMA_TSC images and images missing a stride value */
int32_t src_stride = (src_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && src_cf <= LV_COLOR_FORMAT_NEMA_TSC_END)
|| img_dsc->header.stride == 0 ? -1 : (int32_t)img_dsc->header.stride;
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
if(!LV_COLOR_FORMAT_IS_INDEXED(src_cf)) {
nema_bind_src_tex((uintptr_t)(src_buf), tex_w, tex_h, src_nema_cf, src_stride,
dsc->antialias ? NEMA_FILTER_BL : NEMA_FILTER_PS);
}
else {
nema_bind_lut_tex((uintptr_t)((uint8_t *)src_buf + LV_COLOR_INDEXED_PALETTE_SIZE(src_cf) * 4), tex_w, tex_h,
src_nema_cf, src_stride, NEMA_FILTER_PS, (uintptr_t)(src_buf), NEMA_BGRA8888);
blending_mode |= NEMA_BLOP_LUT;
}
/*Guard for previous NemaGFX Version*/
#ifdef NEMA_BLOP_RECOLOR
if(recolor) {
lv_color32_t col32 = lv_color_to_32(dsc->recolor, LV_OPA_MIX2(dsc->recolor_opa, dsc->opa));
uint32_t color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
nema_set_recolor_color(color);
blending_mode |= NEMA_BLOP_RECOLOR;
}
#endif
if(dsc->opa < 255) {
uint32_t rgba = ((uint32_t)dsc->opa << 24U) | ((uint32_t)dsc->opa << 16U) | ((uint32_t)dsc->opa << 8U) | ((
uint32_t)dsc->opa);
nema_set_const_color(rgba);
blending_mode |= NEMA_BLOP_MODULATE_A;
}
if(!has_transform && masked && !recolor) {
if(dsc->bitmap_mask_src->header.cf == LV_COLOR_FORMAT_A8 || dsc->bitmap_mask_src->header.cf == LV_COLOR_FORMAT_L8) {
blending_mode |= NEMA_BLOP_STENCIL_TXTY;
const lv_image_dsc_t * mask = dsc->bitmap_mask_src;
const void * mask_buf = mask->data;
const lv_area_t * image_area;
lv_area_t mask_area;
if(lv_area_get_width(&dsc->image_area) < 0) image_area = coords;
else image_area = &dsc->image_area;
lv_area_set(&mask_area, 0, 0, dsc->bitmap_mask_src->header.w - 1, dsc->bitmap_mask_src->header.h - 1);
lv_area_align(image_area, &mask_area, LV_ALIGN_CENTER, 0, 0);
mask_buf += dsc->bitmap_mask_src->header.w * (coords->y1 - mask_area.y1) + (coords->x1 - mask_area.x1);
nema_bind_tex(NEMA_TEX3, (uintptr_t)NEMA_VIRT2PHYS(mask_buf), mask->header.w, mask->header.h,
lv_nemagfx_mask_cf_to_nema(mask->header.cf),
mask->header.stride, NEMA_FILTER_BL);
}
}
nema_set_blend_blit(blending_mode);
if(!has_transform) {
nema_blit_rect((coords->x1 - layer->buf_area.x1),
(coords->y1 - layer->buf_area.y1), tex_w, tex_h);
}
else {
/*Calculate the transformed points*/
float x0 = (coords->x1 - layer->buf_area.x1);
float y0 = (coords->y1 - layer->buf_area.y1);
float x1 = x0 + tex_w ;
float y1 = y0;
float x2 = x0 + tex_w ;
float y2 = y0 + tex_h;
float x3 = x0 ;
float y3 = y0 + tex_h;
nema_matrix3x3_t m;
nema_mat3x3_load_identity(m);
nema_mat3x3_translate(m, -x0, -y0);
nema_mat3x3_translate(m, -(float)dsc->pivot.x, -(float)dsc->pivot.y);
nema_mat3x3_rotate(m, (dsc->rotation / 10.0f)); /* angle is 1/10 degree */
float scale_x = 1.f * dsc->scale_x / LV_SCALE_NONE;
float scale_y = 1.f * dsc->scale_y / LV_SCALE_NONE;
nema_mat3x3_scale(m, (float)scale_x, (float)scale_y);
nema_mat3x3_translate(m, (float)dsc->pivot.x, (float)dsc->pivot.y);
nema_mat3x3_translate(m, x0, y0);
/*Apply Transformation Matrix to Vertices*/
nema_mat3x3_mul_vec(m, &x0, &y0);
nema_mat3x3_mul_vec(m, &x1, &y1);
nema_mat3x3_mul_vec(m, &x2, &y2);
nema_mat3x3_mul_vec(m, &x3, &y3);
nema_blit_quad_fit(x0, y0,
x1, y1,
x2, y2,
x3, y3);
}
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
/*NemaGFX does mask operations with A8,A4,A2 and A1 formats*/
static uint32_t lv_nemagfx_mask_cf_to_nema(lv_color_format_t cf)
{
switch(cf) {
case LV_COLOR_FORMAT_A1:
return NEMA_A1;
case LV_COLOR_FORMAT_A2:
return NEMA_A2;
case LV_COLOR_FORMAT_A4:
return NEMA_A4;
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_L8:
default:
break;
}
return NEMA_A8;
}
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_img(lv_draw_task_t * t, const lv_draw_image_dsc_t * dsc, const lv_area_t * coords)
{
if(!dsc->tile) {
_draw_nema_gfx_img(t, dsc, coords);
}
else {
_draw_nema_gfx_tile(t, dsc, coords);
}
}
#endif
@@ -0,0 +1,850 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
#include "../../misc/lv_utils.h"
#include "../../misc/lv_bidi_private.h"
#include "../../misc/lv_text_private.h"
#include "../../lvgl.h"
#include "../../libs/freetype/lv_freetype_private.h"
#include "../../core/lv_global.h"
/*********************
* DEFINES
*********************/
#define LABEL_RECOLOR_PAR_LENGTH 6
#define LV_LABEL_HINT_UPDATE_TH 1024 /*Update the "hint" if the label's y coordinates have changed more then this*/
#define FT_F26DOT6_SHIFT 6
#define NEMA_COORD_LIMIT 2046
#define font_draw_buf_handlers &(LV_GLOBAL_DEFAULT()->font_draw_buf_handlers)
/** After converting the font reference size, it is also necessary to scale the 26dot6 data
* in the path to the real physical size
*/
#define FT_F26DOT6_TO_PATH_SCALE(x) (LV_FREETYPE_F26DOT6_TO_FLOAT(x) / (1 << FT_F26DOT6_SHIFT))
/*Forward declarations*/
void nema_set_matrix(nema_matrix3x3_t m);
void nema_raster_rect(int x, int y, int w, int h);
/**********************
* TYPEDEFS
**********************/
enum {
RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER,
RECOLOR_CMD_STATE_PARAMETER,
RECOLOR_CMD_STATE_TEXT_INPUT,
};
typedef unsigned char cmd_state_t;
/**********************
* STATIC PROTOTYPES
**********************/
static void _draw_nema_gfx_letter(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc,
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area);
static void _draw_label_iterate_characters(lv_draw_task_t * t, const lv_draw_label_dsc_t * dsc,
const lv_area_t * coords);
static inline uint8_t _bpp_nema_gfx_format(lv_draw_glyph_dsc_t * glyph_draw_dsc);
static void _draw_letter(lv_draw_task_t * t, lv_draw_glyph_dsc_t * dsc, const lv_point_t * pos,
const lv_font_t * font, uint32_t letter);
static uint8_t hex_char_to_num(char hex);
static bool is_raw_bitmap;
#if LV_USE_FREETYPE && LV_USE_NEMA_VG
#include "lv_nema_gfx_path.h"
static void _draw_nema_gfx_outline(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc);
static void freetype_outline_event_cb(lv_event_t * e);
static void lv_nema_gfx_outline_push(const lv_freetype_outline_event_param_t * param);
static void lv_nema_outline_event_alloc(const lv_freetype_outline_event_param_t * param);
#endif
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_label_init(lv_draw_unit_t * draw_unit)
{
#if LV_USE_FREETYPE
/*Set up the freetype outline event*/
lv_freetype_outline_add_event(freetype_outline_event_cb, LV_EVENT_ALL, draw_unit);
#else
LV_UNUSED(draw_unit);
#endif /* LV_USE_FREETYPE */
}
void lv_draw_nema_gfx_label(lv_draw_task_t * t, const lv_draw_label_dsc_t * dsc, const lv_area_t * coords)
{
if(dsc->opa <= LV_OPA_MIN) return;
lv_layer_t * layer = t->target_layer;
lv_area_t clip_area;
lv_area_copy(&clip_area, &t->clip_area);
lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
_draw_label_iterate_characters(t, dsc, coords);
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
nema_cl_submit(&(draw_nema_gfx_unit->cl));
nema_cl_wait(&(draw_nema_gfx_unit->cl));
}
/**********************
* STATIC FUNCTIONS
**********************/
#if LV_USE_FREETYPE && LV_USE_NEMA_VG
static void _draw_nema_gfx_outline(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc)
{
lv_area_t blend_area;
if(!_lv_area_intersect(&blend_area, glyph_draw_dsc->letter_coords, &t->clip_area))
return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_nema_gfx_path_t * nema_gfx_path = (lv_nema_gfx_path_t *)glyph_draw_dsc->glyph_data;
lv_point_t pos = {glyph_draw_dsc->letter_coords->x1, glyph_draw_dsc->letter_coords->y1};
float scale = FT_F26DOT6_TO_PATH_SCALE(lv_freetype_outline_get_scale(glyph_draw_dsc->g->resolved_font));
/*Calculate Path Matrix*/
nema_matrix3x3_t matrix;
nema_mat3x3_load_identity(matrix);
nema_mat3x3_scale(matrix, scale, -scale);
nema_mat3x3_translate(matrix, pos.x - glyph_draw_dsc->g->ofs_x,
pos.y + glyph_draw_dsc->g->box_h + glyph_draw_dsc->g->ofs_y);
nema_vg_path_clear(nema_gfx_path->path);
nema_vg_paint_clear(nema_gfx_path->paint);
nema_vg_set_fill_rule(NEMA_VG_FILL_EVEN_ODD);
nema_vg_path_set_shape(nema_gfx_path->path, nema_gfx_path->seg_size, nema_gfx_path->seg, nema_gfx_path->data_size,
nema_gfx_path->data);
nema_vg_paint_set_type(nema_gfx_path->paint, NEMA_VG_PAINT_COLOR);
lv_color32_t dsc_col32 = lv_color_to_32(glyph_draw_dsc->color, glyph_draw_dsc->opa);
uint32_t nema_dsc_color = nema_rgba(dsc_col32.red, dsc_col32.green, dsc_col32.blue, dsc_col32.alpha);
nema_vg_paint_set_paint_color(nema_gfx_path->paint, nema_dsc_color);
nema_vg_path_set_matrix(nema_gfx_path->path, matrix);
nema_vg_draw_path(nema_gfx_path->path, nema_gfx_path->paint);
return;
}
static void freetype_outline_event_cb(lv_event_t * e)
{
LV_PROFILER_DRAW_BEGIN;
lv_event_code_t code = lv_event_get_code(e);
lv_freetype_outline_event_param_t * param = lv_event_get_param(e);
switch(code) {
case LV_EVENT_CREATE:
param->outline = lv_nema_gfx_path_create();
lv_nema_outline_event_alloc(param);
break;
case LV_EVENT_DELETE:
lv_nema_gfx_path_destroy(param->outline);
break;
case LV_EVENT_INSERT:
lv_nema_gfx_outline_push(param);
break;
default:
LV_LOG_WARN("unknown event code: %d", code);
break;
}
LV_PROFILER_DRAW_END;
}
static void lv_nema_gfx_outline_push(const lv_freetype_outline_event_param_t * param)
{
LV_PROFILER_DRAW_BEGIN;
lv_nema_gfx_path_t * outline = param->outline;
LV_ASSERT_NULL(outline);
lv_freetype_outline_type_t type = param->type;
switch(type) {
case LV_FREETYPE_OUTLINE_END:
lv_nema_gfx_path_end(outline);
break;
case LV_FREETYPE_OUTLINE_MOVE_TO:
lv_nema_gfx_path_move_to(outline, param->to.x, param->to.y);
break;
case LV_FREETYPE_OUTLINE_LINE_TO:
lv_nema_gfx_path_line_to(outline, param->to.x, param->to.y);
break;
case LV_FREETYPE_OUTLINE_CUBIC_TO:
lv_nema_gfx_path_cubic_to(outline, param->control1.x, param->control1.y,
param->control2.x, param->control2.y,
param->to.x, param->to.y);
break;
case LV_FREETYPE_OUTLINE_CONIC_TO:
lv_nema_gfx_path_quad_to(outline, param->control1.x, param->control1.y,
param->to.x, param->to.y);
break;
default:
LV_LOG_ERROR("unknown point type: %d", type);
LV_ASSERT(false);
break;
}
LV_PROFILER_DRAW_END;
}
static void lv_nema_outline_event_alloc(const lv_freetype_outline_event_param_t * param)
{
lv_nema_gfx_path_t * outline = param->outline;
outline->data_size = param->sizes.data_size;
outline->seg_size = param->sizes.segments_size;
lv_nema_gfx_path_alloc(outline);
}
#endif /* LV_USE_FREETYPE && LV_USE_NEMA_VG */
/**
* Convert a hexadecimal characters to a number (0..15)
* @param hex Pointer to a hexadecimal character (0..9, A..F)
* @return the numerical value of `hex` or 0 on error
*/
static uint8_t hex_char_to_num(char hex)
{
if(hex >= '0' && hex <= '9') return hex - '0';
if(hex >= 'a') hex -= 'a' - 'A'; /*Convert to upper case*/
return 'A' <= hex && hex <= 'F' ? hex - 'A' + 10 : 0;
}
static inline uint8_t _bpp_nema_gfx_format(lv_draw_glyph_dsc_t * glyph_draw_dsc)
{
uint32_t format = glyph_draw_dsc->g->format;
switch(format) {
case LV_FONT_GLYPH_FORMAT_A1:
return NEMA_A1;
case LV_FONT_GLYPH_FORMAT_A2:
return NEMA_A2;
case LV_FONT_GLYPH_FORMAT_A4:
return NEMA_A4;
case LV_FONT_GLYPH_FORMAT_A8:
default:
return NEMA_A8;
}
}
static void _draw_nema_gfx_letter(lv_draw_task_t * t, lv_draw_glyph_dsc_t * glyph_draw_dsc,
lv_draw_fill_dsc_t * fill_draw_dsc, const lv_area_t * fill_area)
{
if(glyph_draw_dsc) {
if(glyph_draw_dsc->format == LV_FONT_GLYPH_FORMAT_NONE) {
#if LV_USE_FONT_PLACEHOLDER
/* Draw a placeholder rectangle*/
lv_draw_border_dsc_t border_draw_dsc;
lv_draw_border_dsc_init(&border_draw_dsc);
border_draw_dsc.opa = glyph_draw_dsc->opa;
border_draw_dsc.color = glyph_draw_dsc->color;
border_draw_dsc.width = 1;
lv_draw_nema_gfx_border(t, &border_draw_dsc, glyph_draw_dsc->bg_coords);
#endif
}
else if(glyph_draw_dsc->format >= LV_FONT_GLYPH_FORMAT_A1 &&
glyph_draw_dsc->format <= LV_FONT_GLYPH_FORMAT_A8) {
/*Do not draw transparent things*/
if(glyph_draw_dsc->opa <= LV_OPA_MIN)
return;
lv_layer_t * layer = t->target_layer;
lv_area_t blend_area;
if(!lv_area_intersect(&blend_area, glyph_draw_dsc->letter_coords, &t->clip_area))
return;
const lv_draw_buf_t * draw_buf = glyph_draw_dsc->glyph_data;
const void * mask_buf;
uint32_t src_cf;
lv_area_t mask_area = *glyph_draw_dsc->letter_coords;
lv_area_t rel_coords;
lv_area_copy(&rel_coords, &blend_area);
lv_area_move(&rel_coords, -layer->buf_area.x1, -layer->buf_area.y1);
int32_t x, y, w, h;
/*Read the static font*/
if(is_raw_bitmap) {
mask_buf = glyph_draw_dsc->glyph_data;
src_cf = _bpp_nema_gfx_format(glyph_draw_dsc);
x = glyph_draw_dsc->letter_coords->x1 - layer->buf_area.x1;
y = glyph_draw_dsc->letter_coords->y1 - layer->buf_area.y1;
w = glyph_draw_dsc->g->box_w;
h = glyph_draw_dsc->g->box_h;
}
/*Read the draw buffer*/
else {
mask_buf = draw_buf->data;
src_cf = lv_nemagfx_cf_to_nema(draw_buf->header.cf);
mask_area.x2 = mask_area.x1 + lv_draw_buf_width_to_stride(lv_area_get_width(&mask_area), LV_COLOR_FORMAT_A8) - 1;
mask_buf += draw_buf->header.stride * (blend_area.y1 - mask_area.y1) + (blend_area.x1 - mask_area.x1);
x = rel_coords.x1;
y = rel_coords.y1;
w = lv_area_get_width(&rel_coords);
h = lv_area_get_height(&rel_coords);
}
if(is_raw_bitmap && (glyph_draw_dsc->format <= LV_FONT_GLYPH_FORMAT_A4)) {
nema_bind_src_tex((uintptr_t)(mask_buf), w * h, 1, src_cf, glyph_draw_dsc->g->stride, NEMA_FILTER_PS);
nema_matrix3x3_t m = {
{1, w, -x - (y * w) - (0.5 * w)},
{0, 1, 0},
{0, 0, 1}
};
nema_set_matrix(m);
nema_raster_rect(x, y, w, h);
}
else {
nema_bind_src_tex((uintptr_t)(mask_buf), lv_area_get_width(&mask_area), lv_area_get_height(&mask_area), src_cf,
glyph_draw_dsc->g->stride ? glyph_draw_dsc->g->stride : lv_area_get_width(&mask_area),
NEMA_FILTER_BL);
nema_blit_rect(x, y, w, h);
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
nema_cl_submit(&(draw_nema_gfx_unit->cl));
nema_cl_wait(&(draw_nema_gfx_unit->cl));
}
}
else if(glyph_draw_dsc->format == LV_FONT_GLYPH_FORMAT_IMAGE) {
#if LV_USE_IMGFONT
lv_draw_img_dsc_t img_dsc;
lv_draw_img_dsc_init(&img_dsc);
img_dsc.angle = 0;
img_dsc.zoom = LV_ZOOM_NONE;
img_dsc.opa = glyph_draw_dsc->opa;
img_dsc.src = glyph_draw_dsc->glyph_data;
lv_draw_nema_gfx_img(t, &img_dsc, glyph_draw_dsc->letter_coords);
#endif
}
#if LV_USE_FREETYPE && LV_USE_NEMA_VG
else if(glyph_draw_dsc->format == LV_FONT_GLYPH_FORMAT_VECTOR) {
if(lv_freetype_is_outline_font(glyph_draw_dsc->g->resolved_font)) {
_draw_nema_gfx_outline(t, glyph_draw_dsc);
}
}
#endif
}
if(fill_draw_dsc && fill_area) {
lv_draw_nema_gfx_fill(t, fill_draw_dsc, fill_area);
}
}
static inline void _set_color_blend(uint32_t color, uint8_t alpha)
{
nema_set_tex_color(color);
if(alpha < 255U) {
nema_set_blend_blit(NEMA_BL_SIMPLE | NEMA_BLOP_MODULATE_A);
nema_set_const_color(color);
}
else {
nema_set_blend_blit(NEMA_BL_SIMPLE);
}
}
static void _draw_label_iterate_characters(lv_draw_task_t * t, const lv_draw_label_dsc_t * dsc,
const lv_area_t * coords)
{
const lv_font_t * font = dsc->font;
int32_t w;
lv_area_t clipped_area;
bool clip_ok = lv_area_intersect(&clipped_area, coords, &t->clip_area);
if(!clip_ok) return;
lv_text_align_t align = dsc->align;
lv_base_dir_t base_dir = dsc->bidi_dir;
lv_bidi_calculate_align(&align, &base_dir, dsc->text);
if((dsc->flag & LV_TEXT_FLAG_EXPAND) == 0) {
/*Normally use the label's width as width*/
w = lv_area_get_width(coords);
}
else {
/*If EXPAND is enabled then not limit the text's width to the object's width*/
lv_point_t p;
lv_text_get_size(&p, dsc->text, dsc->font, dsc->letter_space, dsc->line_space, LV_COORD_MAX,
dsc->flag);
w = p.x;
}
int32_t line_height_font = lv_font_get_line_height(font);
int32_t line_height = line_height_font + dsc->line_space;
/*Init variables for the first line*/
int32_t line_width = 0;
lv_point_t pos;
lv_point_set(&pos, coords->x1, coords->y1);
int32_t x_ofs = 0;
int32_t y_ofs = 0;
x_ofs = dsc->ofs_x;
y_ofs = dsc->ofs_y;
pos.y += y_ofs;
uint32_t line_start = 0;
int32_t last_line_start = -1;
/*Check the hint to use the cached info*/
if(dsc->hint && y_ofs == 0 && coords->y1 < 0) {
/*If the label changed too much recalculate the hint.*/
if(LV_ABS(dsc->hint->coord_y - coords->y1) > LV_LABEL_HINT_UPDATE_TH - 2 * line_height) {
dsc->hint->line_start = -1;
}
last_line_start = dsc->hint->line_start;
}
/*Use the hint if it's valid*/
if(dsc->hint && last_line_start >= 0) {
line_start = last_line_start;
pos.y += dsc->hint->y;
}
uint32_t remaining_len = dsc->text_length;
uint32_t line_end = line_start + lv_text_get_next_line(&dsc->text[line_start], remaining_len, font, dsc->letter_space,
w, NULL, dsc->flag);
/*Go the first visible line*/
while(pos.y + line_height_font < t->clip_area.y1) {
/*Go to next line*/
line_start = line_end;
line_end += lv_text_get_next_line(&dsc->text[line_start], remaining_len, font, dsc->letter_space, w, NULL, dsc->flag);
pos.y += line_height;
/*Save at the threshold coordinate*/
if(dsc->hint && pos.y >= -LV_LABEL_HINT_UPDATE_TH && dsc->hint->line_start < 0) {
dsc->hint->line_start = line_start;
dsc->hint->y = pos.y - coords->y1;
dsc->hint->coord_y = coords->y1;
}
if(dsc->text[line_start] == '\0') return;
}
/*Align to middle*/
if(align == LV_TEXT_ALIGN_CENTER) {
line_width = lv_text_get_width_with_flags(&dsc->text[line_start], line_end - line_start, font, dsc->letter_space,
dsc->flag);
pos.x += (lv_area_get_width(coords) - line_width) / 2;
}
/*Align to the right*/
else if(align == LV_TEXT_ALIGN_RIGHT) {
line_width = lv_text_get_width_with_flags(&dsc->text[line_start], line_end - line_start, font, dsc->letter_space,
dsc->flag);
pos.x += lv_area_get_width(coords) - line_width;
}
uint32_t sel_start = dsc->sel_start;
uint32_t sel_end = dsc->sel_end;
if(sel_start > sel_end) {
uint32_t tmp = sel_start;
sel_start = sel_end;
sel_end = tmp;
}
lv_area_t bg_coords;
lv_draw_glyph_dsc_t draw_letter_dsc;
lv_draw_glyph_dsc_init(&draw_letter_dsc);
draw_letter_dsc.opa = dsc->opa;
draw_letter_dsc.bg_coords = &bg_coords;
draw_letter_dsc.color = dsc->color;
draw_letter_dsc.rotation = dsc->rotation;
lv_draw_fill_dsc_t fill_dsc;
lv_draw_fill_dsc_init(&fill_dsc);
fill_dsc.opa = dsc->opa;
int32_t underline_width = font->underline_thickness ? font->underline_thickness : 1;
int32_t line_start_x;
uint32_t next_char_offset;
uint32_t recolor_command_start_index = 0;
int32_t letter_w;
cmd_state_t recolor_cmd_state = RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER;
lv_color_t recolor = lv_color_black(); /* Holds the selected color inside the recolor command */
uint8_t is_first_space_after_cmd = 0;
lv_color32_t dsc_col32 = lv_color_to_32(dsc->color, dsc->opa);
uint32_t nema_dsc_color = nema_rgba(dsc_col32.red, dsc_col32.green, dsc_col32.blue, dsc_col32.alpha);
lv_color32_t dsc_sel_col32 = lv_color_to_32(dsc->sel_color, dsc->opa);
uint32_t nema_dsc_sel_color = nema_rgba(dsc_sel_col32.red, dsc_sel_col32.green, dsc_sel_col32.blue,
dsc_sel_col32.alpha);
uint32_t blend_color;
uint8_t blend_alpha = 255;
_set_color_blend(nema_dsc_color, dsc_col32.alpha);
uint8_t cur_state = 2;
uint8_t prev_state = 2;
/*Write out all lines*/
while(remaining_len && dsc->text[line_start] != '\0') {
pos.x += x_ofs;
line_start_x = pos.x;
/*Write all letter of a line*/
recolor_cmd_state = RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER;
next_char_offset = 0;
#if LV_USE_BIDI
char * bidi_txt = lv_malloc(line_end - line_start + 1);
LV_ASSERT_MALLOC(bidi_txt);
lv_bidi_process_paragraph(dsc->text + line_start, bidi_txt, line_end - line_start, base_dir, NULL, 0);
#else
const char * bidi_txt = dsc->text + line_start;
#endif
while(next_char_offset < remaining_len && next_char_offset < line_end - line_start) {
uint32_t logical_char_pos = 0;
/* Check if the text selection is enabled */
if(sel_start != LV_DRAW_LABEL_NO_TXT_SEL && sel_end != LV_DRAW_LABEL_NO_TXT_SEL) {
#if LV_USE_BIDI
logical_char_pos = lv_text_encoded_get_char_id(dsc->text, line_start);
uint32_t c_idx = lv_text_encoded_get_char_id(bidi_txt, next_char_offset);
logical_char_pos += lv_bidi_get_logical_pos(bidi_txt, NULL, line_end - line_start, base_dir, c_idx, NULL);
#else
logical_char_pos = lv_text_encoded_get_char_id(dsc->text, line_start + next_char_offset);
#endif
}
uint32_t letter;
uint32_t letter_next;
lv_text_encoded_letter_next_2(bidi_txt, &letter, &letter_next, &next_char_offset);
/* If recolor is enabled */
if((dsc->flag & LV_TEXT_FLAG_RECOLOR) != 0) {
if(letter == (uint32_t)LV_TXT_COLOR_CMD[0]) {
/* Handle the recolor command marker depending of the current recolor state */
if(recolor_cmd_state == RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER) {
recolor_command_start_index = next_char_offset;
recolor_cmd_state = RECOLOR_CMD_STATE_PARAMETER;
continue;
}
/*Other start char in parameter escaped cmd. char*/
else if(recolor_cmd_state == RECOLOR_CMD_STATE_PARAMETER) {
recolor_cmd_state = RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER;
}
/* If letter is LV_TXT_COLOR_CMD and we were in the CMD_STATE_IN then the recolor close marked has been found */
else if(recolor_cmd_state == RECOLOR_CMD_STATE_TEXT_INPUT) {
recolor_cmd_state = RECOLOR_CMD_STATE_WAIT_FOR_PARAMETER;
continue;
}
}
/* Find the first space (aka ' ') after the recolor command parameter, we need to skip rendering it */
if((recolor_cmd_state == RECOLOR_CMD_STATE_PARAMETER) && (letter == ' ') && (is_first_space_after_cmd == 0)) {
is_first_space_after_cmd = 1;
}
else {
is_first_space_after_cmd = 0;
}
/* Skip the color parameter and wait the space after it
* Once we have reach the space ' ', then we will extract the color information
* and store it into the recolor variable */
if(recolor_cmd_state == RECOLOR_CMD_STATE_PARAMETER) {
/* Not an space? Continue with the next character */
if(letter != ' ') {
continue;
}
/*Get the recolor parameter*/
if((next_char_offset - recolor_command_start_index) == LABEL_RECOLOR_PAR_LENGTH + 1) {
/* Temporary buffer to hold the recolor information */
char buf[LABEL_RECOLOR_PAR_LENGTH + 1];
lv_memcpy(buf, &bidi_txt[recolor_command_start_index], LABEL_RECOLOR_PAR_LENGTH);
buf[LABEL_RECOLOR_PAR_LENGTH] = '\0';
uint8_t r, g, b;
r = (hex_char_to_num(buf[0]) << 4) + hex_char_to_num(buf[1]);
g = (hex_char_to_num(buf[2]) << 4) + hex_char_to_num(buf[3]);
b = (hex_char_to_num(buf[4]) << 4) + hex_char_to_num(buf[5]);
recolor = lv_color_make(r, g, b);
}
else {
recolor.red = dsc->color.red;
recolor.blue = dsc->color.blue;
recolor.green = dsc->color.green;
}
/*After the parameter the text is in the command*/
recolor_cmd_state = RECOLOR_CMD_STATE_TEXT_INPUT;
}
/* Don't draw the first space after the recolor command */
if(is_first_space_after_cmd) {
continue;
}
}
/* If we're in the CMD_STATE_IN state then we need to subtract the recolor command length */
if(((dsc->flag & LV_TEXT_FLAG_RECOLOR) != 0) && (recolor_cmd_state == RECOLOR_CMD_STATE_TEXT_INPUT)) {
logical_char_pos -= (LABEL_RECOLOR_PAR_LENGTH + 1);
}
letter_w = lv_font_get_glyph_width(font, letter, letter_next);
/*Always set the bg_coordinates for placeholder drawing*/
bg_coords.x1 = pos.x;
bg_coords.y1 = pos.y;
bg_coords.x2 = pos.x + letter_w - 1;
bg_coords.y2 = pos.y + line_height - 1;
if(next_char_offset >= line_end - line_start) {
if(dsc->decor & LV_TEXT_DECOR_UNDERLINE) {
lv_area_t fill_area;
fill_area.x1 = line_start_x;
fill_area.x2 = pos.x + letter_w - 1;
fill_area.y1 = pos.y + font->line_height - font->base_line - font->underline_position;
fill_area.y2 = fill_area.y1 + underline_width - 1;
fill_dsc.color = dsc->color;
lv_draw_nema_gfx_fill(t, &fill_dsc, &fill_area);
}
if(dsc->decor & LV_TEXT_DECOR_STRIKETHROUGH) {
lv_area_t fill_area;
fill_area.x1 = line_start_x;
fill_area.x2 = pos.x + letter_w - 1;
fill_area.y1 = pos.y + (font->line_height - font->base_line) * 2 / 3 + font->underline_thickness / 2;
fill_area.y2 = fill_area.y1 + underline_width - 1;
fill_dsc.color = dsc->color;
lv_draw_nema_gfx_fill(t, &fill_dsc, &fill_area);
}
}
/* Handle text selection */
if(sel_start != LV_DRAW_LABEL_NO_TXT_SEL && sel_end != LV_DRAW_LABEL_NO_TXT_SEL
&& logical_char_pos >= sel_start && logical_char_pos < sel_end) {
draw_letter_dsc.color = dsc->sel_color;
fill_dsc.color = dsc->sel_bg_color;
lv_draw_nema_gfx_fill(t, &fill_dsc, &bg_coords);
cur_state = 0 ;
blend_alpha = dsc_sel_col32.alpha;
blend_color = nema_dsc_sel_color;
}
else if(recolor_cmd_state == RECOLOR_CMD_STATE_TEXT_INPUT) {
draw_letter_dsc.color = recolor;
cur_state = 1 ;
blend_alpha = dsc_col32.alpha;
lv_color32_t dsc_recolor_col32 = lv_color_to_32(recolor, dsc->opa);
blend_color = nema_rgba(dsc_recolor_col32.red, dsc_recolor_col32.green, dsc_recolor_col32.blue,
dsc_recolor_col32.alpha);
}
else {
draw_letter_dsc.color = dsc->color;
cur_state = 2;
blend_alpha = dsc_col32.alpha;
blend_color = nema_dsc_color;
}
if(cur_state != prev_state) {
_set_color_blend(blend_color, blend_alpha);
prev_state = cur_state;
}
_draw_letter(t, &draw_letter_dsc, &pos, font, letter);
if(letter_w > 0) {
pos.x += letter_w + dsc->letter_space;
}
}
#if LV_USE_BIDI
lv_free(bidi_txt);
bidi_txt = NULL;
#endif
/*Go to next line*/
remaining_len -= line_end - line_start;
line_start = line_end;
if(remaining_len) {
line_end += lv_text_get_next_line(&dsc->text[line_start], remaining_len, font, dsc->letter_space, w, NULL, dsc->flag);
}
pos.x = coords->x1;
/*Align to middle*/
if(align == LV_TEXT_ALIGN_CENTER) {
line_width =
lv_text_get_width_with_flags(&dsc->text[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag);
pos.x += (lv_area_get_width(coords) - line_width) / 2;
}
/*Align to the right*/
else if(align == LV_TEXT_ALIGN_RIGHT) {
line_width =
lv_text_get_width_with_flags(&dsc->text[line_start], line_end - line_start, font, dsc->letter_space, dsc->flag);
pos.x += lv_area_get_width(coords) - line_width;
}
/*Go the next line position*/
pos.y += line_height;
if(pos.y > t->clip_area.y2) break;
}
if(draw_letter_dsc._draw_buf) lv_draw_buf_destroy(draw_letter_dsc._draw_buf);
LV_ASSERT_MEM_INTEGRITY();
}
static void _draw_letter(lv_draw_task_t * t, lv_draw_glyph_dsc_t * dsc, const lv_point_t * pos,
const lv_font_t * font, uint32_t letter)
{
lv_font_glyph_dsc_t g;
if(lv_text_is_marker(letter)) /*Markers are valid letters but should not be rendered.*/
return;
LV_PROFILER_DRAW_BEGIN;
bool g_ret = lv_font_get_glyph_dsc(font, &g, letter, '\0');
if(g_ret == false) {
/*Add warning if the dsc is not found*/
LV_LOG_WARN("lv_draw_letter: glyph dsc. not found for U+%" LV_PRIX32, letter);
}
/*Don't draw anything if the character is empty. E.g. space*/
if((g.box_h == 0) || (g.box_w == 0)) {
LV_PROFILER_DRAW_END;
return;
}
lv_area_t letter_coords;
letter_coords.x1 = pos->x + g.ofs_x;
letter_coords.x2 = letter_coords.x1 + g.box_w - 1;
letter_coords.y1 = pos->y + (font->line_height - font->base_line) - g.box_h - g.ofs_y;
letter_coords.y2 = letter_coords.y1 + g.box_h - 1;
lv_area_move(&letter_coords, -dsc->pivot.x, -dsc->pivot.y);
/*If the letter is completely out of mask don't draw it*/
if(lv_area_is_out(&letter_coords, &t->clip_area, 0) &&
dsc->bg_coords &&
lv_area_is_out(dsc->bg_coords, &t->clip_area, 0)) {
LV_PROFILER_DRAW_END;
return;
}
if(g.resolved_font) {
lv_draw_buf_t * draw_buf = NULL;
if(LV_FONT_GLYPH_FORMAT_NONE < g.format && g.format < LV_FONT_GLYPH_FORMAT_IMAGE) {
/*Only check draw buf for bitmap glyph*/
draw_buf = lv_draw_buf_reshape(dsc->_draw_buf, 0, g.box_w, g.box_h, LV_STRIDE_AUTO);
if(draw_buf == NULL) {
if(dsc->_draw_buf) lv_draw_buf_destroy(dsc->_draw_buf);
uint32_t h = LV_ROUND_UP(g.box_h, 32); /*Assume a larger size to avoid many reallocations*/
draw_buf = lv_draw_buf_create_ex(font_draw_buf_handlers, g.box_w, h, LV_COLOR_FORMAT_A8, LV_STRIDE_AUTO);
LV_ASSERT_MALLOC(draw_buf);
draw_buf->header.h = g.box_h;
dsc->_draw_buf = draw_buf;
}
}
/* Performance Optimization for lv_font_fmt_txt_dsc_t fonts, always request raw bitmaps */
/*Exception for w*h >= NEMA_COORD_LIMIT due to HW limitation on data handling*/
is_raw_bitmap = false;
if(g.box_h * g.box_w <= NEMA_COORD_LIMIT) {
g.req_raw_bitmap = 1;
if(font->get_glyph_bitmap == lv_font_get_bitmap_fmt_txt) {
lv_font_fmt_txt_dsc_t * fdsc = (lv_font_fmt_txt_dsc_t *)font->dsc;
if(fdsc->bitmap_format == LV_FONT_FMT_TXT_PLAIN) {
is_raw_bitmap = true;
}
}
}
dsc->glyph_data = g.resolved_font->get_glyph_bitmap(&g, draw_buf);
dsc->format = dsc->glyph_data ? g.format : LV_FONT_GLYPH_FORMAT_NONE;
}
else {
dsc->format = LV_FONT_GLYPH_FORMAT_NONE;
}
dsc->letter_coords = &letter_coords;
dsc->g = &g;
_draw_nema_gfx_letter(t, dsc, NULL, NULL);
if(g.resolved_font && font->release_glyph) {
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
nema_cl_submit(&(draw_nema_gfx_unit->cl));
nema_cl_wait(&(draw_nema_gfx_unit->cl));
font->release_glyph(font, &g);
}
LV_PROFILER_DRAW_END;
}
#endif /*LV_USE_NEMA_GFX*/
@@ -0,0 +1,57 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_layer(lv_draw_task_t * t, const lv_draw_image_dsc_t * draw_dsc, const lv_area_t * coords)
{
lv_layer_t * layer_to_draw = (lv_layer_t *)draw_dsc->src;
/*It can happen that nothing was draw on a layer and therefore its buffer is not allocated.
*In this case just return. */
if(layer_to_draw->draw_buf == NULL) return;
lv_draw_image_dsc_t new_draw_dsc = *draw_dsc;
new_draw_dsc.src = layer_to_draw->draw_buf;
lv_draw_nema_gfx_img(t, &new_draw_dsc, coords);
}
#endif /*LV_USE_NEMA_GFX*/
@@ -0,0 +1,96 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_line(lv_draw_task_t * t, const lv_draw_line_dsc_t * dsc)
{
if(dsc->width == 0)
return;
if(dsc->opa <= (lv_opa_t)LV_OPA_MIN)
return;
if(dsc->p1.x == dsc->p2.x && dsc->p1.y == dsc->p2.y)
return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
lv_area_t clip_area;
clip_area.x1 = LV_MIN(dsc->p1.x, dsc->p2.x) - dsc->width / 2;
clip_area.x2 = LV_MAX(dsc->p1.x, dsc->p2.x) + dsc->width / 2;
clip_area.y1 = LV_MIN(dsc->p1.y, dsc->p2.y) - dsc->width / 2;
clip_area.y2 = LV_MAX(dsc->p1.y, dsc->p2.y) + dsc->width / 2;
if(!lv_area_intersect(&clip_area, &clip_area, &t->clip_area))
return; /*Fully clipped, nothing to do*/
lv_area_move(&clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
lv_point_t point1 = {dsc->p1.x - layer->buf_area.x1, dsc->p1.y - layer->buf_area.y1};
lv_point_t point2 = {dsc->p2.x - layer->buf_area.x1, dsc->p2.y - layer->buf_area.y1};
nema_set_clip(clip_area.x1, clip_area.y1, lv_area_get_width(&clip_area), lv_area_get_height(&clip_area));
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
/* the stride should be computed internally for NEMA_TSC images and images missing a stride value */
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
if(col32.alpha < 255U) {
nema_set_blend_fill(NEMA_BL_SIMPLE);
}
else {
nema_set_blend_fill(NEMA_BL_SRC);
}
nema_draw_line_aa(point1.x, point1.y, point2.x, point2.y, dsc->width, bg_color);
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
#endif
@@ -0,0 +1,254 @@
/**
* @file lv_draw_nema_gfx_hal.c
*
* Global functions that implement some HAL functionality
* which Nema will call directly.
*/
/*********************
* INCLUDES
*********************/
#include "../../lv_conf_internal.h"
#if LV_USE_NEMA_GFX
#if LV_USE_NEMA_HAL == LV_NEMA_HAL_STM32
#include "../../misc/lv_types.h"
#include "../../misc/lv_assert.h"
#include "../../stdlib/lv_string.h"
#include <nema_sys_defs.h>
#include <nema_core.h>
#include <assert.h>
#include <string.h>
#include LV_NEMA_STM32_HAL_INCLUDE
#include "tsi_malloc.h"
extern GPU2D_HandleTypeDef hgpu2d;
/*********************
* DEFINES
*********************/
#define RING_SIZE 1024 /* Ring Buffer Size in byte */
/* NemaGFX byte pool size in bytes.
* One byte per peixel for masking/stencling plus 10240 for additional allocations.
*/
#if defined(LV_NEMA_GFX_MAX_RESX) && defined(LV_NEMA_GFX_MAX_RESY)
#define NEMAGFX_MEM_POOL_SIZE ((LV_NEMA_GFX_MAX_RESX * LV_NEMA_GFX_MAX_RESY) + 10240)
#else
/* LV_USE_NEMA_VG is 0 so masking/stencling memory is not needed. */
#define NEMAGFX_MEM_POOL_SIZE 10240
#endif
/**********************
* TYPEDEFS
**********************/
/**********************
* STATIC PROTOTYPES
**********************/
#if (USE_HAL_GPU2D_REGISTER_CALLBACKS == 1)
static void GPU2D_CommandListCpltCallback(GPU2D_HandleTypeDef * hgpu2d, uint32_t CmdListID);
#endif
/**********************
* STATIC VARIABLES
**********************/
static uint8_t nemagfx_pool_mem[NEMAGFX_MEM_POOL_SIZE]; /* NemaGFX memory pool */
static nema_ringbuffer_t ring_buffer_str;
static volatile int last_cl_id = -1;
/**********************
* MACROS
**********************/
/**********************
* GLOBAL FUNCTIONS
**********************/
#if (USE_HAL_GPU2D_REGISTER_CALLBACKS == 1)
static void GPU2D_CommandListCpltCallback(GPU2D_HandleTypeDef * hgpu2d, uint32_t CmdListID)
#else
void HAL_GPU2D_CommandListCpltCallback(GPU2D_HandleTypeDef * hgpu2d, uint32_t CmdListID)
#endif
{
LV_UNUSED(hgpu2d);
last_cl_id = CmdListID;
}
int32_t nema_sys_init(void)
{
int error_code = 0;
/* Setup GPU2D Callback */
#if (USE_HAL_GPU2D_REGISTER_CALLBACKS == 1)
/* Register Command List Complete Callback */
HAL_GPU2D_RegisterCommandListCpltCallback(&hgpu2d, GPU2D_CommandListCpltCallback);
#endif
/* Initialise Mem Space */
error_code = tsi_malloc_init_pool_aligned(0, (void *)nemagfx_pool_mem, (uintptr_t)nemagfx_pool_mem,
NEMAGFX_MEM_POOL_SIZE, 1, 8);
LV_ASSERT(error_code == 0);
/* Allocate ring_buffer memory */
ring_buffer_str.bo = nema_buffer_create(RING_SIZE);
LV_ASSERT(ring_buffer_str.bo.base_virt);
/* Initialize Ring Buffer */
error_code = nema_rb_init(&ring_buffer_str, 1);
if(error_code < 0) {
return error_code;
}
/* Reset last_cl_id counter */
last_cl_id = 0;
return error_code;
}
uint32_t nema_reg_read(uint32_t reg)
{
return HAL_GPU2D_ReadRegister(&hgpu2d, reg);
}
void nema_reg_write(uint32_t reg, uint32_t value)
{
HAL_GPU2D_WriteRegister(&hgpu2d, reg, value);
}
int nema_wait_irq(void)
{
return 0;
}
int nema_wait_irq_cl(int cl_id)
{
while(last_cl_id < cl_id) {
(void)nema_wait_irq();
}
return 0;
}
int nema_wait_irq_brk(int brk_id)
{
while(nema_reg_read(GPU2D_BREAKPOINT) == 0U) {
(void)nema_wait_irq();
}
return 0;
}
void nema_host_free(void * ptr)
{
tsi_free(ptr);
}
void * nema_host_malloc(unsigned size)
{
return tsi_malloc(size);
}
nema_buffer_t nema_buffer_create(int size)
{
nema_buffer_t bo;
lv_memset(&bo, 0, sizeof(bo));
bo.base_virt = tsi_malloc(size);
bo.base_phys = (uint32_t)bo.base_virt;
bo.size = size;
LV_ASSERT_MSG(bo.base_virt != 0, "Unable to allocate memory in nema_buffer_create");
return bo;
}
nema_buffer_t nema_buffer_create_pool(int pool, int size)
{
LV_UNUSED(pool);
return nema_buffer_create(size);
}
void * nema_buffer_map(nema_buffer_t * bo)
{
return bo->base_virt;
}
void nema_buffer_unmap(nema_buffer_t * bo)
{
LV_UNUSED(bo);
}
void nema_buffer_destroy(nema_buffer_t * bo)
{
if(bo->fd == -1) {
return; /* Buffer weren't allocated! */
}
tsi_free(bo->base_virt);
bo->base_virt = (void *)0;
bo->base_phys = 0;
bo->size = 0;
bo->fd = -1; /* Buffer not allocated */
}
uintptr_t nema_buffer_phys(nema_buffer_t * bo)
{
return bo->base_phys;
}
void nema_buffer_flush(nema_buffer_t * bo)
{
LV_UNUSED(bo);
}
int nema_mutex_lock(int mutex_id)
{
int retval = 0;
LV_UNUSED(mutex_id);
return retval;
}
int nema_mutex_unlock(int mutex_id)
{
int retval = 0;
LV_UNUSED(mutex_id);
return retval;
}
void platform_disable_cache(void)
{
}
void platform_invalidate_cache(void)
{
}
/**********************
* STATIC FUNCTIONS
**********************/
#endif /* LV_USE_NEMA_HAL == LV_NEMA_HAL_STM32 */
#endif /* LV_USE_NEMA_GFX */
@@ -0,0 +1,171 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_fill.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* GLOBAL FUNCTIONS
**********************/
void lv_draw_nema_gfx_triangle(lv_draw_task_t * t, const lv_draw_triangle_dsc_t * dsc)
{
if(dsc->opa <= LV_OPA_MIN) return;
lv_draw_nema_gfx_unit_t * draw_nema_gfx_unit = (lv_draw_nema_gfx_unit_t *)t->draw_unit;
lv_layer_t * layer = t->target_layer;
lv_area_t rel_clip_area;
lv_area_copy(&rel_clip_area, &t->clip_area);
lv_area_move(&rel_clip_area, -layer->buf_area.x1, -layer->buf_area.y1);
lv_area_t coords;
coords.x1 = (int32_t)LV_MIN3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
coords.y1 = (int32_t)LV_MIN3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
coords.x2 = (int32_t)LV_MAX3(dsc->p[0].x, dsc->p[1].x, dsc->p[2].x);
coords.y2 = (int32_t)LV_MAX3(dsc->p[0].y, dsc->p[1].y, dsc->p[2].y);
lv_area_move(&coords, -layer->buf_area.x1, -layer->buf_area.y1);
lv_area_t clipped_coords;
if(!lv_area_intersect(&clipped_coords, &coords, &rel_clip_area))
return; /* Fully clipped, nothing to do */
nema_set_clip(rel_clip_area.x1, rel_clip_area.y1, lv_area_get_width(&rel_clip_area),
lv_area_get_height(&rel_clip_area));
lv_color_format_t dst_cf = layer->draw_buf->header.cf;
uint32_t dst_nema_cf = lv_nemagfx_cf_to_nema(dst_cf);
/* the stride should be computed internally for NEMA_TSC images and images missing a stride value */
int32_t stride = (dst_cf >= LV_COLOR_FORMAT_NEMA_TSC_START && dst_cf <= LV_COLOR_FORMAT_NEMA_TSC_END) ?
-1 : lv_area_get_width(&(layer->buf_area)) * lv_color_format_get_size(dst_cf);
nema_bind_dst_tex((uintptr_t)NEMA_VIRT2PHYS(layer->draw_buf->data), lv_area_get_width(&(layer->buf_area)),
lv_area_get_height(&(layer->buf_area)), dst_nema_cf, stride);
if(dsc->grad.dir == (lv_grad_dir_t)LV_GRAD_DIR_NONE) {
lv_color32_t col32 = lv_color_to_32(dsc->color, dsc->opa);
if(col32.alpha < 255U) {
nema_set_blend_fill(NEMA_BL_SIMPLE);
}
else {
nema_set_blend_fill(NEMA_BL_SRC);
}
uint32_t bg_color = nema_rgba(col32.red, col32.green, col32.blue, col32.alpha);
nema_enable_aa(1, 1, 1, 0);
nema_fill_triangle(dsc->p[0].x, dsc->p[0].y, dsc->p[1].x, dsc->p[1].y, dsc->p[2].x, dsc->p[2].y, bg_color);
}
#if LV_USE_NEMA_VG
else {
nema_vg_path_clear(draw_nema_gfx_unit->path);
nema_vg_paint_clear(draw_nema_gfx_unit->paint);
nema_vg_paint_set_type(draw_nema_gfx_unit->paint, NEMA_VG_PAINT_GRAD_LINEAR);
nema_vg_set_blend(NEMA_BL_SRC_OVER | NEMA_BLOP_SRC_PREMULT);
nema_vg_set_fill_rule(NEMA_VG_FILL_EVEN_ODD);
float stops[LV_GRADIENT_MAX_STOPS];
color_var_t colors[LV_GRADIENT_MAX_STOPS];
uint32_t cnt = LV_MAX(dsc->grad.stops_count, LV_GRADIENT_MAX_STOPS);
for(uint8_t i = 0; i < cnt; i++) {
stops[i] = (float)(dsc->grad.stops[i].frac) / 255.f;
colors[i].a = dsc->grad.stops[i].opa;
colors[i].r = dsc->grad.stops[i].color.red;
colors[i].g = dsc->grad.stops[i].color.green;
colors[i].b = dsc->grad.stops[i].color.blue;
}
nema_vg_grad_set(draw_nema_gfx_unit->gradient, cnt, stops, colors);
//Calculate Bounding Box
float min_x = LV_MIN(dsc->p[0].x, dsc->p[1].x);
min_x = LV_MIN(dsc->p[2].x, min_x);
float min_y = LV_MIN(dsc->p[0].y, dsc->p[1].y);
min_y = LV_MIN(dsc->p[2].y, min_y);
float max_x = LV_MAX(dsc->p[0].x, dsc->p[1].x);
max_x = LV_MAX(dsc->p[2].x, max_x);
float max_y = LV_MAX(dsc->p[0].y, dsc->p[1].y);
max_y = LV_MAX(dsc->p[2].y, max_y);
float x0, x1, y0, y1;
if(dsc->grad.dir == LV_GRAD_DIR_HOR) {
x0 = min_x;
x1 = max_x;
y0 = min_y;
y1 = min_y;
}
else {
x0 = min_x;
x1 = min_x;
y0 = min_y;
y1 = max_y;
}
y0 -= (float) layer->buf_area.y1;
y1 -= (float) layer->buf_area.y1;
x0 -= (float) layer->buf_area.x1;
x1 -= (float) layer->buf_area.x1;
uint8_t cmds_polygon[] = {NEMA_VG_PRIM_MOVE, NEMA_VG_PRIM_POLYGON};
float triangle_coords[] = {dsc->p[0].x - layer->buf_area.x1, dsc->p[0].y - layer->buf_area.y1,
4.0f,
dsc->p[1].x - layer->buf_area.x1, dsc->p[1].y - layer->buf_area.y1,
dsc->p[2].x - layer->buf_area.x1, dsc->p[2].y - layer->buf_area.y1
};
nema_enable_aa(0, 0, 0, 0);
nema_vg_paint_set_grad_linear(draw_nema_gfx_unit->paint, draw_nema_gfx_unit->gradient, x0, y0, x1, y1,
NEMA_TEX_CLAMP | NEMA_FILTER_BL);
nema_vg_path_set_shape(draw_nema_gfx_unit->path, 2, cmds_polygon, 7, triangle_coords);
nema_vg_draw_path(draw_nema_gfx_unit->path, draw_nema_gfx_unit->paint);
}
#endif
nema_cl_submit(&(draw_nema_gfx_unit->cl));
}
#endif
@@ -0,0 +1,143 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx_utils.c
*
*/
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
/**********************
* GLOBAL FUNCTIONS
**********************/
uint32_t lv_nemagfx_cf_to_nema(lv_color_format_t cf)
{
switch(cf) {
case LV_COLOR_FORMAT_A1:
return NEMA_A1;
case LV_COLOR_FORMAT_A2:
return NEMA_A2;
case LV_COLOR_FORMAT_A4:
return NEMA_A4;
case LV_COLOR_FORMAT_A8:
return NEMA_A8;
case LV_COLOR_FORMAT_I1:
return NEMA_L1;
case LV_COLOR_FORMAT_I2:
return NEMA_L2;
case LV_COLOR_FORMAT_I4:
return NEMA_L4;
case LV_COLOR_FORMAT_L8:
case LV_COLOR_FORMAT_I8:
return NEMA_L8;
case LV_COLOR_FORMAT_RGB565:
return NEMA_RGB565;
case LV_COLOR_FORMAT_RGB888:
return NEMA_BGR24;
case LV_COLOR_FORMAT_ARGB8888:
return NEMA_BGRA8888;
case LV_COLOR_FORMAT_XRGB8888:
return NEMA_BGRX8888;
case LV_COLOR_FORMAT_NEMA_TSC4:
return NEMA_TSC4;
case LV_COLOR_FORMAT_NEMA_TSC6:
return NEMA_TSC6;
case LV_COLOR_FORMAT_NEMA_TSC6A:
return NEMA_TSC6A;
case LV_COLOR_FORMAT_NEMA_TSC12:
return NEMA_TSC12;
case LV_COLOR_FORMAT_NEMA_TSC12A:
return NEMA_TSC12A;
/*Guard for previous NemaGFX Version*/
#ifdef NEMA_TSC6AP
case LV_COLOR_FORMAT_NEMA_TSC6AP:
return NEMA_TSC6AP;
#endif
default:
return LV_NEMA_GFX_COLOR_FORMAT;
}
}
uint32_t lv_nemagfx_blending_mode(lv_blend_mode_t lv_blend_mode)
{
uint32_t blending_mode;
switch(lv_blend_mode) {
case LV_BLEND_MODE_NORMAL:
blending_mode = NEMA_BL_SIMPLE;
break;
case LV_BLEND_MODE_ADDITIVE:
blending_mode = NEMA_BL_ADD;
break;
case LV_BLEND_MODE_MULTIPLY:
blending_mode = nema_blending_mode(NEMA_BF_DESTCOLOR, NEMA_BF_INVSRCALPHA, NEMA_BLOP_SRC_PREMULT);
break;
default:
blending_mode = NEMA_BL_SIMPLE;
break;
}
return blending_mode;
}
void lv_nemagfx_grad_set(NEMA_VG_GRAD_HANDLE gradient, lv_grad_dsc_t lv_grad, lv_opa_t opa)
{
float stops[LV_GRADIENT_MAX_STOPS];
color_var_t colors[LV_GRADIENT_MAX_STOPS];
uint32_t cnt = LV_MAX(lv_grad.stops_count, LV_GRADIENT_MAX_STOPS);
for(uint8_t i = 0; i < cnt; i++) {
stops[i] = (float)(lv_grad.stops[i].frac) / 255.f;
colors[i].a = LV_OPA_MIX2(lv_grad.stops[i].opa, opa);
colors[i].r = lv_grad.stops[i].color.red;
colors[i].g = lv_grad.stops[i].color.green;
colors[i].b = lv_grad.stops[i].color.blue;
}
nema_vg_grad_set(gradient, cnt, stops, colors);
}
bool lv_nemagfx_is_cf_supported(lv_color_format_t cf)
{
switch(cf) {
case LV_COLOR_FORMAT_ARGB8565:
case LV_COLOR_FORMAT_RGB565A8:
return false;
default:
break;
}
return true;
}
#endif /*LV_USE_NEMA_GFX*/
@@ -0,0 +1,132 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_draw_nema_gfx.h
*
*/
#ifndef LV_DRAW_NEMA_GFX_UTILS_H
#define LV_DRAW_NEMA_GFX_UTILS_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "../../lv_conf_internal.h"
#if LV_USE_NEMA_GFX
#include "../sw/lv_draw_sw.h"
#include "nema_core.h"
#include "nema_utils.h"
#include "nema_error.h"
#include "nema_provisional.h"
#include "nema_vg.h"
/*********************
* DEFINES
*********************/
#ifndef NEMA_VIRT2PHYS
#define NEMA_VIRT2PHYS
#else
uintptr_t NEMA_VIRT2PHYS(void * addr);
#endif
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#if LV_COLOR_DEPTH == 8
#define LV_NEMA_GFX_COLOR_FORMAT NEMA_L8
#define LV_NEMA_GFX_FORMAT_MULTIPLIER 1
#elif LV_COLOR_DEPTH == 16
#define LV_NEMA_GFX_COLOR_FORMAT NEMA_RGB565
#define LV_NEMA_GFX_FORMAT_MULTIPLIER 2
#elif LV_COLOR_DEPTH == 24
#define LV_NEMA_GFX_COLOR_FORMAT NEMA_BGR24
#define LV_NEMA_GFX_FORMAT_MULTIPLIER 3
#elif LV_COLOR_DEPTH == 32
#define LV_NEMA_GFX_COLOR_FORMAT NEMA_BGRA8888
#define LV_NEMA_GFX_FORMAT_MULTIPLIER 4
#else
/*Can't use GPU with other formats*/
#error Selected Color Depth Not Supported
#endif
/**********************
* GLOBAL PROTOTYPES
**********************/
/**
* Check if `lv_color_format_t` is supported.
* @param cf The LVGL color format
* @return True/false
*/
bool lv_nemagfx_is_cf_supported(lv_color_format_t cf);
/**
* Convert a `lv_color_format_t` to a Nema color format.
* @param cf The LVGL color format
* @return The Nema color format
*/
uint32_t lv_nemagfx_cf_to_nema(lv_color_format_t cf);
/**
* Get NemaGFX blending mode
*
* @param[in] lv_blend_mode The LVGL blend mode
*
* @return NemaGFX blending mode
*
*/
uint32_t lv_nemagfx_blending_mode(lv_blend_mode_t lv_blend_mode);
/**
* Get NemaGFX blending mode
*
* @param[in] gradient NemaGFX Gradient Buffer
*
* @param[in] lv_grad Gradient descriptor
*
* @param[in] opa Descriptor's opacity
*
*/
void lv_nemagfx_grad_set(NEMA_VG_GRAD_HANDLE gradient, lv_grad_dsc_t lv_grad, lv_opa_t opa);
/**********************
* MACROS
**********************/
#endif /*LV_USE_NEMA_GFX*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_DRAW_NEMA_GFX_UTILS_H*/
@@ -0,0 +1,159 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_nema_gfx_path.c
*
*/
/*********************
* INCLUDES
*********************/
#include "../../core/lv_refr.h"
#if LV_USE_NEMA_GFX
#if LV_USE_NEMA_VG
#include "lv_nema_gfx_path.h"
/**********************
* GLOBAL FUNCTIONS
**********************/
static int data_point = 0;
static int seg_point = 0;
lv_nema_gfx_path_t * lv_nema_gfx_path_create(void)
{
LV_PROFILER_DRAW_BEGIN;
lv_nema_gfx_path_t * nema_gfx_path = lv_malloc_zeroed(sizeof(lv_nema_gfx_path_t));
LV_ASSERT_MALLOC(nema_gfx_path);
nema_gfx_path->seg = NULL;
nema_gfx_path->data = NULL;
nema_gfx_path->seg_size = 0;
nema_gfx_path->data_size = 0;
data_point = 0;
seg_point = 0;
LV_PROFILER_DRAW_END;
return nema_gfx_path;
}
void lv_nema_gfx_path_alloc(lv_nema_gfx_path_t * nema_gfx_path)
{
LV_PROFILER_DRAW_BEGIN;
nema_gfx_path->path = nema_vg_path_create();
nema_gfx_path->paint = nema_vg_paint_create();
nema_gfx_path->data = (float *) lv_malloc(nema_gfx_path->data_size * sizeof(float));
LV_ASSERT_MALLOC(nema_gfx_path->data);
nema_gfx_path->seg = (uint8_t *) lv_malloc(nema_gfx_path->seg_size * sizeof(uint8_t));
LV_ASSERT_MALLOC(nema_gfx_path->seg);
LV_PROFILER_DRAW_END;
}
void lv_nema_gfx_path_destroy(lv_nema_gfx_path_t * nema_gfx_path)
{
LV_PROFILER_DRAW_BEGIN;
LV_ASSERT_NULL(nema_gfx_path);
if(nema_gfx_path->path != NULL) {
nema_vg_path_destroy(nema_gfx_path->path);
nema_gfx_path->path = NULL;
}
if(nema_gfx_path->paint != NULL) {
nema_vg_paint_destroy(nema_gfx_path->paint);
nema_gfx_path->paint = NULL;
}
if(nema_gfx_path->data != NULL) {
lv_free(nema_gfx_path->data);
nema_gfx_path->data = NULL;
}
if(nema_gfx_path->seg != NULL) {
lv_free(nema_gfx_path->seg);
nema_gfx_path->seg = NULL;
}
lv_free(nema_gfx_path);
LV_PROFILER_DRAW_END;
}
void lv_nema_gfx_path_move_to(lv_nema_gfx_path_t * path, float x, float y)
{
LV_ASSERT_NULL(path);
LV_ASSERT(path->data_size > data_point + 1);
LV_ASSERT(path->seg_size > seg_point);
path->seg[seg_point++] = NEMA_VG_PRIM_MOVE;
path->data[data_point++] = x;
path->data[data_point++] = y;
}
void lv_nema_gfx_path_line_to(lv_nema_gfx_path_t * path, float x, float y)
{
LV_ASSERT_NULL(path);
LV_ASSERT(path->data_size > data_point + 1);
LV_ASSERT(path->seg_size > seg_point);
path->seg[seg_point++] = NEMA_VG_PRIM_LINE;
path->data[data_point++] = x;
path->data[data_point++] = y;
}
void lv_nema_gfx_path_quad_to(lv_nema_gfx_path_t * path, float cx, float cy, float x, float y)
{
LV_ASSERT_NULL(path);
LV_ASSERT(path->data_size > data_point + 3);
LV_ASSERT(path->seg_size > seg_point);
path->seg[seg_point++] = NEMA_VG_PRIM_BEZIER_QUAD;
path->data[data_point++] = cx;
path->data[data_point++] = cy;
path->data[data_point++] = x;
path->data[data_point++] = y;
}
void lv_nema_gfx_path_cubic_to(lv_nema_gfx_path_t * path, float cx1, float cy1, float cx2, float cy2, float x, float y)
{
LV_ASSERT_NULL(path);
LV_ASSERT(path->data_size > data_point + 5);
LV_ASSERT(path->seg_size > seg_point);
path->seg[seg_point++] = NEMA_VG_PRIM_BEZIER_CUBIC;
path->data[data_point++] = cx1;
path->data[data_point++] = cy1;
path->data[data_point++] = cx2;
path->data[data_point++] = cy2;
path->data[data_point++] = x;
path->data[data_point++] = y;
}
void lv_nema_gfx_path_end(lv_nema_gfx_path_t * path)
{
/* Do Path end jobs....whatever*/
seg_point = 0;
data_point = 0;
}
#endif /*LV_USE_NEMA_VG*/
#endif /*LV_USE_NEMA_GFX*/
@@ -0,0 +1,97 @@
/**
* MIT License
*
* -----------------------------------------------------------------------------
* Copyright (c) 2008-24 Think Silicon Single Member PC
* -----------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next paragraph)
* shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @file lv_nema_gfx_path.h
*
*/
#ifndef LV_NEMA_GFX_PATH_H
#define LV_NEMA_GFX_PATH_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
#include "lv_draw_nema_gfx.h"
#if LV_USE_NEMA_GFX
#if LV_USE_NEMA_VG
/**********************
* TYPEDEFS
**********************/
typedef struct {
NEMA_VG_PATH_HANDLE path;
NEMA_VG_PAINT_HANDLE paint;
float * data;
uint8_t * seg;
uint32_t data_size;
uint32_t seg_size;
} lv_nema_gfx_path_t;
/**********************
* GLOBAL PROTOTYPES
**********************/
lv_nema_gfx_path_t * lv_nema_gfx_path_create(void);
void lv_nema_gfx_path_alloc(lv_nema_gfx_path_t * nema_gfx_path);
void lv_nema_gfx_path_destroy(lv_nema_gfx_path_t * nema_gfx_path);
void lv_nema_gfx_path_move_to(lv_nema_gfx_path_t * nema_gfx_path,
float x, float y);
void lv_nema_gfx_path_line_to(lv_nema_gfx_path_t * nema_gfx_path,
float x, float y);
void lv_nema_gfx_path_quad_to(lv_nema_gfx_path_t * nema_gfx_path,
float cx, float cy,
float x, float y);
void lv_nema_gfx_path_cubic_to(lv_nema_gfx_path_t * nema_gfx_path,
float cx1, float cy1,
float cx2, float cy2,
float x, float y);
void lv_nema_gfx_path_end(lv_nema_gfx_path_t * nema_gfx_path);
#endif /*LV_USE_NEMA_VG*/
#endif /*LV_USE_NEMA_GFX*/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_NEMA_GFX_PATH_H*/