From 3450faf7999210e499b894c97bfca42bfcf7257a Mon Sep 17 00:00:00 2001 From: _VIFEXTech Date: Wed, 10 Jan 2024 18:39:31 +0800 Subject: [PATCH] feat(dev): add VG-Lite simulator (#5257) Signed-off-by: pengyiqiang Co-authored-by: pengyiqiang --- scripts/code-format.cfg | 1 + src/dev/vg_lite_tvg/vg_lite.h | 1319 ++++++++++++++ src/dev/vg_lite_tvg/vg_lite_matrix.c | 147 ++ src/dev/vg_lite_tvg/vg_lite_tvg.cpp | 2409 ++++++++++++++++++++++++++ 4 files changed, 3876 insertions(+) create mode 100644 src/dev/vg_lite_tvg/vg_lite.h create mode 100644 src/dev/vg_lite_tvg/vg_lite_matrix.c create mode 100644 src/dev/vg_lite_tvg/vg_lite_tvg.cpp diff --git a/scripts/code-format.cfg b/scripts/code-format.cfg index 538694964..6ee64307f 100644 --- a/scripts/code-format.cfg +++ b/scripts/code-format.cfg @@ -30,6 +30,7 @@ --exclude=../src/lv_conf_internal.h --exclude=../src/core/lv_obj_style_gen.c --exclude=../src/core/lv_obj_style_gen.h +--exclude=../src/dev/vg_lite_tvg/vg_lite.h --exclude=../src/libs/gif/gifdec.c --exclude=../src/libs/gif/gifdec.h --exclude=../src/libs/lodepng/lodepng.c diff --git a/src/dev/vg_lite_tvg/vg_lite.h b/src/dev/vg_lite_tvg/vg_lite.h new file mode 100644 index 000000000..4f5a163cb --- /dev/null +++ b/src/dev/vg_lite_tvg/vg_lite.h @@ -0,0 +1,1319 @@ +/**************************************************************************** +* +* Copyright 2012 - 2022 Vivante Corporation, Santa Clara, California. +* All Rights Reserved. +* +* 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, sub license, 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 NON-INFRINGEMENT. +* IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS 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. +* +*****************************************************************************/ + +#ifndef _vg_lite_h_ +#define _vg_lite_h_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_MSC_VER) +#define inline __inline +#endif + +#include +#include + + +/* VGLite API Constants *******************************************************************************************************************/ + +#define VGLITE_HEADER_VERSION 7 + +#ifndef VGLITE_VERSION_3_0 +#define VGLITE_VERSION_3_0 1 + +#define VGLITE_MAKE_VERSION(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch)) +#define VGLITE_VERSION_MAJOR(version) (((uint32_t)(version) >> 16) & 0xff) +#define VGLITE_VERSION_MINOR(version) (((uint32_t)(version) >> 8) & 0xff) +#define VGLITE_VERSION_PATCH(version) ((uint32_t)(version) & 0xff) + +#define VGLITE_API_VERSION_3_0 VGLITE_MAKE_VERSION(3, 0, 0) + +#define VGLITE_RELEASE_VERSION VGLITE_MAKE_VERSION(4, 0, 20) + +#define VGL_FALSE 0 +#define VGL_TRUE 1 + +/* Path command (op code). */ +#define VLC_OP_END 0x00 +#define VLC_OP_CLOSE 0x01 +#define VLC_OP_MOVE 0x02 +#define VLC_OP_MOVE_REL 0x03 +#define VLC_OP_LINE 0x04 +#define VLC_OP_LINE_REL 0x05 +#define VLC_OP_QUAD 0x06 +#define VLC_OP_QUAD_REL 0x07 +#define VLC_OP_CUBIC 0x08 +#define VLC_OP_CUBIC_REL 0x09 +#define VLC_OP_BREAK 0x0A +#define VLC_OP_HLINE 0x0B +#define VLC_OP_HLINE_REL 0x0C +#define VLC_OP_VLINE 0x0D +#define VLC_OP_VLINE_REL 0x0E +#define VLC_OP_SQUAD 0x0F +#define VLC_OP_SQUAD_REL 0x10 +#define VLC_OP_SCUBIC 0x11 +#define VLC_OP_SCUBIC_REL 0x12 +#define VLC_OP_SCCWARC 0x13 +#define VLC_OP_SCCWARC_REL 0x14 +#define VLC_OP_SCWARC 0x15 +#define VLC_OP_SCWARC_REL 0x16 +#define VLC_OP_LCCWARC 0x17 +#define VLC_OP_LCCWARC_REL 0x18 +#define VLC_OP_LCWARC 0x19 +#define VLC_OP_LCWARC_REL 0x1A + +/* Macros for path manipulating: See path definitions. */ +#define VLM_PATH_ENABLE_UPLOAD(path) (path).uploaded.property |= 1 +#define VLM_PATH_DISABLE_UPLOAD(path) (path).uploaded.property &= (~1) +#define VLM_PATH_GET_UPLOAD_BIT(path) ((path).uploaded.property & 1) + +/* Gradient constants. */ +#define VLC_MAX_COLOR_RAMP_STOPS 256 /*! The max number of radial gradient stops. */ +#define VLC_MAX_GRADIENT_STOPS 16 /*! The max number of gradient stops. */ +#define VLC_GRADIENT_BUFFER_WIDTH 1024 /*! The internal gradient buffer width.*/ + + +/* API name defines for backward compatibility to VGLite 2.0 APIs */ +#define vg_lite_buffer_upload vg_lite_upload_buffer +#define vg_lite_path_append vg_lite_append_path +#define vg_lite_path_calc_length vg_lite_get_path_length +#define vg_lite_set_ts_buffer vg_lite_set_tess_buffer +#define vg_lite_set_draw_path_type vg_lite_set_path_type +#define vg_lite_create_mask_layer vg_lite_create_masklayer +#define vg_lite_fill_mask_layer vg_lite_fill_masklayer +#define vg_lite_blend_mask_layer vg_lite_blend_masklayer +#define vg_lite_generate_mask_layer_by_path vg_lite_render_masklayer +#define vg_lite_set_mask_layer vg_lite_set_masklayer +#define vg_lite_destroy_mask_layer vg_lite_destroy_masklayer +#define vg_lite_enable_mask vg_lite_enable_masklayer +#define vg_lite_enable_color_transformation vg_lite_enable_color_transform +#define vg_lite_set_color_transformation vg_lite_set_color_transform +#define vg_lite_set_image_global_alpha vg_lite_source_global_alpha +#define vg_lite_set_dest_global_alpha vg_lite_dest_global_alpha +#define vg_lite_clear_rad_grad vg_lite_clear_radial_grad +#define vg_lite_update_rad_grad vg_lite_update_radial_grad +#define vg_lite_get_rad_grad_matrix vg_lite_get_radial_grad_matrix +#define vg_lite_set_rad_grad vg_lite_set_radial_grad +#define vg_lite_draw_linear_gradient vg_lite_draw_linear_grad +#define vg_lite_draw_radial_gradient vg_lite_draw_radial_grad +#define vg_lite_draw_gradient vg_lite_draw_grad +#define vg_lite_mem_avail vg_lite_get_mem_size +#define vg_lite_set_update_stroke vg_lite_update_stroke + +#define vg_lite_buffer_image_mode_t vg_lite_image_mode_t +#define vg_lite_draw_path_type_t vg_lite_path_type_t +#define vg_lite_linear_gradient_ext_t vg_lite_ext_linear_gradient_t +#define vg_lite_buffer_transparency_mode_t vg_lite_transparency_t + + +/* VGLite API Types ***********************************************************************************************************************/ + +typedef int vg_lite_bool_t; +typedef unsigned char vg_lite_uint8_t; +typedef char vg_lite_int8_t; +typedef short vg_lite_int16_t; +typedef unsigned short vg_lite_uint16_t; +typedef int vg_lite_int32_t; +typedef unsigned int vg_lite_uint32_t; +typedef unsigned long long vg_lite_uint64_t; +typedef float vg_lite_float_t; +typedef double vg_lite_double_t; +typedef char vg_lite_char; +typedef char* vg_lite_string; +typedef void* vg_lite_pointer; +typedef void vg_lite_void; +typedef unsigned int vg_lite_color_t; + + +/* VGLite API Enumerations ****************************************************************************************************************/ + +#ifndef VG_LITE_ERROR +#define VG_LITE_ERROR 1 + + /* Error codes that the vg_lite functions can return. */ + typedef enum vg_lite_error + { + VG_LITE_SUCCESS = 0, /*! Success. */ + VG_LITE_INVALID_ARGUMENT, /*! An invalid argument was specified. */ + VG_LITE_OUT_OF_MEMORY, /*! Out of memory. */ + VG_LITE_NO_CONTEXT, /*! No context or an unintialized context specified. */ + VG_LITE_TIMEOUT, /*! A timeout has occurred during a wait. */ + VG_LITE_OUT_OF_RESOURCES, /*! Out of system resources. */ + VG_LITE_GENERIC_IO, /*! Cannot communicate with the kernel driver. */ + VG_LITE_NOT_SUPPORT, /*! Function call not supported. */ + VG_LITE_ALREADY_EXISTS, /*! Object already exists */ + VG_LITE_NOT_ALIGNED, /*! Data alignment error */ + VG_LITE_FLEXA_TIME_OUT, /*! VG timeout requesting for segment buffer */ + VG_LITE_FLEXA_HANDSHAKE_FAIL, /*! VG and SBI synchronizer handshake failed */ + } vg_lite_error_t; +#endif + + /* Chip features bit */ + typedef enum vg_lite_feature + { + gcFEATURE_BIT_VG_IM_INDEX_FORMAT, + gcFEATURE_BIT_VG_SCISSOR, + gcFEATURE_BIT_VG_BORDER_CULLING, + gcFEATURE_BIT_VG_RGBA2_FORMAT, + gcFEATURE_BIT_VG_QUALITY_8X, + gcFEATURE_BIT_VG_IM_FASTCLAER, + gcFEATURE_BIT_VG_RADIAL_GRADIENT, + gcFEATURE_BIT_VG_GLOBAL_ALPHA, + gcFEATURE_BIT_VG_RGBA8_ETC2_EAC, + gcFEATURE_BIT_VG_COLOR_KEY, + gcFEATURE_BIT_VG_DOUBLE_IMAGE, + gcFEATURE_BIT_VG_YUV_OUTPUT, + gcFEATURE_BIT_VG_FLEXA, + gcFEATURE_BIT_VG_24BIT, + gcFEATURE_BIT_VG_DITHER, + gcFEATURE_BIT_VG_USE_DST, + gcFEATURE_BIT_VG_PE_CLEAR, + gcFEATURE_BIT_VG_IM_INPUT, + gcFEATURE_BIT_VG_DEC_COMPRESS, + gcFEATURE_BIT_VG_LINEAR_GRADIENT_EXT, + gcFEATURE_BIT_VG_MASK, + gcFEATURE_BIT_VG_MIRROR, + gcFEATURE_BIT_VG_GAMMA, + gcFEATURE_BIT_VG_NEW_BLEND_MODE, + gcFEATURE_BIT_VG_STENCIL, + gcFEATURE_BIT_VG_SRC_PREMULTIPLIED, /*! Valid only if gcFEATURE_BIT_VG_HW_PREMULTIPLY is 0 */ + gcFEATURE_BIT_VG_HW_PREMULTIPLY, /*! HW multiplier can accept either premultiplied or not */ + gcFEATURE_BIT_VG_COLOR_TRANSFORMATION, + gcFEATURE_BIT_VG_LVGL_SUPPORT, + gcFEATURE_BIT_VG_INDEX_ENDIAN, + gcFEATURE_BIT_VG_24BIT_PLANAR, + gcFEATURE_BIT_VG_PIXEL_MATRIX, + gcFEATURE_BIT_VG_NEW_IMAGE_INDEX, + gcFEATURE_BIT_VG_PARALLEL_PATHS, + gcFEATURE_BIT_VG_STRIPE_MODE, + gcFEATURE_BIT_VG_IM_DEC_INPUT, + gcFEATURE_BIT_VG_GAUSSIAN_BLUR, + gcFEATURE_BIT_VG_RECTANGLE_TILED_OUT, + gcFEATURE_BIT_VG_TESSELLATION_TILED_OUT, + gcFEATURE_BIT_VG_IM_REPEAT_REFLECT, + gcFEATURE_BIT_VG_YUY2_INPUT, + gcFEATURE_BIT_VG_YUV_INPUT, + gcFEATURE_BIT_VG_YUV_TILED_INPUT, + gcFEATURE_BIT_VG_AYUV_INPUT, + gcFEATURE_BIT_VG_16PIXELS_ALIGN, + gcFEATURE_COUNT + } vg_lite_feature_t; + + #define gcFEATURE_BIT_VG_PE_PREMULTIPLY gcFEATURE_BIT_VG_HW_PREMULTIPLY + + /* Rendering quality enums. */ + typedef enum vg_lite_quality + { + VG_LITE_HIGH, /*! High quality 16x anti-aliasing path. */ + VG_LITE_UPPER, /*! Upper quality 8x anti-aliasing path. */ + VG_LITE_MEDIUM, /*! Medium quality 4x anti-aliasing path. */ + VG_LITE_LOW, /*! Low quality pat without any anti-aliasing. */ + } vg_lite_quality_t; + + /* Format of path coordinates. */ + typedef enum vg_lite_format + { + VG_LITE_S8, /*! Signed 8-bit coordinates. */ + VG_LITE_S16, /*! Signed 16-bit coordinates. */ + VG_LITE_S32, /*! Signed 32-bit coordinates. */ + VG_LITE_FP32, /*! 32-bit floating point coordinates. */ + } vg_lite_format_t; + + /* Format of pixel buffer. */ + typedef enum vg_lite_buffer_format + { + /* OpenVG VGImageFormat enums */ + + /* RGB{A,X} channel ordering */ + VG_sRGBX_8888 = 0, + VG_sRGBA_8888 = 1, + VG_sRGBA_8888_PRE = 2, + VG_sRGB_565 = 3, + VG_sRGBA_5551 = 4, + VG_sRGBA_4444 = 5, + VG_sL_8 = 6, + VG_lRGBX_8888 = 7, + VG_lRGBA_8888 = 8, + VG_lRGBA_8888_PRE = 9, + VG_lL_8 = 10, + VG_A_8 = 11, + VG_BW_1 = 12, + VG_A_1 = 13, + VG_A_4 = 14, + + /* {A,X}RGB channel ordering */ + VG_sXRGB_8888 = 0 | (1 << 6), + VG_sARGB_8888 = 1 | (1 << 6), + VG_sARGB_8888_PRE = 2 | (1 << 6), + VG_sARGB_1555 = 4 | (1 << 6), + VG_sARGB_4444 = 5 | (1 << 6), + VG_lXRGB_8888 = 7 | (1 << 6), + VG_lARGB_8888 = 8 | (1 << 6), + VG_lARGB_8888_PRE = 9 | (1 << 6), + + /* BGR{A,X} channel ordering */ + VG_sBGRX_8888 = 0 | (1 << 7), + VG_sBGRA_8888 = 1 | (1 << 7), + VG_sBGRA_8888_PRE = 2 | (1 << 7), + VG_sBGR_565 = 3 | (1 << 7), + VG_sBGRA_5551 = 4 | (1 << 7), + VG_sBGRA_4444 = 5 | (1 << 7), + VG_lBGRX_8888 = 7 | (1 << 7), + VG_lBGRA_8888 = 8 | (1 << 7), + VG_lBGRA_8888_PRE = 9 | (1 << 7), + + /* {A,X}BGR channel ordering */ + VG_sXBGR_8888 = 0 | (1 << 6) | (1 << 7), + VG_sABGR_8888 = 1 | (1 << 6) | (1 << 7), + VG_sABGR_8888_PRE = 2 | (1 << 6) | (1 << 7), + VG_sABGR_1555 = 4 | (1 << 6) | (1 << 7), + VG_sABGR_4444 = 5 | (1 << 6) | (1 << 7), + VG_lXBGR_8888 = 7 | (1 << 6) | (1 << 7), + VG_lABGR_8888 = 8 | (1 << 6) | (1 << 7), + VG_lABGR_8888_PRE = 9 | (1 << 6) | (1 << 7), + + /* Original VGLite API image format enums */ + + VG_LITE_RGBA8888 = 0 | (1 << 10), + VG_LITE_BGRA8888 = 1 | (1 << 10), + VG_LITE_RGBX8888 = 2 | (1 << 10), + VG_LITE_BGRX8888 = 3 | (1 << 10), + VG_LITE_RGB565 = 4 | (1 << 10), + VG_LITE_BGR565 = 5 | (1 << 10), + VG_LITE_RGBA4444 = 6 | (1 << 10), + VG_LITE_BGRA4444 = 7 | (1 << 10), + VG_LITE_BGRA5551 = 8 | (1 << 10), + VG_LITE_A4 = 9 | (1 << 10), + VG_LITE_A8 = 10 | (1 << 10), + VG_LITE_L8 = 11 | (1 << 10), + VG_LITE_YUYV = 12 | (1 << 10), + VG_LITE_YUY2 = 13 | (1 << 10), + VG_LITE_ANV12 = 14 | (1 << 10), + VG_LITE_AYUY2 = 15 | (1 << 10), + VG_LITE_NV12 = 16 | (1 << 10), + VG_LITE_YV12 = 17 | (1 << 10), + VG_LITE_YV24 = 18 | (1 << 10), + VG_LITE_YV16 = 19 | (1 << 10), + VG_LITE_NV16 = 20 | (1 << 10), + VG_LITE_YUY2_TILED = 21 | (1 << 10), + VG_LITE_NV12_TILED = 22 | (1 << 10), + VG_LITE_ANV12_TILED = 23 | (1 << 10), + VG_LITE_AYUY2_TILED = 24 | (1 << 10), + VG_LITE_RGBA2222 = 25 | (1 << 10), + VG_LITE_BGRA2222 = 26 | (1 << 10), + VG_LITE_ABGR2222 = 27 | (1 << 10), + VG_LITE_ARGB2222 = 28 | (1 << 10), + VG_LITE_ABGR4444 = 29 | (1 << 10), + VG_LITE_ARGB4444 = 30 | (1 << 10), + VG_LITE_ABGR8888 = 31 | (1 << 10), + VG_LITE_ARGB8888 = 32 | (1 << 10), + VG_LITE_ABGR1555 = 33 | (1 << 10), + VG_LITE_RGBA5551 = 34 | (1 << 10), + VG_LITE_ARGB1555 = 35 | (1 << 10), + VG_LITE_XBGR8888 = 36 | (1 << 10), + VG_LITE_XRGB8888 = 37 | (1 << 10), + VG_LITE_RGBA8888_ETC2_EAC = 38 | (1 << 10), + VG_LITE_RGB888 = 39 | (1 << 10), + VG_LITE_BGR888 = 40 | (1 << 10), + VG_LITE_ABGR8565 = 41 | (1 << 10), + VG_LITE_BGRA5658 = 42 | (1 << 10), + VG_LITE_ARGB8565 = 43 | (1 << 10), + VG_LITE_RGBA5658 = 44 | (1 << 10), + VG_LITE_ABGR8565_PLANAR = 45 | (1 << 10), + VG_LITE_BGRA5658_PLANAR = 46 | (1 << 10), + VG_LITE_ARGB8565_PLANAR = 47 | (1 << 10), + VG_LITE_RGBA5658_PLANAR = 48 | (1 << 10), + + + VG_LITE_INDEX_1 = 0 | (1 << 11), /*! Indexed format. */ + VG_LITE_INDEX_2 = 1 | (1 << 11), + VG_LITE_INDEX_4 = 2 | (1 << 11), + VG_LITE_INDEX_8 = 3 | (1 << 11), + + } vg_lite_buffer_format_t; + + /* Swizzle of packed YUV format UV channels. */ + typedef enum vg_lite_swizzle + { + VG_LITE_SWIZZLE_UV, + VG_LITE_SWIZZLE_VU, + } vg_lite_swizzle_t; + + /* The YUV<->RGB conversion rule. */ + typedef enum vg_lite_yuv2rgb + { + VG_LITE_YUV601, + VG_LITE_YUV709, + } vg_lite_yuv2rgb_t; + + /* The pixel layout in a buffer. */ + typedef enum vg_lite_buffer_layout + { + VG_LITE_LINEAR, + VG_LITE_TILED, + } vg_lite_buffer_layout_t; + + /* The image (buffer) rendering mode. Match OpenVG enum VGImageMode */ + typedef enum vg_lite_image_mode + { + /* For enum value backward compatibility */ + VG_LITE_ZERO = 0, + VG_LITE_NORMAL_IMAGE_MODE = 0x1F00, + VG_LITE_MULTIPLY_IMAGE_MODE = 0x1F01, + VG_LITE_STENCIL_MODE = 0x1F02, + VG_LITE_NONE_IMAGE_MODE = 0x1F03, + VG_LITE_RECOLOR_MODE = 0x1F04, + } vg_lite_image_mode_t; + + /* The image (buffer) transparency mode. */ + typedef enum vg_lite_transparency + { + VG_LITE_IMAGE_OPAQUE, + VG_LITE_IMAGE_TRANSPARENT + } vg_lite_transparency_t; + + /* Blending modes. Match OpenVG enum VGBlendMode. + * S and D represent source and destination color channels. + * Sa and Da represent the source and destination alpha channels. + * For the new version of 265, the Src and Dst colors are already pre_multiplied in previous step. + */ + + typedef enum vg_lite_blend + { + VG_LITE_BLEND_NONE = 0x2000, /*! S, i.e. no blending. */ + VG_LITE_BLEND_SRC_OVER = 0x2001, /*! S + (1 - Sa) * D */ + VG_LITE_BLEND_DST_OVER = 0x2002, /*! (1 - Da) * S + D */ + VG_LITE_BLEND_SRC_IN = 0x2003, /*! Da * S */ + VG_LITE_BLEND_DST_IN = 0x2004, /*! Sa * D */ + VG_LITE_BLEND_MULTIPLY = 0x2005, /*! S * (1 - Da) + D * (1 - Sa) + S * D */ + VG_LITE_BLEND_SCREEN = 0x2006, /*! S + D - S * D */ + VG_LITE_BLEND_DARKEN = 0x2007, /*! min(SrcOver, DstOver) */ + VG_LITE_BLEND_LIGHTEN = 0x2008, /*! max(SrcOver, DstOver) */ + VG_LITE_BLEND_ADDITIVE = 0x2009, /*! S + D */ + VG_LITE_BLEND_SUBTRACT = 0x200A, /*! D * (1 - S) */ + VG_LITE_BLEND_SUBTRACT_LVGL = 0x200B, /*! D - S */ + VG_LITE_BLEND_NORMAL_LVGL = 0x200C, /*! S * Sa + (1 - Sa) * D */ + VG_LITE_BLEND_ADDITIVE_LVGL = 0x200D, /*! (S + D) * Sa + D * (1 - Sa) */ + VG_LITE_BLEND_MULTIPLY_LVGL = 0x200E, /*! (S * D) * Sa + D * (1 - Sa) */ + VG_LITE_BLEND_PREMULTIPLY_SRC_OVER = 0x200F, /*! S * Sa + (1 - Sa) * D , Not the standard blend mode defined + by openvg, only support on the new version GC265. */ + } vg_lite_blend_t; + + /* Fill rules. Match OpenVG enum VGFillRule */ + typedef enum vg_lite_fill + { + VG_LITE_FILL_EVEN_ODD = 0x1900, /*! A pixel is drawn it it crosses an odd number of path pixels. */ + VG_LITE_FILL_NON_ZERO = 0x1901, /*! A pixel is drawn if it crosses at least one path pixel. */ + } vg_lite_fill_t; + + /* Global alpha modes. */ + typedef enum vg_lite_global_alpha + { + VG_LITE_NORMAL = 0, /*! Use original src/dst alpha value. */ + VG_LITE_GLOBAL, /*! Use global src/dst alpha value to replace original src/dst alpha value. */ + VG_LITE_SCALED, /*! Multiply global src/dst alpha value and original src/dst alpha value. */ + } vg_lite_global_alpha_t; + + /* Filter modes. */ + typedef enum vg_lite_filter + { + VG_LITE_FILTER_POINT = 0, /*! Fetch the nearest image pixel. */ + VG_LITE_FILTER_LINEAR = 0x1000, /*! Used for linear paint. */ + VG_LITE_FILTER_BI_LINEAR = 0x2000, /*! Use a 2x2 box around the image pixel and perform an interpolation. */ + VG_LITE_FILTER_GAUSSIAN = 0x3000, /*! Perform 3x3 gaussian blur with the convolution for image pixel. */ + } vg_lite_filter_t; + + /* Pattern padding mode. Match OpenVG enum VGTilingMode. */ + typedef enum vg_lite_pattern_mode + { + VG_LITE_PATTERN_COLOR = 0x1D00, /*! Pixel outside the bounds of sourceimage should be taken as the color */ + VG_LITE_PATTERN_PAD = 0x1D01, /*! Pixel outside the bounds of sourceimage should be taken as having the same color as the closest edge pixel */ + VG_LITE_PATTERN_REPEAT = 0x1D02, /*! Pixel outside the bounds of sourceimage should be repeated indefinitely in all directions */ + VG_LITE_PATTERN_REFLECT = 0x1D03, /*! Pixel outside the bounds of sourceimage should be reflected indefinitely in all directions */ + } vg_lite_pattern_mode_t; + + /* Radial gradient padding mode. Match OpenVG enum VGColorRampSpreadMode */ + typedef enum + { + VG_LITE_GRADIENT_SPREAD_FILL = 0, + VG_LITE_GRADIENT_SPREAD_PAD = 0x1C00, + VG_LITE_GRADIENT_SPREAD_REPEAT = 0x1C01, + VG_LITE_GRADIENT_SPREAD_REFLECT = 0x1C02, + } vg_lite_gradient_spreadmode_t; + + /* Decnano Compress mode. */ + typedef enum vg_lite_compress_mode + { + VG_LITE_DEC_DISABLE = 0, /*! disable compress */ + VG_LITE_DEC_NON_SAMPLE, /*! compress ratio is 1.6 if use ARGB8888, compress ratio is 2 if use XRGB8888 */ + VG_LITE_DEC_HSAMPLE, /*! compress ratio is 2 if use ARGB8888, compress ratio is 2.6 if use XRGB8888 */ + VG_LITE_DEC_HV_SAMPLE, /*! compress ratio is 2.6 if use ARGB8888, compress ratio is 4 if use XRGB8888 */ + } vg_lite_compress_mode_t; + + /* Draw path type. Match OpenVG enum VGPaintMode */ + typedef enum vg_lite_path_type + { + /* For enum value backward compatibility */ + VG_LITE_DRAW_ZERO = 0, + VG_LITE_DRAW_STROKE_PATH = (1<<0), + VG_LITE_DRAW_FILL_PATH = (1<<1), + VG_LITE_DRAW_FILL_STROKE_PATH = (1<<1 | 1<<0), + } vg_lite_path_type_t; + + /* End cap style. Match OpenVG enum VGCapStyle */ + typedef enum vg_lite_cap_style + { + VG_LITE_CAP_BUTT = 0x1700, + VG_LITE_CAP_ROUND = 0x1701, + VG_LITE_CAP_SQUARE = 0x1702, + } vg_lite_cap_style_t; + + /* Line join styles. Match OpenVG enum VGJoinStyle */ + typedef enum vg_lite_join_style + { + VG_LITE_JOIN_MITER = 0x1800, + VG_LITE_JOIN_ROUND = 0x1801, + VG_LITE_JOIN_BEVEL = 0x1802, + } vg_lite_join_style_t; + + /* Mask operation mode. Match OpenVG enum VGMaskOperation */ + typedef enum vg_lite_mask_operation + { + VG_LITE_CLEAR_MASK = 0x1500, /*! Set all dest mask values to 0 */ + VG_LITE_FILL_MASK = 0x1501, /*! Set all dest mask values to 1 */ + VG_LITE_SET_MASK = 0x1502, /*! Copy from src masklayer to dest masklayer. */ + VG_LITE_UNION_MASK = 0x1503, /*! Replace dest masklayer by its union with src masklayer. */ + VG_LITE_INTERSECT_MASK = 0x1504, /*! Replace dest masklayer by its intersection with src masklayer. */ + VG_LITE_SUBTRACT_MASK = 0x1505, /*! Subtract src mask in dest masklayer */ + } vg_lite_mask_operation_t; + + /* Mirror orientation mode. */ + typedef enum vg_lite_orientation + { + VG_LITE_ORIENTATION_TOP_BOTTOM, + VG_LITE_ORIENTATION_BOTTOM_TOP, + } vg_lite_orientation_t; + + /* Gamma conversion mode. */ + typedef enum vg_lite_gamma_conversion + { + VG_LITE_GAMMA_NO_CONVERSION, /*! Leave color as is. */ + VG_LITE_GAMMA_LINEAR, /*! Convert from sRGB to linear space. */ + VG_LITE_GAMMA_NON_LINEAR /*! Convert from linear to sRGB space. */ + } vg_lite_gamma_conversion_t; + + /* Index endian */ + typedef enum vg_lite_index_endian + { + VG_LITE_INDEX_LITTLE_ENDIAN, /*! Parse the index pixel from low to high, + *! when using index1, the parsing order is bit0~bit7. + *! when using index2, the parsing order is bit0:1,bit2:3,bit4:5.bit6:7. + *! when using index4, the parsing order is bit0:3,bit4:7. + */ + VG_LITE_INDEX_BIG_ENDIAN, /*! Parse the index pixel from low to high, + *! when using index1, the parsing order is bit7~bit0. + *! when using index2, the parsing order is bit7:6,bit5:4,bit3:2.bit1:0. + *! when using index4, the parsing order is bit4:7,bit0:3. + */ + } vg_lite_index_endian_t; + + /* Map flag*/ + typedef enum vg_lite_map_flag + { + VG_LITE_MAP_USER_MEMORY = 0, + VG_LITE_MAP_DMABUF = 0x01, + } vg_lite_map_flag_t; + +/* VGLite API Structures ******************************************************************************************************************/ + + /* VGLite driver information */ + typedef struct vg_lite_info { + vg_lite_uint32_t api_version; + vg_lite_uint32_t header_version; + vg_lite_uint32_t release_version; + vg_lite_uint32_t reserved; + } vg_lite_info_t; + + /* A 2D Point definition. */ + typedef struct vg_lite_point { + vg_lite_int32_t x; + vg_lite_int32_t y; + } vg_lite_point_t; + + /* Four 2D Point that form a polygon */ + typedef vg_lite_point_t vg_lite_point4_t[4]; + + /* A rectangle.*/ + typedef struct vg_lite_rectangle { + vg_lite_int32_t x; /*! Left coordinate of rectangle. */ + vg_lite_int32_t y; /*! Top coordinate of rectangle. */ + vg_lite_int32_t width; /*! Width of rectangle. */ + vg_lite_int32_t height; /*! Height of rectangle. */ + } vg_lite_rectangle_t; + + typedef struct vg_lite_matrix { + vg_lite_float_t m[3][3]; /*! The 3x3 matrix is in [row][column] order. */ + } vg_lite_matrix_t; + + typedef struct vg_lite_yuvinfo + { + vg_lite_swizzle_t swizzle; /*! UV swizzle. */ + vg_lite_yuv2rgb_t yuv2rgb; /*! 601 or 709 conversion standard. */ + vg_lite_uint32_t uv_planar; /*! UV(U) planar address. */ + vg_lite_uint32_t v_planar; /*! V planar address. */ + vg_lite_uint32_t alpha_planar; /*! Alpha planar address. */ + vg_lite_uint32_t uv_stride; /*! UV(U) stride. */ + vg_lite_uint32_t v_stride; /*! V stride. */ + vg_lite_uint32_t alpha_stride; /*! Alpha stride. */ + vg_lite_uint32_t uv_height; /*! UV(U) height. */ + vg_lite_uint32_t v_height; /*! V height. */ + vg_lite_pointer uv_memory; /*! The logical pointer to the UV(U) planar memory. */ + vg_lite_pointer v_memory; /*! The logical pointer to the V planar memory. */ + vg_lite_pointer uv_handle; /*! The memory handle of the UV(U) planar. */ + vg_lite_pointer v_handle; /*! The memory handle of the V planar. */ + } vg_lite_yuvinfo_t; + + typedef struct vg_lite_path_point* vg_lite_path_point_ptr; + typedef struct vg_lite_path_point + { + /* X coordinate. */ + vg_lite_float_t x; + + /* Y coordinate. */ + vg_lite_float_t y; + + /* Flatten flag for flattened path. */ + vg_lite_uint8_t flatten_flag; + + /* Curve type for stroke path. */ + vg_lite_uint8_t curve_type; + + /* X tangent. */ + vg_lite_float_t tangentX; + + /* Y tangent. */ + vg_lite_float_t tangentY; + + /* Length of the line. */ + vg_lite_float_t length; + + /* Pointer to next point node. */ + vg_lite_path_point_ptr next; + + /* Pointer to previous point node. */ + vg_lite_path_point_ptr prev; + + } vg_lite_path_point_t; + + typedef struct vg_lite_sub_path* vg_lite_sub_path_ptr; + typedef struct vg_lite_sub_path + { + /* Pointer to next sub path. */ + vg_lite_sub_path_ptr next; + + /* Number of points. */ + vg_lite_uint32_t point_count; + + /* Point list. */ + vg_lite_path_point_ptr point_list; + + /* Last point. */ + vg_lite_path_point_ptr end_point; + + /* Whether is path is closed. */ + vg_lite_uint8_t closed; + + /* Sub path length. */ + vg_lite_float_t length; + + } vg_lite_sub_path_t; + + /* Save divided path data according to MOVE/MOVE_REL. */ + typedef struct vg_lite_path_list* vg_lite_path_list_ptr; + typedef struct vg_lite_path_list + { + vg_lite_path_point_ptr path_points; + vg_lite_path_point_ptr path_end; + vg_lite_uint32_t point_count; + vg_lite_path_list_ptr next; + vg_lite_uint8_t closed; + + } vg_lite_path_list_t; + + typedef struct vg_lite_stroke + { + /* Stroke parameters */ + vg_lite_cap_style_t cap_style; + vg_lite_join_style_t join_style; + vg_lite_float_t line_width; + vg_lite_float_t miter_limit; + vg_lite_float_t *dash_pattern; + vg_lite_uint32_t pattern_count; + vg_lite_float_t dash_phase; + vg_lite_float_t dash_length; + vg_lite_uint32_t dash_index; + + vg_lite_float_t half_width; + + /* Total length of stroke dash patterns. */ + vg_lite_float_t pattern_length; + + /* For fast checking. */ + vg_lite_float_t miter_square; + + /* Temp storage of stroke subPath. */ + vg_lite_path_point_ptr path_points; + vg_lite_path_point_ptr path_end; + vg_lite_uint32_t point_count; + vg_lite_path_point_ptr left_point; + vg_lite_path_point_ptr right_point; + vg_lite_path_point_ptr stroke_points; + vg_lite_path_point_ptr stroke_end; + vg_lite_uint32_t stroke_count; + + /* Divide stroke path according to move or move_rel for avoiding implicit closure. */ + vg_lite_path_list_ptr path_list_divide; + + /* pointer to current divided path data. */ + vg_lite_path_list_ptr cur_list; + + /* Flag that add end_path in driver. */ + vg_lite_uint8_t add_end; + + /* Sub path list. */ + vg_lite_sub_path_ptr stroke_paths; + + /* Last sub path. */ + vg_lite_sub_path_ptr last_stroke; + + /* Swing area handling. */ + vg_lite_uint8_t need_swing; + vg_lite_uint32_t swing_handling; + vg_lite_uint8_t swing_ccw; + vg_lite_float_t swing_deltax; + vg_lite_float_t swing_deltay; + vg_lite_path_point_ptr swing_start; + vg_lite_path_point_ptr swing_stroke; + vg_lite_float_t swing_length; + vg_lite_float_t swing_centlen; + vg_lite_uint32_t swing_count; + + vg_lite_float_t stroke_length; + vg_lite_uint32_t stroke_size; + + /* The stroke line is fat line. */ + vg_lite_uint8_t fattened; + vg_lite_uint8_t closed; + + } vg_lite_stroke_t; + + /* Fast clear buffer. */ + typedef struct vg_lite_fc_buffer + { + vg_lite_int32_t width; /*! Width of the buffer in pixels. */ + vg_lite_int32_t height; /*! height of the buffer in pixels. */ + vg_lite_int32_t stride; /*! The number of bytes to move from one line in the buffer to the next line. */ + vg_lite_pointer handle; /*! The memory handle of the buffer's memory as allocated by the VGLite kernel. */ + vg_lite_pointer memory; /*! The logical pointer to the buffer's memory for the CPU. */ + vg_lite_uint32_t address; /*! The address to the buffer's memory for the hardware. */ + vg_lite_uint32_t color; /*! The fastclear color value. */ + } vg_lite_fc_buffer_t; + + /* Structure for any image or render target. */ + typedef struct vg_lite_buffer + { + vg_lite_int32_t width; /*! Width of the buffer in pixels. */ + vg_lite_int32_t height; /*! Height of the buffer in pixels. */ + vg_lite_int32_t stride; /*! The number of bytes to move from one line in the buffer to the next line. */ + vg_lite_buffer_layout_t tiled; /*! Indicating the buffer memory layout is linear or tiled. */ + vg_lite_buffer_format_t format; /*! The pixel format of the buffer. */ + vg_lite_pointer handle; /*! The memory handle of the buffer's memory as allocated by the VGLite kernel. */ + vg_lite_pointer memory; /*! The logical pointer to the buffer's memory for the CPU. */ + vg_lite_uint32_t address; /*! The address to the buffer's memory for the hardware. */ + vg_lite_yuvinfo_t yuv; /*! The yuv format details. */ + vg_lite_image_mode_t image_mode; /*! The blit image mode. */ + vg_lite_transparency_t transparency_mode; /*! image transparency mode. */ + vg_lite_int8_t fc_enable; /*! enable im fastclear. */ + vg_lite_fc_buffer_t fc_buffer[3]; /*! 3 fastclear buffers,reserved YUV format. */ + vg_lite_compress_mode_t compress_mode; /*! Refer to the definition by vg_lite_compress_mode_t. */ + vg_lite_index_endian_t index_endian; /*! Refer to the definition by vg_lite_index_endian_t. */ + } vg_lite_buffer_t; + + /* Memory allocation info by kernel. */ + typedef struct vg_lite_hw_memory + { + vg_lite_pointer handle; /*! gpu memory object handle. */ + vg_lite_pointer memory; /*! logical memory address. */ + vg_lite_uint32_t address; /*! GPU memory address. */ + vg_lite_uint32_t bytes; /*! Size of memory. */ + vg_lite_uint32_t property; /*! Currently bit0 is used for path upload state: + *! 1 : enable auto path data uploading. + *! 0 : disable path data uploading. path data is embedded in command buffer. */ + } vg_lite_hw_memory_t; + + /* Path info for drawing command. */ + typedef struct vg_lite_path + { + vg_lite_float_t bounding_box[4]; /*! Bounding box specified as left, top, right, and bottom. */ + vg_lite_quality_t quality; /*! Quality hint for the path. */ + vg_lite_format_t format; /*! Coordinate format. */ + vg_lite_hw_memory_t uploaded; /*! Path data that has been upload into GPU addressable memory. */ + vg_lite_uint32_t path_length; /*! Number of bytes in the path data. */ + vg_lite_pointer path; /*! Pointer to the physical description of the path. */ + vg_lite_int8_t path_changed; /*! Indicate whether path data is synced with command buffer (uploaded) or not. */ + vg_lite_int8_t pdata_internal; /*! Indicate whether path data memory is allocated by driver. */ + vg_lite_path_type_t path_type; /*! Refer to the definition by vg_lite_path_type_t. */ + vg_lite_stroke_t *stroke; /*! Pointer to a vg_lite_stroke_t structure.*/ + vg_lite_pointer stroke_path; /*! Pointer to the physical description of the stroke path. */ + vg_lite_uint32_t stroke_size; /*! Number of bytes in the stroke path data. */ + vg_lite_color_t stroke_color; /*! The stroke path fill color. */ + vg_lite_int8_t add_end; /*! Flag that add end_path in driver. */ + } vg_lite_path_t; + + /* Color ramp definition. */ + typedef struct vg_lite_color_ramp + { + vg_lite_float_t stop; /*! Value for the color stop. */ + vg_lite_float_t red; /*! Red color channel value for the color stop. */ + vg_lite_float_t green; /*! Green color channel value for the color stop. */ + vg_lite_float_t blue; /*! Blue color channel value for the color stop. */ + vg_lite_float_t alpha; /*! Alpha color channel value for the color stop. */ + } vg_lite_color_ramp_t; + + /* Linear gradient parameter */ + typedef struct vg_lite_linear_gradient_parameter + { + vg_lite_float_t X0; + vg_lite_float_t Y0; + vg_lite_float_t X1; + vg_lite_float_t Y1; + } vg_lite_linear_gradient_parameter_t; + + typedef struct vg_lite_radial_gradient_parameter + { + vg_lite_float_t cx; /*! x coordinate of the center point. */ + vg_lite_float_t cy; /*! y coordinate of the center point. */ + vg_lite_float_t r; /*! radius. */ + vg_lite_float_t fx; /*! x coordinate of the focal point. */ + vg_lite_float_t fy; /*! y coordinate of the focal point. */ + } vg_lite_radial_gradient_parameter_t; + + /* Linear gradient definition. */ + typedef struct vg_lite_linear_gradient { + vg_lite_uint32_t colors[VLC_MAX_GRADIENT_STOPS]; /*! Colors for stops. */ + vg_lite_uint32_t count; /*! Count of colors, up to 16. */ + vg_lite_uint32_t stops[VLC_MAX_GRADIENT_STOPS]; /*! Color stops, value from 0 to 255. */ + vg_lite_matrix_t matrix; /*! The matrix to transform the gradient. */ + vg_lite_buffer_t image; /*! The image for rendering as gradient pattern. */ + } vg_lite_linear_gradient_t; + + /* Extended linear gradient definition. */ + typedef struct vg_lite_ext_linear_gradient { + vg_lite_uint32_t count; /*! Count of colors, up to 256. */ + vg_lite_matrix_t matrix; /*! The matrix to transform the gradient. */ + vg_lite_buffer_t image; /*! The image for rendering as gradient pattern. */ + vg_lite_linear_gradient_parameter_t linear_grad; /*! Include center point,focal point and radius.*/ + + vg_lite_uint32_t ramp_length; /*! Color ramp for gradient paints provided to driver. */ + vg_lite_color_ramp_t color_ramp[VLC_MAX_COLOR_RAMP_STOPS]; + + vg_lite_uint32_t converted_length; /*! Converted internal color ramp. */ + vg_lite_color_ramp_t converted_ramp[VLC_MAX_COLOR_RAMP_STOPS + 2]; + + vg_lite_uint8_t pre_multiplied; /*! If color values of color_ramp[] are multiply by alpha value of color_ramp[]. */ + vg_lite_gradient_spreadmode_t spread_mode; /*! The spread mode that applied to the pixels out of the image after transformed. */ + } vg_lite_ext_linear_gradient_t; + + /* Radial gradient definition. */ + typedef struct vg_lite_radial_gradient + { + vg_lite_uint32_t count; /*! Count of colors, up to 256. */ + vg_lite_matrix_t matrix; /*! The matrix to transform the gradient. */ + vg_lite_buffer_t image; /*! The image for rendering as gradient pattern. */ + vg_lite_radial_gradient_parameter_t radial_grad; /*! Include center point,focal point and radius.*/ + + vg_lite_uint32_t ramp_length; /*! Color ramp for gradient paints provided to the driver. */ + vg_lite_color_ramp_t color_ramp[VLC_MAX_COLOR_RAMP_STOPS]; + + vg_lite_uint32_t converted_length; /*! Converted internal color ramp. */ + vg_lite_color_ramp_t converted_ramp[VLC_MAX_COLOR_RAMP_STOPS + 2]; + + vg_lite_uint8_t pre_multiplied; /*! If color values of color_ramp[] are multiply by alpha value of color_ramp[]. */ + vg_lite_gradient_spreadmode_t spread_mode; /*! The spread mode that applied to the pixels out of the image after transformed. */ + } vg_lite_radial_gradient_t; + + /* Colorkey definition */ + typedef struct vg_lite_color_key + { + vg_lite_uint8_t enable; /*! The color key is effective only when "enable" is ture, */ + vg_lite_uint8_t low_r; /*! The R chanel of low_rgb. */ + vg_lite_uint8_t low_g; /*! The G chanel of low_rgb. */ + vg_lite_uint8_t low_b; /*! The B chanel of low_rgb. */ + vg_lite_uint8_t alpha; /*! The alpha channel to replace destination pixel alpha channel.*/ + vg_lite_uint8_t hign_r; /*! The R chanel of hign_rgb. */ + vg_lite_uint8_t hign_g; /*! The G chanel of hign_rgb. */ + vg_lite_uint8_t hign_b; /*! The B chanel of hign_rgb. */ + } vg_lite_color_key_t; + + /* Four colorkey definition. + * rgb_hi_0, rgb_lo_0, alpha_0, enable_0; + * rgb_hi_1, rgb_lo_1, alpha_1, enable_1; + * rgb_hi_2, rgb_lo_2, alpha_2, enable_2; + * rgb_hi_3, rgb_lo_3, alpha_3, enable_3; + * Priority order: color_key_0 > color_key_1 > color_key_2 > color_key_3. + */ + typedef vg_lite_color_key_t vg_lite_color_key4_t[4]; + + /* Pixel matrix values */ + typedef vg_lite_float_t vg_lite_pixel_matrix_t[20]; + + /* HW pixel channel enable flags */ + typedef struct vg_lite_pixel_channel_enable + { + vg_lite_uint8_t enable_a; /*! Enable A channel.*/ + vg_lite_uint8_t enable_b; /*! Enable B channel. */ + vg_lite_uint8_t enable_g; /*! Enable G channel. */ + vg_lite_uint8_t enable_r; /*! Enable R channel. */ + } vg_lite_pixel_channel_enable_t; + + /* Pixel color transform */ + typedef struct vg_lite_color_transform + { + vg_lite_float_t a_scale; + vg_lite_float_t a_bias; + vg_lite_float_t r_scale; + vg_lite_float_t r_bias; + vg_lite_float_t g_scale; + vg_lite_float_t g_bias; + vg_lite_float_t b_scale; + vg_lite_float_t b_bias; + } vg_lite_color_transform_t; + +/* VGLite API Functions *******************************************************************************************************************/ + + /* Initialize a vglite context. */ + vg_lite_error_t vg_lite_init(vg_lite_int32_t tess_width, vg_lite_int32_t tess_height); + + /* Destroy a vglite context. */ + vg_lite_error_t vg_lite_close(void); + + /* Get the VGLite driver information. */ + vg_lite_error_t vg_lite_get_info(vg_lite_info_t* info); + + /* Get the GPU chip information. */ + vg_lite_uint32_t vg_lite_get_product_info(vg_lite_char *name, vg_lite_uint32_t *chip_id, vg_lite_uint32_t *chip_rev); + + /* Query if a specific feature is supported. */ + vg_lite_uint32_t vg_lite_query_feature(vg_lite_feature_t feature); + + /* Flush command buffer and wait for GPU to complete. */ + vg_lite_error_t vg_lite_finish(void); + + /* Flush the command buffer without waiting for GPU to complete. */ + vg_lite_error_t vg_lite_flush(void); + + /* Get the value of register from register's address. */ + vg_lite_error_t vg_lite_get_register(vg_lite_uint32_t address, vg_lite_uint32_t* result); + + /* Generate a 3x3 homogenous matrix to transform 4 source coordinates to 4 target coordinates. */ + vg_lite_error_t vg_lite_get_transform_matrix(vg_lite_point4_t src, vg_lite_point4_t dst, vg_lite_matrix_t *mat); + + /* Allocate a buffer from GPU hardware accessible memory. */ + vg_lite_error_t vg_lite_allocate(vg_lite_buffer_t *buffer); + + /* Free a buffer allocated by vg_lite_allocate() */ + vg_lite_error_t vg_lite_free(vg_lite_buffer_t *buffer); + + /* Upload RGB or YUV pixel data to an allocated buffer. */ + vg_lite_error_t vg_lite_upload_buffer(vg_lite_buffer_t *buffer, vg_lite_uint8_t *data[3], vg_lite_uint32_t stride[3]); + + /* Map a buffer into hardware accessible address space. */ + vg_lite_error_t vg_lite_map(vg_lite_buffer_t *buffer, vg_lite_map_flag_t flag, int32_t fd); + + /* Unmap a buffer that is mapped */ + vg_lite_error_t vg_lite_unmap(vg_lite_buffer_t *buffer); + + /* flush cache */ + vg_lite_error_t vg_lite_flush_mapped_buffer(vg_lite_buffer_t * buffer); + + /* Fill a buffer rectangle area with a specified color. */ + vg_lite_error_t vg_lite_clear(vg_lite_buffer_t *target, vg_lite_rectangle_t *rect, vg_lite_color_t color); + + /* Copy a source image to target buffer with transformation, blending, color mixing, and filtering. */ + vg_lite_error_t vg_lite_blit(vg_lite_buffer_t *target, + vg_lite_buffer_t *source, + vg_lite_matrix_t *matrix, + vg_lite_blend_t blend, + vg_lite_color_t color, + vg_lite_filter_t filter); + + /* Copy a rectangle area of source image to target buffer with transformation, blending, color mixing, and filtering. */ + vg_lite_error_t vg_lite_blit_rect(vg_lite_buffer_t *target, + vg_lite_buffer_t *source, + vg_lite_rectangle_t *rect, + vg_lite_matrix_t *matrix, + vg_lite_blend_t blend, + vg_lite_color_t color, + vg_lite_filter_t filter); + + /* Copy two source images to the target buffer with transformation, blending, and filtering. */ + vg_lite_error_t vg_lite_blit2(vg_lite_buffer_t *target, + vg_lite_buffer_t *source0, + vg_lite_buffer_t *source1, + vg_lite_matrix_t *matrix0, + vg_lite_matrix_t *matrix1, + vg_lite_blend_t blend, + vg_lite_filter_t filter); + + /* Draw a path to a target buffer with transformation, color, and blending */ + vg_lite_error_t vg_lite_draw(vg_lite_buffer_t *target, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t *matrix, + vg_lite_blend_t blend, + vg_lite_color_t color); + + /* Set stroke path attributes. */ + vg_lite_error_t vg_lite_set_stroke(vg_lite_path_t *path, + vg_lite_cap_style_t cap_style, + vg_lite_join_style_t join_style, + vg_lite_float_t line_width, + vg_lite_float_t miter_limit, + vg_lite_float_t *dash_pattern, + vg_lite_uint32_t pattern_count, + vg_lite_float_t dash_phase, + vg_lite_color_t color); + + /* Update stroke path. */ + vg_lite_error_t vg_lite_update_stroke(vg_lite_path_t *path); + + /* Set path type. */ + vg_lite_error_t vg_lite_set_path_type(vg_lite_path_t *path, vg_lite_path_type_t path_type); + + /* Clears all attributes of a path. */ + vg_lite_error_t vg_lite_clear_path(vg_lite_path_t *path); + + /* Upload a path to GPU memory so GPU can access it directly. */ + vg_lite_error_t vg_lite_upload_path(vg_lite_path_t *path); + + /* Initialize a path object with attributes. */ + vg_lite_error_t vg_lite_init_path(vg_lite_path_t *path, + vg_lite_format_t format, + vg_lite_quality_t quality, + vg_lite_uint32_t length, + vg_lite_pointer data, + vg_lite_float_t min_x, + vg_lite_float_t min_y, + vg_lite_float_t max_x, + vg_lite_float_t max_y); + + /* Initializes a arc path with attributes. */ + vg_lite_error_t vg_lite_init_arc_path(vg_lite_path_t *path, + vg_lite_format_t format, + vg_lite_quality_t quality, + vg_lite_uint32_t length, + vg_lite_pointer data, + vg_lite_float_t min_x, + vg_lite_float_t min_y, + vg_lite_float_t max_x, + vg_lite_float_t max_y); + + /* Return the size (in bytes) of command buffer for a path opcode array. */ + vg_lite_uint32_t vg_lite_get_path_length(vg_lite_uint8_t *opcode, + vg_lite_uint32_t count, + vg_lite_format_t format); + + /* Generate command buffer for the (path) based on input opcodes (opcode) and coordinates (data). */ + vg_lite_error_t vg_lite_append_path(vg_lite_path_t *path, + vg_lite_uint8_t *opcode, + vg_lite_pointer data, + vg_lite_uint32_t seg_count); + + /* Set CLUT (Color Look Up Table) for index image. The (colors) is in ARGB format. */ + vg_lite_error_t vg_lite_set_CLUT(vg_lite_uint32_t count, vg_lite_uint32_t *colors); + + /* Draw a path that is filled by a transformed image pattern. */ + vg_lite_error_t vg_lite_draw_pattern(vg_lite_buffer_t *target, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t *path_matrix, + vg_lite_buffer_t *pattern_image, + vg_lite_matrix_t *pattern_matrix, + vg_lite_blend_t blend, + vg_lite_pattern_mode_t pattern_mode, + vg_lite_color_t pattern_color, + vg_lite_color_t color, + vg_lite_filter_t filter); + + /* Initialize a linear gradient object with default attributes. */ + vg_lite_error_t vg_lite_init_grad(vg_lite_linear_gradient_t *grad); + + /* Reset a linear gradient object attributes. */ + vg_lite_error_t vg_lite_clear_grad(vg_lite_linear_gradient_t *grad); + + /* Update a linear gradient object. */ + vg_lite_error_t vg_lite_update_grad(vg_lite_linear_gradient_t *grad); + + /* Return pointer to a linear gradient object's matrix. */ + vg_lite_matrix_t* vg_lite_get_grad_matrix(vg_lite_linear_gradient_t *grad); + + /* Set attributes for a linear gradient object. */ + vg_lite_error_t vg_lite_set_grad(vg_lite_linear_gradient_t *grad, + vg_lite_uint32_t count, + vg_lite_uint32_t *colors, + vg_lite_uint32_t *stops); + + /* Draw a path with a linear gradient object pattern. */ + vg_lite_error_t vg_lite_draw_grad(vg_lite_buffer_t *target, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t *matrix, + vg_lite_linear_gradient_t *grad, + vg_lite_blend_t blend); + + /* Reset an extended linear gradient object attributes and free image buffer. */ + vg_lite_error_t vg_lite_clear_linear_grad(vg_lite_ext_linear_gradient_t *grad); + + /* Update an extended linear gradient object. */ + vg_lite_error_t vg_lite_update_linear_grad(vg_lite_ext_linear_gradient_t *grad); + + /* Return pointer to an extended linear gradient object's matrix. */ + vg_lite_matrix_t* vg_lite_get_linear_grad_matrix(vg_lite_ext_linear_gradient_t *grad); + + /* Set attributes for an extended linear gradient object. */ + vg_lite_error_t vg_lite_set_linear_grad(vg_lite_ext_linear_gradient_t *grad, + vg_lite_uint32_t count, + vg_lite_color_ramp_t *color_ramp, + vg_lite_linear_gradient_parameter_t grad_param, + vg_lite_gradient_spreadmode_t spread_mode, + vg_lite_uint8_t pre_mult); + + /* Draw a path with an extended linear gradient object. */ + vg_lite_error_t vg_lite_draw_linear_grad(vg_lite_buffer_t *target, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t *path_matrix, + vg_lite_ext_linear_gradient_t *grad, + vg_lite_color_t paint_color, + vg_lite_blend_t blend, + vg_lite_filter_t filter); + + /* Reset a radial gradient object attributes and free image buffer. */ + vg_lite_error_t vg_lite_clear_radial_grad(vg_lite_radial_gradient_t *grad); + + /* Update a radial gradient object. */ + vg_lite_error_t vg_lite_update_radial_grad(vg_lite_radial_gradient_t *grad); + + /* Return pointer to a radial gradient object's matrix. */ + vg_lite_matrix_t* vg_lite_get_radial_grad_matrix(vg_lite_radial_gradient_t *grad); + + /* Set attributes for a radial gradient object. */ + vg_lite_error_t vg_lite_set_radial_grad(vg_lite_radial_gradient_t *grad, + vg_lite_uint32_t count, + vg_lite_color_ramp_t *color_ramp, + vg_lite_radial_gradient_parameter_t grad_param, + vg_lite_gradient_spreadmode_t spread_mode, + vg_lite_uint8_t pre_mult); + + /* Draw a path with a radial gradient object pattern. */ + vg_lite_error_t vg_lite_draw_radial_grad(vg_lite_buffer_t *target, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t *path_matrix, + vg_lite_radial_gradient_t *grad, + vg_lite_color_t paint_color, + vg_lite_blend_t blend, + vg_lite_filter_t filter); + + /* Load an identity matrix. */ + vg_lite_error_t vg_lite_identity(vg_lite_matrix_t *matrix); + + /* Translate a matrix. */ + vg_lite_error_t vg_lite_translate(vg_lite_float_t x, vg_lite_float_t y, vg_lite_matrix_t *matrix); + + /* Scale a matrix. */ + vg_lite_error_t vg_lite_scale(vg_lite_float_t scale_x, vg_lite_float_t scale_y, vg_lite_matrix_t *matrix); + + /* Rotate a matrix. */ + vg_lite_error_t vg_lite_rotate(vg_lite_float_t degrees, vg_lite_matrix_t *matrix); + + vg_lite_error_t vg_lite_perspective(vg_lite_float_t px, vg_lite_float_t py, vg_lite_matrix_t * matrix); + + /* Set a scissor rectangle for render target. */ + vg_lite_error_t vg_lite_set_scissor(vg_lite_int32_t x, vg_lite_int32_t y, vg_lite_int32_t right, vg_lite_int32_t bottom); + + /* Enable scissor. */ + vg_lite_error_t vg_lite_enable_scissor(void); + + /* Disable scissor. */ + vg_lite_error_t vg_lite_disable_scissor(void); + + /* Query size of available contiguous video memory. */ + vg_lite_error_t vg_lite_get_mem_size(vg_lite_uint32_t *size); + + /* Set global alpha value for source image */ + vg_lite_error_t vg_lite_source_global_alpha(vg_lite_global_alpha_t alpha_mode, vg_lite_uint8_t alpha_value); + + /* Set global alpha value for destination image. */ + vg_lite_error_t vg_lite_dest_global_alpha(vg_lite_global_alpha_t alpha_mode, vg_lite_uint8_t alpha_value); + + /* Set colorkey. */ + vg_lite_error_t vg_lite_set_color_key(vg_lite_color_key4_t colorkey); + + /* Enable dither function. Dither is OFF by default. */ + vg_lite_error_t vg_lite_enable_dither(void); + + /* Disable dither function. Dither is OFF by default. */ + vg_lite_error_t vg_lite_disable_dither(void); + + /* Set a 64-byte aligned memory buffer (physical) as VGLite tessellation buffer. */ + vg_lite_error_t vg_lite_set_tess_buffer(vg_lite_uint32_t physical, vg_lite_uint32_t size); + + /* Can be called before vg_lite_init() to overwrite the default VG_LITE_COMMAND_BUFFER_SIZE */ + vg_lite_error_t vg_lite_set_command_buffer_size(vg_lite_uint32_t size); + + /* Set a user-defined external memory buffer (physical, 64-byte aligned) as VGLite command buffer. */ + vg_lite_error_t vg_lite_set_command_buffer(vg_lite_uint32_t physical, vg_lite_uint32_t size); + + /* Setup a pixel transform matrix m[20] which transforms each pixel as following: + * + * |a'| |m0 m1 m2 m3 m4 | |a| + * |r'| |m5 m6 m7 m8 m9 | |r| + * |g'| = |m10 m11 m12 m13 m14|.|g| + * |b'| |m15 m16 m17 m18 m19| |b| + * |1 | |0 0 0 0 1 | |1| + * + * The pixel transform for A, R, G, B channel can be enabled/disabled individually with (channel) parameter. + */ + vg_lite_error_t vg_lite_set_pixel_matrix(vg_lite_pixel_matrix_t matrix, vg_lite_pixel_channel_enable_t *channel); + + /* Setup 3x3 gaussian blur weight values to filter image pixels. + * + * Paramters w0, w1, w2 define a 3x3 gaussian blur weight matrix as below + * + * | w2 w1 w2 | + * | w1 w0 w1 | + * | w2 w1 w2 | + * + * The sum of 9 kernel weights must be 1.0 to avoid convolution overflow ( w0 + 4*w1 + 4*w2 = 1.0 ). + * The 3x3 weight matrix applies to a 3x3 pixel block + * + * | pixel[i-1][j-1] pixel[i][j-1] pixel[i+1][j-1]| + * | pixel[i-1][j] pixel[i][j] pixel[i+1][j] | + * | pixel[i-1][j+1] pixel[i][j+1] pixel[i+1][j+1]| + * + * With the following dot product equation: + * + * color[i][j] = w2*pixel[i-1][j-1] + w1*pixel[i][j-1] + w2*pixel[i+1][j-1] + * + w1*pixel[i-1][j] + w0*pixel[i][j] + w1*pixel[i+1][j] + * + w2*pixel[i-1][j+1] + w1*pixel[i][j+1] + w2*pixel[i+1][j+1]; + */ + vg_lite_error_t vg_lite_gaussian_filter(vg_lite_float_t w0, vg_lite_float_t w1, vg_lite_float_t w2); + + /* Enable masklayer function. Masklayer is OFF by default. */ + vg_lite_error_t vg_lite_enable_masklayer(void); + + /* Disable masklayer function. Masklayer is OFF by default. */ + vg_lite_error_t vg_lite_disable_masklayer(void); + + /* Setup a masklayer. */ + vg_lite_error_t vg_lite_set_masklayer(vg_lite_buffer_t *masklayer); + + /* Free a masklayer and disable mask operation. */ + vg_lite_error_t vg_lite_destroy_masklayer(vg_lite_buffer_t *masklayer); + + /* Create a masklayer with default format A8 and default pixel value 255. */ + vg_lite_error_t vg_lite_create_masklayer(vg_lite_buffer_t *masklayer, + vg_lite_uint32_t width, + vg_lite_uint32_t height); + + /* Set pixel values for a rectangle area in a masklayer */ + vg_lite_error_t vg_lite_fill_masklayer(vg_lite_buffer_t *masklayer, + vg_lite_rectangle_t *rect, + vg_lite_uint8_t value); + + /* Blend a rectangle area of src masklayer with dst masklayer according to (operation). */ + vg_lite_error_t vg_lite_blend_masklayer(vg_lite_buffer_t *dst, + vg_lite_buffer_t *src, + vg_lite_mask_operation_t operation, + vg_lite_rectangle_t *rect); + + /* Render a (path) with (fill_rule), (color), (matrix) to the masklayer. */ + vg_lite_error_t vg_lite_render_masklayer(vg_lite_buffer_t *masklayer, + vg_lite_mask_operation_t operation, + vg_lite_path_t *path, + vg_lite_fill_t fill_rule, + vg_lite_color_t color, + vg_lite_matrix_t *matrix); + + /* Set scissor rectangles. */ + vg_lite_error_t vg_lite_scissor_rects(vg_lite_uint32_t nums, vg_lite_rectangle_t rect[]); + + /* Set mirror orientation. */ + vg_lite_error_t vg_lite_set_mirror(vg_lite_orientation_t orientation); + + /* Set gamma value. */ + vg_lite_error_t vg_lite_set_gamma(vg_lite_gamma_conversion_t gamma_value); + + /* Set source image and target image premultiply states */ + vg_lite_error_t vg_lite_set_premultiply(vg_lite_uint8_t src_premult, vg_lite_uint8_t dst_premult); + + /* Enable color transformation, which is OFF by default. */ + vg_lite_error_t vg_lite_enable_color_transform(void); + + /* Disable color transformation, which is OFF by default. */ + vg_lite_error_t vg_lite_disable_color_transform(void); + + /* Set pixel color transformation scale and bias values for each pixel channel. */ + vg_lite_error_t vg_lite_set_color_transform(vg_lite_color_transform_t *values); + + /* Set flexa stream id. */ + vg_lite_error_t vg_lite_flexa_set_stream(vg_lite_uint8_t stream_id); + + /* set flexa background buffer.*/ + vg_lite_error_t vg_lite_flexa_bg_buffer(vg_lite_uint8_t stream_id, + vg_lite_buffer_t *buffer, + vg_lite_uint32_t seg_count, + vg_lite_uint32_t seg_size); + + /* Enable flexa. */ + vg_lite_error_t vg_lite_flexa_enable(void); + + /* Disable flexa.*/ + vg_lite_error_t vg_lite_flexa_disable(void); + + /* Set flexa stop flag after the last frame. */ + vg_lite_error_t vg_lite_flexa_stop_frame(void); + +#endif /* VGLITE_VERSION_3_0 */ + +#ifdef __cplusplus +} +#endif +#endif /* _vg_lite_h_ */ diff --git a/src/dev/vg_lite_tvg/vg_lite_matrix.c b/src/dev/vg_lite_tvg/vg_lite_matrix.c new file mode 100644 index 000000000..23ad1cca2 --- /dev/null +++ b/src/dev/vg_lite_tvg/vg_lite_matrix.c @@ -0,0 +1,147 @@ +/** + * @file vg_lite_matrix.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "../../lv_conf_internal.h" + +#if LV_USE_VG_LITE_THORVG + +#include +#include +#include "vg_lite.h" + +/********************* + * DEFINES + *********************/ + +#ifndef M_PI + #define M_PI 3.1415926f +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +vg_lite_error_t vg_lite_identity(vg_lite_matrix_t * matrix) +{ + /* Set identify matrix. */ + matrix->m[0][0] = 1.0f; + matrix->m[0][1] = 0.0f; + matrix->m[0][2] = 0.0f; + matrix->m[1][0] = 0.0f; + matrix->m[1][1] = 1.0f; + matrix->m[1][2] = 0.0f; + matrix->m[2][0] = 0.0f; + matrix->m[2][1] = 0.0f; + matrix->m[2][2] = 1.0f; + return VG_LITE_SUCCESS; +} + +static void multiply(vg_lite_matrix_t * matrix, vg_lite_matrix_t * mult) +{ + vg_lite_matrix_t temp; + int row, column; + + /* Process all rows. */ + for(row = 0; row < 3; row++) { + /* Process all columns. */ + for(column = 0; column < 3; column++) { + /* Compute matrix entry. */ + temp.m[row][column] = (matrix->m[row][0] * mult->m[0][column]) + + (matrix->m[row][1] * mult->m[1][column]) + + (matrix->m[row][2] * mult->m[2][column]); + } + } + + /* Copy temporary matrix into result. */ + memcpy(matrix, &temp, sizeof(temp)); +} + +vg_lite_error_t vg_lite_translate(vg_lite_float_t x, vg_lite_float_t y, vg_lite_matrix_t * matrix) +{ + /* Set translation matrix. */ + vg_lite_matrix_t t = { { {1.0f, 0.0f, x}, + {0.0f, 1.0f, y}, + {0.0f, 0.0f, 1.0f} + } + }; + + /* Multiply with current matrix. */ + multiply(matrix, &t); + return VG_LITE_SUCCESS; +} + +vg_lite_error_t vg_lite_scale(vg_lite_float_t scale_x, vg_lite_float_t scale_y, vg_lite_matrix_t * matrix) +{ + /* Set scale matrix. */ + vg_lite_matrix_t s = { { {scale_x, 0.0f, 0.0f}, + {0.0f, scale_y, 0.0f}, + {0.0f, 0.0f, 1.0f} + } + }; + + /* Multiply with current matrix. */ + multiply(matrix, &s); + return VG_LITE_SUCCESS; +} + +vg_lite_error_t vg_lite_rotate(vg_lite_float_t degrees, vg_lite_matrix_t * matrix) +{ + /* Convert degrees into radians. */ + vg_lite_float_t angle = degrees / 180.0f * M_PI; + + /* Compuet cosine and sine values. */ + vg_lite_float_t cos_angle = cosf(angle); + vg_lite_float_t sin_angle = sinf(angle); + + /* Set rotation matrix. */ + vg_lite_matrix_t r = { { {cos_angle, -sin_angle, 0.0f}, + {sin_angle, cos_angle, 0.0f}, + {0.0f, 0.0f, 1.0f} + } + }; + + /* Multiply with current matrix. */ + multiply(matrix, &r); + return VG_LITE_SUCCESS; +} + +vg_lite_error_t vg_lite_perspective(vg_lite_float_t px, vg_lite_float_t py, vg_lite_matrix_t * matrix) +{ + /* set prespective matrix */ + vg_lite_matrix_t p = { { {1.0f, 0.0f, 0.0f}, + {0.0f, 1.0f, 0.0f}, + {px, py, 1.0f} + } + }; + /* Multiply with current matrix. */ + multiply(matrix, &p); + return VG_LITE_SUCCESS; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +#endif /*LV_USE_VG_LITE_THORVG*/ \ No newline at end of file diff --git a/src/dev/vg_lite_tvg/vg_lite_tvg.cpp b/src/dev/vg_lite_tvg/vg_lite_tvg.cpp new file mode 100644 index 000000000..a488d9ba2 --- /dev/null +++ b/src/dev/vg_lite_tvg/vg_lite_tvg.cpp @@ -0,0 +1,2409 @@ +/** + * @file vg_lite_tvg.cpp + * + */ + +/********************* + * INCLUDES + *********************/ +#include "../../lv_conf_internal.h" +#if LV_USE_VG_LITE_THORVG + +#include "vg_lite.h" +#include "../../lvgl.h" +#include "../../libs/thorvg/thorvg.h" +#include +#include +#include +#include +#include +#include + +#ifdef LV_VG_LITE_THORVG_YUV_SUPPORT + #include +#endif + +/********************* + * DEFINES + *********************/ + +/* Configuration reference. */ +// #define LV_VG_LITE_THORVG_LVGL_BLEND_SUPPORT +// #define LV_VG_LITE_THORVG_YUV_SUPPORT +// #define LV_VG_LITE_THORVG_16PIXELS_ALIGN +// #define LV_VG_LITE_THORVG_THREAD_RENDER +// #define LV_VG_LITE_THORVG_TRACE_API + +#ifndef LV_VG_LITE_THORVG_BUF_ADDR_ALIGN + #define LV_VG_LITE_THORVG_BUF_ADDR_ALIGN 64 +#endif + +#define TVG_CANVAS_ENGINE CanvasEngine::Sw +#define TVG_COLOR(COLOR) B(COLOR), G(COLOR), R(COLOR), A(COLOR) +#define TVG_IS_VG_FMT_SUPPORT(fmt) ((fmt) == VG_LITE_BGRA8888 || (fmt) == VG_LITE_BGRX8888) + +#define TVG_CHECK_RETURN_VG_ERROR(FUNC) \ + do { \ + Result res = FUNC; \ + if (res != Result::Success) { \ + LV_LOG_ERROR("Executed '" #FUNC "' error: %d\n", (int)res); \ + return vg_lite_error_conv(res); \ + } \ + } while (0) +#define TVG_CHECK_RETURN_RESULT(FUNC) \ + do { \ + Result res = FUNC; \ + if (res != Result::Success) { \ + LV_LOG_ERROR("Executed '" #FUNC "' error: %d\n", (int)res);\ + return res; \ + } \ + } while (0) + +/* clang-format off */ + +#define IS_INDEX_FMT(fmt) \ + ((fmt) == VG_LITE_INDEX_1 \ + || (fmt) == VG_LITE_INDEX_2 \ + || (fmt) == VG_LITE_INDEX_4 \ + || (fmt) == VG_LITE_INDEX_8) + +#define VLC_GET_ARG(CUR, INDEX) vlc_get_arg((cur + (INDEX) * fmt_len), path->format); +#define VLC_GET_OP_CODE(ptr) (*((uint8_t*)ptr)) +#define VLC_OP_ARG_LEN(OP, LEN) \ + case VLC_OP_##OP: \ + return (LEN) + +#define A(color) ((color) >> 24) +#define R(color) (((color) & 0x00ff0000) >> 16) +#define G(color) (((color) & 0x0000ff00) >> 8) +#define B(color) ((color) & 0xff) +#define ARGB(a, r, g, b) ((a) << 24) | ((r) << 16) | ((g) << 8) | (b) +#define MIN(a, b) (a) > (b) ? (b) : (a) +#define MAX(a, b) (a) > (b) ? (a) : (b) +#define UDIV255(x) (((x) * 0x8081U) >> 0x17) +#define LERP(v1, v2, w) ((v1) * (w) + (v2) * (1.0f - (w))) +#define CLAMP(x, min, max) (((x) < (min)) ? (min) : ((x) > (max)) ? (max) : (x)) +#define COLOR_FROM_RAMP(ColorRamp) (((vg_lite_float_t*)ColorRamp) + 1) + +#define VG_LITE_RETURN_ERROR(func) \ + if ((error = func) != VG_LITE_SUCCESS) \ + return error + +#define VG_LITE_ALIGN(number, align_bytes) \ + (((number) + ((align_bytes)-1)) & ~((align_bytes)-1)) + +#define VG_LITE_IS_ALIGNED(num, align) (((uintptr_t)(num) & ((align)-1)) == 0) + +#define VG_LITE_IS_ALPHA_FORMAT(format) \ + ((format) == VG_LITE_A8 || (format) == VG_LITE_A4) + +/* clang-format on */ + +/********************** + * TYPEDEFS + **********************/ + +using namespace tvg; + +#pragma pack(1) +typedef struct { + uint8_t blue; + uint8_t green; + uint8_t red; +} vg_color24_t; + +typedef struct { + uint16_t blue : 5; + uint16_t green : 6; + uint16_t red : 5; +} vg_color16_t; + +typedef struct { + vg_color16_t c; + uint8_t alpha; +} vg_color16_alpha_t; + +typedef struct { + uint8_t blue; + uint8_t green; + uint8_t red; + uint8_t alpha; +} vg_color32_t; + +#pragma pack() + +class vg_lite_ctx +{ + public: + std::unique_ptr canvas; + void * target_buffer; + uint32_t target_px_size; + vg_lite_buffer_format_t target_format; + + public: + vg_lite_ctx() + : target_buffer { nullptr } + , target_px_size { 0 } + , target_format { VG_LITE_BGRA8888 } + , clut_2colors { 0 } + , clut_4colors { 0 } + , clut_16colors { 0 } + , clut_256colors { 0 } + { + canvas = SwCanvas::gen(); + } + + uint32_t * get_image_buffer(uint32_t w, uint32_t h) + { + src_buffer.resize(w * h); + return src_buffer.data(); + } + + uint32_t * get_temp_target_buffer(uint32_t w, uint32_t h) + { + uint32_t px_size = w * h; + if(px_size > dest_buffer.size()) { + + /* During resize, the first address of the vector may change + * to ensure that there is no unfinished drawing. + */ + LV_ASSERT(target_buffer == nullptr); + dest_buffer.resize(w * h); + } + return dest_buffer.data(); + } + + uint32_t * get_temp_target_buffer() + { + return dest_buffer.data(); + } + + void set_CLUT(uint32_t count, const uint32_t * colors) + { + switch(count) { + case 2: + memcpy(clut_2colors, colors, sizeof(clut_2colors)); + break; + case 4: + memcpy(clut_4colors, colors, sizeof(clut_4colors)); + break; + case 16: + memcpy(clut_16colors, colors, sizeof(clut_16colors)); + break; + case 256: + memcpy(clut_256colors, colors, sizeof(clut_256colors)); + break; + default: + LV_ASSERT(false); + break; + } + } + + const uint32_t * get_CLUT(vg_lite_buffer_format_t format) + { + switch(format) { + case VG_LITE_INDEX_1: + return clut_2colors; + + case VG_LITE_INDEX_2: + return clut_2colors; + + case VG_LITE_INDEX_4: + return clut_4colors; + + case VG_LITE_INDEX_8: + return clut_256colors; + + default: + break; + } + + LV_ASSERT(false); + return nullptr; + } + + static vg_lite_ctx * get_instance() + { + static vg_lite_ctx instance; + return &instance; + } + + private: + /* */ + std::vector src_buffer; + std::vector dest_buffer; + + uint32_t clut_2colors[2]; + uint32_t clut_4colors[4]; + uint32_t clut_16colors[16]; + uint32_t clut_256colors[256]; +}; + +template +class vg_lite_converter +{ + public: + typedef void (*converter_cb_t)(DEST_TYPE * dest, const SRC_TYPE * src, uint32_t px_size, uint32_t color); + + public: + vg_lite_converter(converter_cb_t converter) + : _converter_cb(converter) + { + } + + void convert(vg_lite_buffer_t * dest_buf, const vg_lite_buffer_t * src_buf, uint32_t color = 0) + { + LV_ASSERT(_converter_cb); + uint8_t * dest = (uint8_t *)dest_buf->memory; + const uint8_t * src = (const uint8_t *)src_buf->memory; + uint32_t h = src_buf->height; + + while(h--) { + _converter_cb((DEST_TYPE *)dest, (const SRC_TYPE *)src, src_buf->width, color); + dest += dest_buf->stride; + src += src_buf->stride; + } + } + + private: + converter_cb_t _converter_cb; +}; + +typedef vg_lite_float_t FLOATVECTOR4[4]; + +/********************** + * STATIC PROTOTYPES + **********************/ + +static vg_lite_error_t vg_lite_error_conv(Result result); +static Matrix matrix_conv(const vg_lite_matrix_t * matrix); +static FillRule fill_rule_conv(vg_lite_fill_t fill); +static BlendMethod blend_method_conv(vg_lite_blend_t blend); +static Result shape_append_path(std::unique_ptr & shape, vg_lite_path_t * path, vg_lite_matrix_t * matrix); +static Result shape_append_rect(std::unique_ptr & shape, const vg_lite_buffer_t * target, + const vg_lite_rectangle_t * rect); +static Result canvas_set_target(vg_lite_ctx * ctx, vg_lite_buffer_t * target); +static Result picture_load(vg_lite_ctx * ctx, std::unique_ptr & picture, const vg_lite_buffer_t * source, + vg_lite_color_t color = 0); + +static inline bool math_zero(float a) +{ + return (fabs(a) < FLT_EPSILON); +} + +static inline bool math_equal(float a, float b) +{ + return math_zero(a - b); +} + +static void ClampColor(FLOATVECTOR4 Source, FLOATVECTOR4 Target, uint8_t Premultiplied); +static uint8_t PackColorComponent(vg_lite_float_t value); +static void get_format_bytes(vg_lite_buffer_format_t format, + uint32_t * mul, + uint32_t * div, + uint32_t * bytes_align); + +/********************** + * STATIC VARIABLES + **********************/ + +/* color converters */ + +static vg_lite_converter conv_bgra8888_to_bgr565( + [](vg_color16_t * dest, const vg_color32_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + dest->red = src->red >> 3; + dest->green = src->green >> 2; + dest->blue = src->blue >> 3; + src++; + dest++; + } +}); + +static vg_lite_converter conv_bgra8888_to_bgra5658( + [](vg_color16_alpha_t * dest, const vg_color32_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + dest->c.red = src->red >> 3; + dest->c.green = src->green >> 2; + dest->c.blue = src->blue >> 3; + dest->alpha = src->alpha; + src++; + dest++; + } +}); + +static vg_lite_converter conv_bgr565_to_bgra8888( + [](vg_color32_t * dest, const vg_color16_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + dest->red = src->red << 3; + dest->green = src->green << 2; + dest->blue = src->blue << 3; + dest->alpha = 0xFF; + src++; + dest++; + } +}); + +static vg_lite_converter conv_bgra5658_to_bgra8888( + [](vg_color32_t * dest, const vg_color16_alpha_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + dest->red = src->c.red << 3; + dest->green = src->c.green << 2; + dest->blue = src->c.blue << 3; + dest->alpha = src->alpha; + src++; + dest++; + } +}); + +static vg_lite_converter conv_bgrx8888_to_bgra8888( + [](vg_color32_t * dest, const vg_color32_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + *dest = *src; + dest->alpha = 0xFF; + dest++; + src++; + } +}); + +static vg_lite_converter conv_bgr888_to_bgra8888( + [](vg_color32_t * dest, const vg_color24_t * src, uint32_t px_size, uint32_t /* color */) +{ + while(px_size--) { + dest->red = src->red; + dest->green = src->green; + dest->blue = src->blue; + dest->alpha = 0xFF; + src++; + dest++; + } +}); + +static vg_lite_converter conv_alpha8_to_bgra8888( + [](vg_color32_t * dest, const uint8_t * src, uint32_t px_size, uint32_t color) +{ + while(px_size--) { + uint8_t alpha = *src; + dest->alpha = alpha; + dest->red = UDIV255(B(color) * alpha); + dest->green = UDIV255(G(color) * alpha); + dest->blue = UDIV255(R(color) * alpha); + dest++; + src++; + } +}); + +static vg_lite_converter conv_alpha4_to_bgra8888( + [](vg_color32_t * dest, const uint8_t * src, uint32_t px_size, uint32_t color) +{ + /* 1 byte -> 2 px */ + px_size /= 2; + + while(px_size--) { + /* high 4bit */ + uint8_t alpha = (*src & 0xF0); + dest->alpha = alpha; + dest->red = UDIV255(B(color) * alpha); + dest->green = UDIV255(G(color) * alpha); + dest->blue = UDIV255(R(color) * alpha); + dest++; + + /* low 4bit */ + alpha = (*src & 0x0F) << 4; + dest->alpha = alpha; + dest->red = UDIV255(B(color) * alpha); + dest->green = UDIV255(G(color) * alpha); + dest->blue = UDIV255(R(color) * alpha); + + dest++; + src++; + } +}); + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +extern "C" { + + void gpu_init(void) + { + vg_lite_init(0, 0); + } + + vg_lite_error_t vg_lite_allocate(vg_lite_buffer_t * buffer) + { +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_allocate %p\n", buffer); +#endif + + if(buffer->format == VG_LITE_RGBA8888_ETC2_EAC && (buffer->width % 16 || buffer->height % 4)) { + return VG_LITE_INVALID_ARGUMENT; + } + + /* Reset planar. */ + buffer->yuv.uv_planar = buffer->yuv.v_planar = buffer->yuv.alpha_planar = 0; + + /* Align height in case format is tiled. */ + if(buffer->format >= VG_LITE_YUY2 && buffer->format <= VG_LITE_NV16) { + buffer->height = VG_LITE_ALIGN(buffer->height, 4); + buffer->yuv.swizzle = VG_LITE_SWIZZLE_UV; + } + + if(buffer->format >= VG_LITE_YUY2_TILED && buffer->format <= VG_LITE_AYUY2_TILED) { + buffer->height = VG_LITE_ALIGN(buffer->height, 4); + buffer->tiled = VG_LITE_TILED; + buffer->yuv.swizzle = VG_LITE_SWIZZLE_UV; + } + + uint32_t mul, div, align; + get_format_bytes(buffer->format, &mul, &div, &align); + uint32_t stride = VG_LITE_ALIGN((buffer->width * mul / div), align); + + buffer->stride = stride; + buffer->memory = aligned_alloc(LV_VG_LITE_THORVG_BUF_ADDR_ALIGN, stride * buffer->height); + LV_ASSERT(buffer->memory); + buffer->address = (uint32_t)(uintptr_t)buffer->memory; + buffer->handle = buffer->memory; + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_free(vg_lite_buffer_t * buffer) + { + LV_ASSERT(buffer->memory); + free(buffer->memory); + memset(buffer, 0, sizeof(vg_lite_buffer_t)); + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_upload_buffer(vg_lite_buffer_t * buffer, uint8_t * data[3], uint32_t stride[3]) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_map(vg_lite_buffer_t * buffer, vg_lite_map_flag_t flag, int32_t fd) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_unmap(vg_lite_buffer_t * buffer) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_clear(vg_lite_buffer_t * target, vg_lite_rectangle_t * rectangle, vg_lite_color_t color) + { + auto ctx = vg_lite_ctx::get_instance(); + TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target)); + + auto shape = Shape::gen(); + TVG_CHECK_RETURN_VG_ERROR(shape_append_rect(shape, target, rectangle)); + TVG_CHECK_RETURN_VG_ERROR(shape->fill(TVG_COLOR(color))); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(shape))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_blit(vg_lite_buffer_t * target, + vg_lite_buffer_t * source, + vg_lite_matrix_t * matrix, + vg_lite_blend_t blend, + vg_lite_color_t color, + vg_lite_filter_t filter) + { + auto ctx = vg_lite_ctx::get_instance(); + canvas_set_target(ctx, target); + + auto picture = Picture::gen(); + + TVG_CHECK_RETURN_VG_ERROR(picture_load(ctx, picture, source, color)); + TVG_CHECK_RETURN_VG_ERROR(picture->transform(matrix_conv(matrix))); + TVG_CHECK_RETURN_VG_ERROR(picture->blend(blend_method_conv(blend))); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(picture))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_blit2(vg_lite_buffer_t * target, + vg_lite_buffer_t * source0, + vg_lite_buffer_t * source1, + vg_lite_matrix_t * matrix0, + vg_lite_matrix_t * matrix1, + vg_lite_blend_t blend, + vg_lite_filter_t filter) + { + if(!vg_lite_query_feature(gcFEATURE_BIT_VG_DOUBLE_IMAGE)) { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t error; + + VG_LITE_RETURN_ERROR(vg_lite_blit(target, source0, matrix0, blend, 0, filter)); + VG_LITE_RETURN_ERROR(vg_lite_blit(target, source1, matrix1, blend, 0, filter)); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_blit_rect(vg_lite_buffer_t * target, + vg_lite_buffer_t * source, + vg_lite_rectangle_t * rect, + vg_lite_matrix_t * matrix, + vg_lite_blend_t blend, + vg_lite_color_t color, + vg_lite_filter_t filter) + { + auto ctx = vg_lite_ctx::get_instance(); + TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target)); + + auto shape = Shape::gen(); + TVG_CHECK_RETURN_VG_ERROR(shape_append_rect(shape, target, rect)); + TVG_CHECK_RETURN_VG_ERROR(shape->transform(matrix_conv(matrix))); + + auto picture = tvg::Picture::gen(); + TVG_CHECK_RETURN_VG_ERROR(picture_load(ctx, picture, source, color)); + TVG_CHECK_RETURN_VG_ERROR(picture->transform(matrix_conv(matrix))); + TVG_CHECK_RETURN_VG_ERROR(picture->blend(blend_method_conv(blend))); + TVG_CHECK_RETURN_VG_ERROR(picture->composite(std::move(shape), CompositeMethod::ClipPath)); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(picture))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_init(int32_t tessellation_width, int32_t tessellation_height) + { +#ifdef LV_VG_LITE_THORVG_THREAD_RENDER + /* Threads Count */ + auto threads = std::thread::hardware_concurrency(); + if(threads > 0) { + --threads; /* Allow the designated main thread capacity */ + } +#endif + + /* Initialize ThorVG Engine */ + TVG_CHECK_RETURN_VG_ERROR(Initializer::init(TVG_CANVAS_ENGINE, 0)); + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_close(void) + { + TVG_CHECK_RETURN_VG_ERROR(Initializer::term(TVG_CANVAS_ENGINE)); + return VG_LITE_SUCCESS; + } + + static void picture_bgra8888_to_bgr565(vg_color16_t * dest, const vg_color32_t * src, uint32_t px_size) + { + while(px_size--) { + dest->red = src->red >> 3; + dest->green = src->green >> 2; + dest->blue = src->blue >> 3; + src++; + dest++; + } + } + + static void picture_bgra8888_to_bgra5658(vg_color16_alpha_t * dest, const vg_color32_t * src, uint32_t px_size) + { + while(px_size--) { + dest->c.red = src->red >> 3; + dest->c.green = src->green >> 2; + dest->c.blue = src->blue >> 3; + dest->alpha = src->alpha; + src++; + dest++; + } + } + + vg_lite_error_t vg_lite_finish(void) + { + vg_lite_ctx * ctx = vg_lite_ctx::get_instance(); + + if(ctx->canvas->draw() == Result::InsufficientCondition) { + return VG_LITE_SUCCESS; + } + + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->sync()); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->clear(true)); + + /* If target_buffer is not in a format supported by thorvg, software conversion is required. */ + if(ctx->target_buffer) { + switch(ctx->target_format) { + case VG_LITE_BGR565: + picture_bgra8888_to_bgr565( + (vg_color16_t *)ctx->target_buffer, + (const vg_color32_t *)ctx->get_temp_target_buffer(), + ctx->target_px_size); + break; + case VG_LITE_BGRA5658: + picture_bgra8888_to_bgra5658( + (vg_color16_alpha_t *)ctx->target_buffer, + (const vg_color32_t *)ctx->get_temp_target_buffer(), + ctx->target_px_size); + break; + default: + TVG_LOG("unsupport format: %d\n", ctx->target_format); + LV_ASSERT(false); + break; + } + + /* finish convert, clean target buffer info */ + ctx->target_buffer = nullptr; + ctx->target_px_size = 0; + } + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_flush(void) + { + return vg_lite_finish(); + } + + vg_lite_error_t vg_lite_draw(vg_lite_buffer_t * target, + vg_lite_path_t * path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t * matrix, + vg_lite_blend_t blend, + vg_lite_color_t color) + { + auto ctx = vg_lite_ctx::get_instance(); + TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target)); + + auto shape = Shape::gen(); + TVG_CHECK_RETURN_VG_ERROR(shape_append_path(shape, path, matrix)); + TVG_CHECK_RETURN_VG_ERROR(shape->transform(matrix_conv(matrix))); + TVG_CHECK_RETURN_VG_ERROR(shape->fill(fill_rule_conv(fill_rule));); + TVG_CHECK_RETURN_VG_ERROR(shape->blend(blend_method_conv(blend))); + TVG_CHECK_RETURN_VG_ERROR(shape->fill(TVG_COLOR(color))); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(shape))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_get_register(uint32_t address, uint32_t * result) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_get_info(vg_lite_info_t * info) + { + info->api_version = VGLITE_API_VERSION_3_0; + info->header_version = VGLITE_HEADER_VERSION; + info->release_version = VGLITE_RELEASE_VERSION; + info->reserved = 0; + return VG_LITE_SUCCESS; + } + + uint32_t vg_lite_get_product_info(char * name, uint32_t * chip_id, uint32_t * chip_rev) + { + strcpy(name, "GCNanoLiteV"); + *chip_id = 0x265; + *chip_rev = 0x2000; + return 1; + } + + uint32_t vg_lite_query_feature(vg_lite_feature_t feature) + { + switch(feature) { + case gcFEATURE_BIT_VG_IM_INDEX_FORMAT: + case gcFEATURE_BIT_VG_SCISSOR: + case gcFEATURE_BIT_VG_BORDER_CULLING: + case gcFEATURE_BIT_VG_RGBA2_FORMAT: + case gcFEATURE_BIT_VG_IM_FASTCLAER: + case gcFEATURE_BIT_VG_GLOBAL_ALPHA: + case gcFEATURE_BIT_VG_COLOR_KEY: + case gcFEATURE_BIT_VG_24BIT: + case gcFEATURE_BIT_VG_DITHER: + case gcFEATURE_BIT_VG_USE_DST: + +#ifdef LV_VG_LITE_THORVG_LVGL_BLEND_SUPPORT + case gcFEATURE_BIT_VG_LVGL_SUPPORT: +#endif + +#ifdef LV_VG_LITE_THORVG_YUV_SUPPORT + case gcFEATURE_BIT_VG_YUV_INPUT: +#endif + +#ifdef LV_VG_LITE_THORVG_16PIXELS_ALIGN + case gcFEATURE_BIT_VG_16PIXELS_ALIGN: +#endif + return 1; + default: + break; + } + return 0; + } + + vg_lite_error_t vg_lite_init_path(vg_lite_path_t * path, + vg_lite_format_t data_format, + vg_lite_quality_t quality, + uint32_t path_length, + void * path_data, + vg_lite_float_t min_x, vg_lite_float_t min_y, + vg_lite_float_t max_x, vg_lite_float_t max_y) + { + if(!path) { + return VG_LITE_INVALID_ARGUMENT; + } + + path->format = data_format; + path->quality = quality; + path->bounding_box[0] = min_x; + path->bounding_box[1] = min_y; + path->bounding_box[2] = max_x; + path->bounding_box[3] = max_y; + + path->path_length = path_length; + path->path = path_data; + + path->path_changed = 1; + path->uploaded.address = 0; + path->uploaded.bytes = 0; + path->uploaded.handle = NULL; + path->uploaded.memory = NULL; + path->pdata_internal = 0; + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_init_arc_path(vg_lite_path_t * path, + vg_lite_format_t data_format, + vg_lite_quality_t quality, + uint32_t path_length, + void * path_data, + vg_lite_float_t min_x, vg_lite_float_t min_y, + vg_lite_float_t max_x, vg_lite_float_t max_y) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_clear_path(vg_lite_path_t * path) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_uint32_t vg_lite_get_path_length(vg_lite_uint8_t * opcode, + vg_lite_uint32_t count, + vg_lite_format_t format) + { + return 0; + } + + vg_lite_error_t vg_lite_append_path(vg_lite_path_t * path, + uint8_t * cmd, + void * data, + uint32_t seg_count) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_upload_path(vg_lite_path_t * path) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_CLUT(uint32_t count, + uint32_t * colors) + { + if(!vg_lite_query_feature(gcFEATURE_BIT_VG_IM_INDEX_FORMAT)) { + return VG_LITE_NOT_SUPPORT; + } + LV_ASSERT(colors); + + auto ctx = vg_lite_ctx::get_instance(); + ctx->set_CLUT(count, colors); + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_draw_pattern(vg_lite_buffer_t * target, + vg_lite_path_t * path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t * path_matrix, + vg_lite_buffer_t * pattern_image, + vg_lite_matrix_t * pattern_matrix, + vg_lite_blend_t blend, + vg_lite_pattern_mode_t pattern_mode, + vg_lite_color_t pattern_color, + vg_lite_color_t color, + vg_lite_filter_t filter) + { + auto ctx = vg_lite_ctx::get_instance(); + TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target)); + + auto shape = Shape::gen(); + TVG_CHECK_RETURN_VG_ERROR(shape_append_path(shape, path, path_matrix)); + TVG_CHECK_RETURN_VG_ERROR(shape->fill(fill_rule_conv(fill_rule))); + TVG_CHECK_RETURN_VG_ERROR(shape->transform(matrix_conv(path_matrix))); + + auto picture = tvg::Picture::gen(); + TVG_CHECK_RETURN_VG_ERROR(picture_load(ctx, picture, pattern_image, color)); + TVG_CHECK_RETURN_VG_ERROR(picture->transform(matrix_conv(pattern_matrix))); + TVG_CHECK_RETURN_VG_ERROR(picture->blend(blend_method_conv(blend))); + TVG_CHECK_RETURN_VG_ERROR(picture->composite(std::move(shape), CompositeMethod::ClipPath)); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(picture))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_init_grad(vg_lite_linear_gradient_t * grad) + { + vg_lite_error_t error = VG_LITE_SUCCESS; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_init_grad %p\n", grad); +#endif + + /* Set the member values according to driver defaults. */ + grad->image.width = VLC_GRADIENT_BUFFER_WIDTH; + grad->image.height = 1; + grad->image.stride = 0; + grad->image.format = VG_LITE_BGRA8888; + + /* Allocate the image for gradient. */ + error = vg_lite_allocate(&grad->image); + + grad->count = 0; + + return error; + } + + vg_lite_error_t vg_lite_set_linear_grad(vg_lite_ext_linear_gradient_t * grad, + vg_lite_uint32_t count, + vg_lite_color_ramp_t * color_ramp, + vg_lite_linear_gradient_parameter_t linear_gradient, + vg_lite_gradient_spreadmode_t spread_mode, + vg_lite_uint8_t pre_multiplied) + { + static vg_lite_color_ramp_t default_ramp[] = { + { + 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + }, + { + 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f + } + }; + + uint32_t i, trg_count; + vg_lite_float_t prev_stop; + vg_lite_color_ramp_t * src_ramp; + vg_lite_color_ramp_t * src_ramp_last; + vg_lite_color_ramp_t * trg_ramp; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_set_linear_grad %p %d %p (%f %f %f %f) %d %d\n", grad, count, color_ramp, + linear_gradient.X0, linear_gradient.X1, linear_gradient.Y0, linear_gradient.Y1, spread_mode, pre_multiplied); +#endif + + /* Reset the count. */ + trg_count = 0; + + if((linear_gradient.X0 == linear_gradient.X1) && (linear_gradient.Y0 == linear_gradient.Y1)) + return VG_LITE_INVALID_ARGUMENT; + + grad->linear_grad = linear_gradient; + grad->pre_multiplied = pre_multiplied; + grad->spread_mode = spread_mode; + + if(!count || count > VLC_MAX_COLOR_RAMP_STOPS || color_ramp == NULL) + goto Empty_sequence_handler; + + for(i = 0; i < count; i++) + grad->color_ramp[i] = color_ramp[i]; + grad->ramp_length = count; + + /* Determine the last source ramp. */ + src_ramp_last + = grad->color_ramp + + grad->ramp_length; + + /* Set the initial previous stop. */ + prev_stop = -1; + + /* Reset the count. */ + trg_count = 0; + + /* Walk through the source ramp. */ + for( + src_ramp = grad->color_ramp, trg_ramp = grad->converted_ramp; + (src_ramp < src_ramp_last) && (trg_count < VLC_MAX_COLOR_RAMP_STOPS + 2); + src_ramp += 1) { + /* Must be in increasing order. */ + if(src_ramp->stop < prev_stop) { + /* Ignore the entire sequence. */ + trg_count = 0; + break; + } + + /* Update the previous stop value. */ + prev_stop = src_ramp->stop; + + /* Must be within [0..1] range. */ + if((src_ramp->stop < 0.0f) || (src_ramp->stop > 1.0f)) { + /* Ignore. */ + continue; + } + + /* Clamp color. */ + ClampColor(COLOR_FROM_RAMP(src_ramp), COLOR_FROM_RAMP(trg_ramp), 0); + + /* First stop greater then zero? */ + if((trg_count == 0) && (src_ramp->stop > 0.0f)) { + /* Force the first stop to 0.0f. */ + trg_ramp->stop = 0.0f; + + /* Replicate the entry. */ + trg_ramp[1] = *trg_ramp; + trg_ramp[1].stop = src_ramp->stop; + + /* Advance. */ + trg_ramp += 2; + trg_count += 2; + } + else { + /* Set the stop value. */ + trg_ramp->stop = src_ramp->stop; + + /* Advance. */ + trg_ramp += 1; + trg_count += 1; + } + } + + /* Empty sequence? */ + if(trg_count == 0) { + memcpy(grad->converted_ramp, default_ramp, sizeof(default_ramp)); + grad->converted_length = sizeof(default_ramp) / 5; + } + else { + /* The last stop must be at 1.0. */ + if(trg_ramp[-1].stop != 1.0f) { + /* Replicate the last entry. */ + *trg_ramp = trg_ramp[-1]; + + /* Force the last stop to 1.0f. */ + trg_ramp->stop = 1.0f; + + /* Update the final entry count. */ + trg_count += 1; + } + + /* Set new length. */ + grad->converted_length = trg_count; + } + return VG_LITE_SUCCESS; + +Empty_sequence_handler: + memcpy(grad->converted_ramp, default_ramp, sizeof(default_ramp)); + grad->converted_length = sizeof(default_ramp) / 5; + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_update_linear_grad(vg_lite_ext_linear_gradient_t * grad) + { + uint32_t ramp_length; + vg_lite_color_ramp_t * color_ramp; + uint32_t common, stop; + uint32_t i, width; + uint8_t * bits; + vg_lite_float_t x0, y0, x1, y1, length; + vg_lite_error_t error = VG_LITE_SUCCESS; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_update_linear_grad %p\n", grad); +#endif + + /* Get shortcuts to the color ramp. */ + ramp_length = grad->converted_length; + color_ramp = grad->converted_ramp; + + x0 = grad->linear_grad.X0; + y0 = grad->linear_grad.Y0; + x1 = grad->linear_grad.X1; + y1 = grad->linear_grad.Y1; + length = (vg_lite_float_t)sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); + + if(length <= 0) + return VG_LITE_INVALID_ARGUMENT; + /* Find the common denominator of the color ramp stops. */ + if(length < 1) { + common = 1; + } + else { + common = (uint32_t)length; + } + + for(i = 0; i < ramp_length; ++i) { + if(color_ramp[i].stop != 0.0f) { + vg_lite_float_t mul = common * color_ramp[i].stop; + vg_lite_float_t frac = mul - (vg_lite_float_t)floor(mul); + if(frac > 0.00013f) { /* Suppose error for zero is 0.00013 */ + common = MAX(common, (uint32_t)(1.0f / frac + 0.5f)); + } + } + } + + /* Compute the width of the required color array. */ + width = common + 1; + + /* Allocate the color ramp surface. */ + memset(&grad->image, 0, sizeof(grad->image)); + grad->image.width = width; + grad->image.height = 1; + grad->image.stride = 0; + grad->image.image_mode = VG_LITE_NONE_IMAGE_MODE; + grad->image.format = VG_LITE_ABGR8888; + + /* Allocate the image for gradient. */ + VG_LITE_RETURN_ERROR(vg_lite_allocate(&grad->image)); + memset(grad->image.memory, 0, grad->image.stride * grad->image.height); + width = common + 1; + /* Set pointer to color array. */ + bits = (uint8_t *)grad->image.memory; + + /* Start filling the color array. */ + stop = 0; + for(i = 0; i < width; ++i) { + vg_lite_float_t gradient; + vg_lite_float_t color[4]; + vg_lite_float_t color1[4]; + vg_lite_float_t color2[4]; + vg_lite_float_t weight; + + if(i == 241) + i = 241; + /* Compute gradient for current color array entry. */ + gradient = (vg_lite_float_t)i / (vg_lite_float_t)(width - 1); + + /* Find the entry in the color ramp that matches or exceeds this + ** gradient. */ + while(gradient > color_ramp[stop].stop) { + ++stop; + } + + if(gradient == color_ramp[stop].stop) { + /* Perfect match weight 1.0. */ + weight = 1.0f; + + /* Use color ramp color. */ + color1[3] = color_ramp[stop].alpha; + color1[2] = color_ramp[stop].blue; + color1[1] = color_ramp[stop].green; + color1[0] = color_ramp[stop].red; + + color2[3] = color2[2] = color2[1] = color2[0] = 0.0f; + } + else { + if(stop == 0) { + return VG_LITE_INVALID_ARGUMENT; + } + /* Compute weight. */ + weight = (color_ramp[stop].stop - gradient) + / (color_ramp[stop].stop - color_ramp[stop - 1].stop); + + /* Grab color ramp color of previous stop. */ + color1[3] = color_ramp[stop - 1].alpha; + color1[2] = color_ramp[stop - 1].blue; + color1[1] = color_ramp[stop - 1].green; + color1[0] = color_ramp[stop - 1].red; + + /* Grab color ramp color of current stop. */ + color2[3] = color_ramp[stop].alpha; + color2[2] = color_ramp[stop].blue; + color2[1] = color_ramp[stop].green; + color2[0] = color_ramp[stop].red; + } + + if(grad->pre_multiplied) { + /* Pre-multiply the first color. */ + color1[2] *= color1[3]; + color1[1] *= color1[3]; + color1[0] *= color1[3]; + + /* Pre-multiply the second color. */ + color2[2] *= color2[3]; + color2[1] *= color2[3]; + color2[0] *= color2[3]; + } + + /* Filter the colors per channel. */ + color[3] = LERP(color1[3], color2[3], weight); + color[2] = LERP(color1[2], color2[2], weight); + color[1] = LERP(color1[1], color2[1], weight); + color[0] = LERP(color1[0], color2[0], weight); + + /* Pack the final color. */ + *bits++ = PackColorComponent(color[3]); + *bits++ = PackColorComponent(color[2]); + *bits++ = PackColorComponent(color[1]); + *bits++ = PackColorComponent(color[0]); + } + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_set_radial_grad(vg_lite_radial_gradient_t * grad, + vg_lite_uint32_t count, + vg_lite_color_ramp_t * color_ramp, + vg_lite_radial_gradient_parameter_t radial_grad, + vg_lite_gradient_spreadmode_t spread_mode, + vg_lite_uint8_t pre_multiplied) + { + static vg_lite_color_ramp_t defaultRamp[] = { + { + 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f + }, + { + 1.0f, + 1.0f, 1.0f, 1.0f, 1.0f + } + }; + + uint32_t i, trgCount; + vg_lite_float_t prevStop; + vg_lite_color_ramp_t * srcRamp; + vg_lite_color_ramp_t * srcRampLast; + vg_lite_color_ramp_t * trgRamp; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_set_radial_grad %p %d %p (%f %f %f %f %f) %d %d\n", grad, count, color_ramp, + radial_grad.cx, radial_grad.cy, radial_grad.fx, radial_grad.fy, radial_grad.r, spread_mode, pre_multiplied); +#endif + + /* Reset the count. */ + trgCount = 0; + + if(radial_grad.r <= 0) + return VG_LITE_INVALID_ARGUMENT; + + grad->radial_grad = radial_grad; + grad->pre_multiplied = pre_multiplied; + grad->spread_mode = spread_mode; + + if(!count || count > VLC_MAX_COLOR_RAMP_STOPS || color_ramp == NULL) + goto Empty_sequence_handler; + + for(i = 0; i < count; i++) + grad->color_ramp[i] = color_ramp[i]; + grad->ramp_length = count; + + /* Determine the last source ramp. */ + srcRampLast + = grad->color_ramp + + grad->ramp_length; + + /* Set the initial previous stop. */ + prevStop = -1; + + /* Reset the count. */ + trgCount = 0; + + /* Walk through the source ramp. */ + for( + srcRamp = grad->color_ramp, trgRamp = grad->converted_ramp; + (srcRamp < srcRampLast) && (trgCount < VLC_MAX_COLOR_RAMP_STOPS + 2); + srcRamp += 1) { + /* Must be in increasing order. */ + if(srcRamp->stop < prevStop) { + /* Ignore the entire sequence. */ + trgCount = 0; + break; + } + + /* Update the previous stop value. */ + prevStop = srcRamp->stop; + + /* Must be within [0..1] range. */ + if((srcRamp->stop < 0.0f) || (srcRamp->stop > 1.0f)) { + /* Ignore. */ + continue; + } + + /* Clamp color. */ + ClampColor(COLOR_FROM_RAMP(srcRamp), COLOR_FROM_RAMP(trgRamp), 0); + + /* First stop greater then zero? */ + if((trgCount == 0) && (srcRamp->stop > 0.0f)) { + /* Force the first stop to 0.0f. */ + trgRamp->stop = 0.0f; + + /* Replicate the entry. */ + trgRamp[1] = *trgRamp; + trgRamp[1].stop = srcRamp->stop; + + /* Advance. */ + trgRamp += 2; + trgCount += 2; + } + else { + /* Set the stop value. */ + trgRamp->stop = srcRamp->stop; + + /* Advance. */ + trgRamp += 1; + trgCount += 1; + } + } + + /* Empty sequence? */ + if(trgCount == 0) { + memcpy(grad->converted_ramp, defaultRamp, sizeof(defaultRamp)); + grad->converted_length = sizeof(defaultRamp) / 5; + } + else { + /* The last stop must be at 1.0. */ + if(trgRamp[-1].stop != 1.0f) { + /* Replicate the last entry. */ + *trgRamp = trgRamp[-1]; + + /* Force the last stop to 1.0f. */ + trgRamp->stop = 1.0f; + + /* Update the final entry count. */ + trgCount += 1; + } + + /* Set new length. */ + grad->converted_length = trgCount; + } + return VG_LITE_SUCCESS; + +Empty_sequence_handler: + memcpy(grad->converted_ramp, defaultRamp, sizeof(defaultRamp)); + grad->converted_length = sizeof(defaultRamp) / 5; + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_update_radial_grad(vg_lite_radial_gradient_t * grad) + { + uint32_t ramp_length; + vg_lite_color_ramp_t * colorRamp; + uint32_t common, stop; + uint32_t i, width; + uint8_t * bits; + vg_lite_error_t error = VG_LITE_SUCCESS; + uint32_t align, mul, div; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_update_radial_grad %p\n", grad); +#endif + + /* Get shortcuts to the color ramp. */ + ramp_length = grad->converted_length; + colorRamp = grad->converted_ramp; + + if(grad->radial_grad.r <= 0) + return VG_LITE_INVALID_ARGUMENT; + + /* Find the common denominator of the color ramp stops. */ + if(grad->radial_grad.r < 1) { + common = 1; + } + else { + common = (uint32_t)grad->radial_grad.r; + } + + for(i = 0; i < ramp_length; ++i) { + if(colorRamp[i].stop != 0.0f) { + vg_lite_float_t m = common * colorRamp[i].stop; + vg_lite_float_t frac = m - (vg_lite_float_t)floor(m); + if(frac > 0.00013f) { /* Suppose error for zero is 0.00013 */ + common = MAX(common, (uint32_t)(1.0f / frac + 0.5f)); + } + } + } + + /* Compute the width of the required color array. */ + width = common + 1; + width = (width + 15) & (~0xf); + + /* Allocate the color ramp surface. */ + memset(&grad->image, 0, sizeof(grad->image)); + grad->image.width = width; + grad->image.height = 1; + grad->image.stride = 0; + grad->image.image_mode = VG_LITE_NONE_IMAGE_MODE; + grad->image.format = VG_LITE_ABGR8888; + + /* Allocate the image for gradient. */ + VG_LITE_RETURN_ERROR(vg_lite_allocate(&grad->image)); + + get_format_bytes(VG_LITE_ABGR8888, &mul, &div, &align); + width = grad->image.stride * div / mul; + + /* Set pointer to color array. */ + bits = (uint8_t *)grad->image.memory; + + /* Start filling the color array. */ + stop = 0; + for(i = 0; i < width; ++i) { + vg_lite_float_t gradient; + vg_lite_float_t color[4]; + vg_lite_float_t color1[4]; + vg_lite_float_t color2[4]; + vg_lite_float_t weight; + + /* Compute gradient for current color array entry. */ + gradient = (vg_lite_float_t)i / (vg_lite_float_t)(width - 1); + + /* Find the entry in the color ramp that matches or exceeds this + ** gradient. */ + while(gradient > colorRamp[stop].stop) { + ++stop; + } + + if(gradient == colorRamp[stop].stop) { + /* Perfect match weight 1.0. */ + weight = 1.0f; + + /* Use color ramp color. */ + color1[3] = colorRamp[stop].alpha; + color1[2] = colorRamp[stop].blue; + color1[1] = colorRamp[stop].green; + color1[0] = colorRamp[stop].red; + + color2[3] = color2[2] = color2[1] = color2[0] = 0.0f; + } + else { + /* Compute weight. */ + weight = (colorRamp[stop].stop - gradient) + / (colorRamp[stop].stop - colorRamp[stop - 1].stop); + + /* Grab color ramp color of previous stop. */ + color1[3] = colorRamp[stop - 1].alpha; + color1[2] = colorRamp[stop - 1].blue; + color1[1] = colorRamp[stop - 1].green; + color1[0] = colorRamp[stop - 1].red; + + /* Grab color ramp color of current stop. */ + color2[3] = colorRamp[stop].alpha; + color2[2] = colorRamp[stop].blue; + color2[1] = colorRamp[stop].green; + color2[0] = colorRamp[stop].red; + } + + if(grad->pre_multiplied) { + /* Pre-multiply the first color. */ + color1[2] *= color1[3]; + color1[1] *= color1[3]; + color1[0] *= color1[3]; + + /* Pre-multiply the second color. */ + color2[2] *= color2[3]; + color2[1] *= color2[3]; + color2[0] *= color2[3]; + } + + /* Filter the colors per channel. */ + color[3] = LERP(color1[3], color2[3], weight); + color[2] = LERP(color1[2], color2[2], weight); + color[1] = LERP(color1[1], color2[1], weight); + color[0] = LERP(color1[0], color2[0], weight); + + /* Pack the final color. */ + *bits++ = PackColorComponent(color[3]); + *bits++ = PackColorComponent(color[2]); + *bits++ = PackColorComponent(color[1]); + *bits++ = PackColorComponent(color[0]); + } + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_set_grad(vg_lite_linear_gradient_t * grad, + vg_lite_uint32_t count, + vg_lite_uint32_t * colors, + vg_lite_uint32_t * stops) + { + uint32_t i; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_set_grad %p %d %p %p\n", grad, count, colors, stops); +#endif + + grad->count = 0; /* Opaque B&W gradient */ + if(!count || count > VLC_MAX_GRADIENT_STOPS || colors == NULL || stops == NULL) + return VG_LITE_SUCCESS; + + /* Check stops validity */ + for(i = 0; i < count; i++) + if(stops[i] < VLC_GRADIENT_BUFFER_WIDTH) { + if(!grad->count || stops[i] > grad->stops[grad->count - 1]) { + grad->stops[grad->count] = stops[i]; + grad->colors[grad->count] = colors[i]; + grad->count++; + } + else if(stops[i] == grad->stops[grad->count - 1]) { + /* Equal stops : use the color corresponding to the last stop + in the sequence */ + grad->colors[grad->count - 1] = colors[i]; + } + } + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_update_grad(vg_lite_linear_gradient_t * grad) + { + vg_lite_error_t error = VG_LITE_SUCCESS; + int32_t r0, g0, b0, a0; + int32_t r1, g1, b1, a1; + int32_t lr, lg, lb, la; + uint32_t i; + int32_t j; + int32_t ds, dr, dg, db, da; + uint32_t * buffer = (uint32_t *)grad->image.memory; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_update_grad %p\n", grad); +#endif + + if(grad->count == 0) { + /* If no valid stops have been specified (e.g., due to an empty input + * array, out-of-range, or out-of-order stops), a stop at 0 with color + * 0xFF000000 (opaque black) and a stop at 255 with color 0xFFFFFFFF + * (opaque white) are implicitly defined. */ + grad->stops[0] = 0; + grad->colors[0] = 0xFF000000; /* Opaque black */ + grad->stops[1] = 255; + grad->colors[1] = 0xFFFFFFFF; /* Opaque white */ + grad->count = 2; + } + else if(grad->count && grad->stops[0] != 0) { + /* If at least one valid stop has been specified, but none has been + * defined with an offset of 0, an implicit stop is added with an + * offset of 0 and the same color as the first user-defined stop. */ + for(i = 0; i < grad->stops[0]; i++) + buffer[i] = grad->colors[0]; + } + a0 = A(grad->colors[0]); + r0 = R(grad->colors[0]); + g0 = G(grad->colors[0]); + b0 = B(grad->colors[0]); + + /* Calculate the colors for each pixel of the image. */ + for(i = 0; i < grad->count - 1; i++) { + buffer[grad->stops[i]] = grad->colors[i]; + ds = grad->stops[i + 1] - grad->stops[i]; + a1 = A(grad->colors[i + 1]); + r1 = R(grad->colors[i + 1]); + g1 = G(grad->colors[i + 1]); + b1 = B(grad->colors[i + 1]); + + da = a1 - a0; + dr = r1 - r0; + dg = g1 - g0; + db = b1 - b0; + + for(j = 1; j < ds; j++) { + la = a0 + da * j / ds; + lr = r0 + dr * j / ds; + lg = g0 + dg * j / ds; + lb = b0 + db * j / ds; + + buffer[grad->stops[i] + j] = ARGB(la, lr, lg, lb); + } + + a0 = a1; + r0 = r1; + g0 = g1; + b0 = b1; + } + + /* If at least one valid stop has been specified, but none has been defined + * with an offset of 255, an implicit stop is added with an offset of 255 + * and the same color as the last user-defined stop. */ + for(i = grad->stops[grad->count - 1]; i < VLC_GRADIENT_BUFFER_WIDTH; i++) + buffer[i] = grad->colors[grad->count - 1]; + + return error; + } + + vg_lite_error_t vg_lite_clear_linear_grad(vg_lite_ext_linear_gradient_t * grad) + { + vg_lite_error_t error = VG_LITE_SUCCESS; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_clear_linear_grad %p\n", grad); +#endif + + grad->count = 0; + /* Release the image resource. */ + if(grad->image.handle != NULL) { + error = vg_lite_free(&grad->image); + } + + return error; + } + + vg_lite_error_t vg_lite_clear_grad(vg_lite_linear_gradient_t * grad) + { + vg_lite_error_t error = VG_LITE_SUCCESS; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_clear_grad %p\n", grad); +#endif + + grad->count = 0; + /* Release the image resource. */ + if(grad->image.handle != NULL) { + error = vg_lite_free(&grad->image); + } + + return error; + } + + vg_lite_error_t vg_lite_clear_radial_grad(vg_lite_radial_gradient_t * grad) + { + vg_lite_error_t error = VG_LITE_SUCCESS; + +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_clear_radial_grad %p\n", grad); +#endif + + grad->count = 0; + /* Release the image resource. */ + if(grad->image.handle != NULL) { + error = vg_lite_free(&grad->image); + } + + return error; + } + + vg_lite_matrix_t * vg_lite_get_linear_grad_matrix(vg_lite_ext_linear_gradient_t * grad) + { +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_get_linear_grad_matrix %p\n", grad); +#endif + + return &grad->matrix; + } + + vg_lite_matrix_t * vg_lite_get_grad_matrix(vg_lite_linear_gradient_t * grad) + { +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_get_grad_matrix %p\n", grad); +#endif + + return &grad->matrix; + } + + vg_lite_matrix_t * vg_lite_get_radial_grad_matrix(vg_lite_radial_gradient_t * grad) + { +#ifdef LV_VG_LITE_THORVG_TRACE_API + VGLITE_LOG("vg_lite_get_radial_grad_matrix %p\n", grad); +#endif + + return &grad->matrix; + } + + vg_lite_error_t vg_lite_draw_grad(vg_lite_buffer_t * target, + vg_lite_path_t * path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t * matrix, + vg_lite_linear_gradient_t * grad, + vg_lite_blend_t blend) + { + auto ctx = vg_lite_ctx::get_instance(); + TVG_CHECK_RETURN_VG_ERROR(canvas_set_target(ctx, target)); + + auto shape = Shape::gen(); + TVG_CHECK_RETURN_VG_ERROR(shape_append_path(shape, path, matrix)); + TVG_CHECK_RETURN_VG_ERROR(shape->transform(matrix_conv(matrix))); + TVG_CHECK_RETURN_VG_ERROR(shape->fill(fill_rule_conv(fill_rule));); + TVG_CHECK_RETURN_VG_ERROR(shape->blend(blend_method_conv(blend))); + + float x_min = path->bounding_box[0]; + float y_min = path->bounding_box[1]; + float x_max = path->bounding_box[2]; + float y_max = path->bounding_box[3]; + + auto linearGrad = LinearGradient::gen(); + + if(matrix->m[0][1] != 0) { + /* vertical */ + linearGrad->linear(x_min, y_min, x_min, y_max); + } + else { + /* horizontal */ + linearGrad->linear(x_min, y_min, x_max, y_min); + } + + linearGrad->transform(matrix_conv(&grad->matrix)); + linearGrad->spread(FillSpread::Reflect); + + tvg::Fill::ColorStop colorStops[VLC_MAX_GRADIENT_STOPS]; + for(vg_lite_uint32_t i = 0; i < grad->count; i++) { + colorStops[i].offset = grad->stops[i] / 255.0f; + colorStops[i].r = R(grad->colors[i]); + colorStops[i].g = G(grad->colors[i]); + colorStops[i].b = B(grad->colors[i]); + colorStops[i].a = A(grad->colors[i]); + } + TVG_CHECK_RETURN_VG_ERROR(linearGrad->colorStops(colorStops, grad->count)); + + TVG_CHECK_RETURN_VG_ERROR(shape->fill(std::move(linearGrad))); + TVG_CHECK_RETURN_VG_ERROR(ctx->canvas->push(std::move(shape))); + + return VG_LITE_SUCCESS; + } + + vg_lite_error_t vg_lite_draw_radial_grad(vg_lite_buffer_t * target, + vg_lite_path_t * path, + vg_lite_fill_t fill_rule, + vg_lite_matrix_t * path_matrix, + vg_lite_radial_gradient_t * grad, + vg_lite_color_t paint_color, + vg_lite_blend_t blend, + vg_lite_filter_t filter) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_command_buffer_size(uint32_t size) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_scissor(int32_t x, int32_t y, int32_t right, int32_t bottom) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_enable_scissor(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_disable_scissor(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_get_mem_size(uint32_t * size) + { + *size = 0; + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_source_global_alpha(vg_lite_global_alpha_t alpha_mode, uint8_t alpha_value) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_dest_global_alpha(vg_lite_global_alpha_t alpha_mode, uint8_t alpha_value) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_color_key(vg_lite_color_key4_t colorkey) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_flexa_stream_id(uint8_t stream_id) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_flexa_current_background_buffer(uint8_t stream_id, + vg_lite_buffer_t * buffer, + uint32_t background_segment_count, + uint32_t background_segment_size) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_enable_flexa(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_disable_flexa(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_flexa_stop_frame(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_enable_dither(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_disable_dither(void) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_tess_buffer(uint32_t physical, uint32_t size) + { + return VG_LITE_NOT_SUPPORT; + } + + vg_lite_error_t vg_lite_set_command_buffer(uint32_t physical, uint32_t size) + { + return VG_LITE_NOT_SUPPORT; + } +} /* extern "C" */ + +/********************** + * STATIC FUNCTIONS + **********************/ + +static vg_lite_error_t vg_lite_error_conv(Result result) +{ + switch(result) { + case Result::Success: + return VG_LITE_SUCCESS; + + case Result::InvalidArguments: + return VG_LITE_INVALID_ARGUMENT; + + case Result::InsufficientCondition: + return VG_LITE_OUT_OF_RESOURCES; + + case Result::FailedAllocation: + return VG_LITE_OUT_OF_MEMORY; + + case Result::NonSupport: + return VG_LITE_NOT_SUPPORT; + + default: + break; + } + + return VG_LITE_TIMEOUT; +} + +static Matrix matrix_conv(const vg_lite_matrix_t * matrix) +{ + return *(Matrix *)matrix; +} + +static FillRule fill_rule_conv(vg_lite_fill_t fill) +{ + if(fill == VG_LITE_FILL_EVEN_ODD) { + return FillRule::EvenOdd; + } + + return FillRule::Winding; +} + +static BlendMethod blend_method_conv(vg_lite_blend_t blend) +{ + switch(blend) { + case VG_LITE_BLEND_NONE: + return BlendMethod::SrcOver; + + case VG_LITE_BLEND_NORMAL_LVGL: + return BlendMethod::Normal; + + case VG_LITE_BLEND_SRC_OVER: + return BlendMethod::Normal; + + case VG_LITE_BLEND_SCREEN: + return BlendMethod::Screen; + + case VG_LITE_BLEND_ADDITIVE: + return BlendMethod::Add; + + case VG_LITE_BLEND_MULTIPLY: + return BlendMethod::Multiply; + + default: + break; + } + + return BlendMethod::Normal; +} + +static float vlc_get_arg(const void * data, vg_lite_format_t format) +{ + switch(format) { + case VG_LITE_S8: + return *((int8_t *)data); + + case VG_LITE_S16: + return *((int16_t *)data); + + case VG_LITE_S32: + return *((int32_t *)data); + + case VG_LITE_FP32: + return *((float *)data); + + default: + TVG_LOG("UNKNOW_FORMAT: %d\n", format); + break; + } + + return 0; +} + +static uint8_t vlc_format_len(vg_lite_format_t format) +{ + switch(format) { + case VG_LITE_S8: + return 1; + case VG_LITE_S16: + return 2; + case VG_LITE_S32: + return 4; + case VG_LITE_FP32: + return 4; + default: + TVG_LOG("UNKNOW_FORMAT: %d\n", format); + LV_ASSERT(false); + break; + } + + return 0; +} + +static uint8_t vlc_op_arg_len(uint8_t vlc_op) +{ + switch(vlc_op) { + VLC_OP_ARG_LEN(END, 0); + VLC_OP_ARG_LEN(CLOSE, 0); + VLC_OP_ARG_LEN(MOVE, 2); + VLC_OP_ARG_LEN(MOVE_REL, 2); + VLC_OP_ARG_LEN(LINE, 2); + VLC_OP_ARG_LEN(LINE_REL, 2); + VLC_OP_ARG_LEN(QUAD, 4); + VLC_OP_ARG_LEN(QUAD_REL, 4); + VLC_OP_ARG_LEN(CUBIC, 6); + VLC_OP_ARG_LEN(CUBIC_REL, 6); + VLC_OP_ARG_LEN(SCCWARC, 5); + VLC_OP_ARG_LEN(SCCWARC_REL, 5); + VLC_OP_ARG_LEN(SCWARC, 5); + VLC_OP_ARG_LEN(SCWARC_REL, 5); + VLC_OP_ARG_LEN(LCCWARC, 5); + VLC_OP_ARG_LEN(LCCWARC_REL, 5); + VLC_OP_ARG_LEN(LCWARC, 5); + VLC_OP_ARG_LEN(LCWARC_REL, 5); + default: + TVG_LOG("UNKNOW_VLC_OP: 0x%x", vlc_op); + LV_ASSERT(false); + break; + } + + return 0; +} + +static Result shape_append_path(std::unique_ptr & shape, vg_lite_path_t * path, vg_lite_matrix_t * matrix) +{ + uint8_t fmt_len = vlc_format_len(path->format); + uint8_t * cur = (uint8_t *)path->path; + uint8_t * end = cur + path->path_length; + + while(cur < end) { + /* get op code */ + uint8_t op_code = VLC_GET_OP_CODE(cur); + + /* get arguments length */ + uint8_t arg_len = vlc_op_arg_len(op_code); + + /* skip op code */ + cur += fmt_len; + + switch(op_code) { + case VLC_OP_MOVE: { + float x = VLC_GET_ARG(cur, 0); + float y = VLC_GET_ARG(cur, 1); + TVG_CHECK_RETURN_RESULT(shape->moveTo(x, y)); + } + break; + + case VLC_OP_LINE: { + float x = VLC_GET_ARG(cur, 0); + float y = VLC_GET_ARG(cur, 1); + TVG_CHECK_RETURN_RESULT(shape->lineTo(x, y)); + } + break; + + case VLC_OP_QUAD: { + /* hack pre point */ + float qcx0 = VLC_GET_ARG(cur, -3); + float qcy0 = VLC_GET_ARG(cur, -2); + float qcx1 = VLC_GET_ARG(cur, 0); + float qcy1 = VLC_GET_ARG(cur, 1); + float x = VLC_GET_ARG(cur, 2); + float y = VLC_GET_ARG(cur, 3); + + qcx0 += (qcx1 - qcx0) * 2 / 3; + qcy0 += (qcy1 - qcy0) * 2 / 3; + qcx1 = x + (qcx1 - x) * 2 / 3; + qcy1 = y + (qcy1 - y) * 2 / 3; + + TVG_CHECK_RETURN_RESULT(shape->cubicTo(qcx0, qcy0, qcx1, qcy1, x, y)); + } + break; + + case VLC_OP_CUBIC: { + float cx1 = VLC_GET_ARG(cur, 0); + float cy1 = VLC_GET_ARG(cur, 1); + float cx2 = VLC_GET_ARG(cur, 2); + float cy2 = VLC_GET_ARG(cur, 3); + float x = VLC_GET_ARG(cur, 4); + float y = VLC_GET_ARG(cur, 5); + TVG_CHECK_RETURN_RESULT(shape->cubicTo(cx1, cy1, cx2, cy2, x, y)); + } + break; + + case VLC_OP_CLOSE: + case VLC_OP_END: { + TVG_CHECK_RETURN_RESULT(shape->close()); + } + break; + + default: + break; + } + + cur += arg_len * fmt_len; + } + + float x_min = path->bounding_box[0]; + float y_min = path->bounding_box[1]; + float x_max = path->bounding_box[2]; + float y_max = path->bounding_box[3]; + + if(math_equal(x_min, __FLT_MIN__) && math_equal(y_min, __FLT_MIN__) + && math_equal(x_max, __FLT_MAX__) && math_equal(y_max, __FLT_MAX__)) { + return Result::Success; + } + + auto cilp = Shape::gen(); + TVG_CHECK_RETURN_RESULT(cilp->appendRect(x_min, y_min, x_max - x_min, y_max - y_min, 0, 0)); + TVG_CHECK_RETURN_RESULT(cilp->transform(matrix_conv(matrix))); + TVG_CHECK_RETURN_RESULT(shape->composite(std::move(cilp), CompositeMethod::ClipPath)); + + return Result::Success; +} + +static Result shape_append_rect(std::unique_ptr & shape, const vg_lite_buffer_t * target, + const vg_lite_rectangle_t * rect) +{ + if(rect) { + TVG_CHECK_RETURN_RESULT(shape->appendRect(rect->x, rect->y, rect->width, rect->height, 0, 0)); + } + else if(target) { + TVG_CHECK_RETURN_RESULT(shape->appendRect(0, 0, target->width, target->height, 0, 0)); + } + else { + return Result::InvalidArguments; + } + + return Result::Success; +} + +static Result canvas_set_target(vg_lite_ctx * ctx, vg_lite_buffer_t * target) +{ + uint32_t * target_buffer = nullptr; + + /* if target_buffer needs to be changed, finish current drawing */ + if(ctx->target_buffer && ctx->target_buffer != target->memory) { + vg_lite_finish(); + } + + ctx->target_format = target->format; + + if(TVG_IS_VG_FMT_SUPPORT(target->format)) { + /* if target format is supported by VG, use target buffer directly */ + target_buffer = (uint32_t *)target->memory; + ctx->target_buffer = nullptr; + ctx->target_px_size = 0; + } + else { + /* if target format is not supported by VG, use internal buffer */ + target_buffer = ctx->get_temp_target_buffer(target->width, target->height); + ctx->target_buffer = target->memory; + ctx->target_px_size = target->width * target->height; + } + + Result res = ctx->canvas->target( + target_buffer, + target->width, + target->width, + target->height, + SwCanvas::ARGB8888); + + return res; +} + +static uint32_t width_to_stride(uint32_t w, vg_lite_buffer_format_t color_format) +{ + if(vg_lite_query_feature(gcFEATURE_BIT_VG_16PIXELS_ALIGN)) { + w = VG_LITE_ALIGN(w, 16); + } + + uint32_t mul, div, align; + get_format_bytes(color_format, &mul, &div, &align); + return VG_LITE_ALIGN((w * mul / div), align); +} + +static bool decode_indexed_line( + vg_lite_buffer_format_t color_format, + const uint32_t * palette, + int32_t x, int32_t y, + int32_t w_px, const uint8_t * in, uint32_t * out) +{ + uint8_t px_size; + uint16_t mask; + + uint32_t w_byte = width_to_stride(w_px, color_format); + + in += w_byte * y; /*First pixel*/ + out += w_px * y; + + int8_t shift = 0; + switch(color_format) { + case VG_LITE_INDEX_1: + px_size = 1; + in += x / 8; /*8pixel per byte*/ + shift = 7 - (x & 0x7); + break; + case VG_LITE_INDEX_2: + px_size = 2; + in += x / 4; /*4pixel per byte*/ + shift = 6 - 2 * (x & 0x3); + break; + case VG_LITE_INDEX_4: + px_size = 4; + in += x / 2; /*2pixel per byte*/ + shift = 4 - 4 * (x & 0x1); + break; + case VG_LITE_INDEX_8: + px_size = 8; + in += x; + shift = 0; + break; + default: + LV_ASSERT(false); + return false; + } + + mask = (1 << px_size) - 1; /*E.g. px_size = 2; mask = 0x03*/ + + int32_t i; + for(i = 0; i < w_px; i++) { + uint8_t val_act = (*in >> shift) & mask; + out[i] = palette[val_act]; + + shift -= px_size; + if(shift < 0) { + shift = 8 - px_size; + in++; + } + } + return true; +} + +static Result picture_load(vg_lite_ctx * ctx, std::unique_ptr & picture, const vg_lite_buffer_t * source, + vg_lite_color_t color) +{ + uint32_t * image_buffer; + LV_ASSERT(VG_LITE_IS_ALIGNED(source->memory, LV_VG_LITE_THORVG_BUF_ADDR_ALIGN)); + +#ifdef LV_VG_LITE_THORVG_16PIXELS_ALIGN + LV_ASSERT(VG_LITE_IS_ALIGNED(source->width, 16)); +#endif + + if(source->format == VG_LITE_BGRA8888 && source->image_mode == VG_LITE_NORMAL_IMAGE_MODE) { + image_buffer = (uint32_t *)source->memory; + } + else { + uint32_t width = source->width; + uint32_t height = source->height; + uint32_t px_size = width * height; + image_buffer = ctx->get_image_buffer(width, height); + + vg_lite_buffer_t target; + memset(&target, 0, sizeof(target)); + target.memory = image_buffer; + target.format = VG_LITE_BGRA8888; + target.width = width; + target.height = height; + target.stride = width_to_stride(width, target.format); + + switch(source->format) { + case VG_LITE_INDEX_1: + case VG_LITE_INDEX_2: + case VG_LITE_INDEX_4: + case VG_LITE_INDEX_8: { + const uint32_t * clut_colors = ctx->get_CLUT(source->format); + for(uint32_t y = 0; y < height; y++) { + decode_indexed_line(source->format, clut_colors, 0, y, width, (uint8_t *)source->memory, image_buffer); + } + } + break; + + case VG_LITE_A4: { + conv_alpha4_to_bgra8888.convert(&target, source, color); + } + break; + + case VG_LITE_A8: { + conv_alpha8_to_bgra8888.convert(&target, source, color); + } + break; + + case VG_LITE_BGRX8888: { + conv_bgrx8888_to_bgra8888.convert(&target, source); + } + break; + + case VG_LITE_BGR888: { + conv_bgr888_to_bgra8888.convert(&target, source); + } + break; + + case VG_LITE_BGRA5658: { + conv_bgra5658_to_bgra8888.convert(&target, source); + } + break; + + case VG_LITE_BGR565: { + conv_bgr565_to_bgra8888.convert(&target, source); + } + break; + +#ifdef LV_VG_LITE_THORVG_YUV_SUPPORT + case VG_LITE_NV12: { + libyuv::NV12ToARGB((const uint8_t *)source->memory, source->stride, (const uint8_t *)source->yuv.uv_memory, + source->yuv.uv_stride, + (uint8_t *)image_buffer, source->width * sizeof(uint32_t), width, height); + } + break; +#endif + + case VG_LITE_BGRA8888: { + memcpy(image_buffer, source->memory, px_size * sizeof(vg_color32_t)); + } + break; + + default: + TVG_LOG("unsupport format: %d\n", source->format); + LV_ASSERT(false); + break; + } + + /* multiply color */ + if(source->image_mode == VG_LITE_MULTIPLY_IMAGE_MODE && !VG_LITE_IS_ALPHA_FORMAT(source->format)) { + vg_color32_t * dest = (vg_color32_t *)image_buffer; + while(px_size--) { + dest->alpha = UDIV255(dest->alpha * A(color)); + dest->red = UDIV255(dest->red * B(color)); + dest->green = UDIV255(dest->green * G(color)); + dest->blue = UDIV255(dest->blue * R(color)); + dest++; + } + } + } + + TVG_CHECK_RETURN_RESULT(picture->load(image_buffer, source->width, source->height, true)); + + return Result::Success; +} + +static void ClampColor(FLOATVECTOR4 Source, FLOATVECTOR4 Target, uint8_t Premultiplied) +{ + vg_lite_float_t colorMax; + /* Clamp the alpha channel. */ + Target[3] = CLAMP(Source[3], 0.0f, 1.0f); + + /* Determine the maximum value for the color channels. */ + colorMax = Premultiplied ? Target[3] : 1.0f; + + /* Clamp the color channels. */ + Target[0] = CLAMP(Source[0], 0.0f, colorMax); + Target[1] = CLAMP(Source[1], 0.0f, colorMax); + Target[2] = CLAMP(Source[2], 0.0f, colorMax); +} + +static uint8_t PackColorComponent(vg_lite_float_t value) +{ + /* Compute the rounded normalized value. */ + vg_lite_float_t rounded = value * 255.0f + 0.5f; + + /* Get the integer part. */ + int32_t roundedInt = (int32_t)rounded; + + /* Clamp to 0..1 range. */ + uint8_t clamped = (uint8_t)CLAMP(roundedInt, 0, 255); + + /* Return result. */ + return clamped; +} + +/* Get the bpp information of a color format. */ +static void get_format_bytes(vg_lite_buffer_format_t format, + uint32_t * mul, + uint32_t * div, + uint32_t * bytes_align) +{ + *mul = *div = 1; + *bytes_align = 4; + switch(format) { + case VG_LITE_L8: + case VG_LITE_A8: + case VG_LITE_RGBA8888_ETC2_EAC: + break; + + case VG_LITE_A4: + *div = 2; + break; + + case VG_LITE_ABGR1555: + case VG_LITE_ARGB1555: + case VG_LITE_BGRA5551: + case VG_LITE_RGBA5551: + case VG_LITE_RGBA4444: + case VG_LITE_BGRA4444: + case VG_LITE_ABGR4444: + case VG_LITE_ARGB4444: + case VG_LITE_RGB565: + case VG_LITE_BGR565: + case VG_LITE_YUYV: + case VG_LITE_YUY2: + case VG_LITE_YUY2_TILED: + /* AYUY2 buffer memory = YUY2 + alpha. */ + case VG_LITE_AYUY2: + case VG_LITE_AYUY2_TILED: + /* ABGR8565_PLANAR buffer memory = RGB565 + alpha. */ + case VG_LITE_ABGR8565_PLANAR: + case VG_LITE_ARGB8565_PLANAR: + case VG_LITE_RGBA5658_PLANAR: + case VG_LITE_BGRA5658_PLANAR: + *mul = 2; + break; + + case VG_LITE_RGBA8888: + case VG_LITE_BGRA8888: + case VG_LITE_ABGR8888: + case VG_LITE_ARGB8888: + case VG_LITE_RGBX8888: + case VG_LITE_BGRX8888: + case VG_LITE_XBGR8888: + case VG_LITE_XRGB8888: + *mul = 4; + break; + + case VG_LITE_NV12: + case VG_LITE_NV12_TILED: + *mul = 3; + break; + + case VG_LITE_ANV12: + case VG_LITE_ANV12_TILED: + *mul = 4; + break; + + case VG_LITE_INDEX_1: + *div = 8; + *bytes_align = 8; + break; + + case VG_LITE_INDEX_2: + *div = 4; + *bytes_align = 8; + break; + + case VG_LITE_INDEX_4: + *div = 2; + *bytes_align = 8; + break; + + case VG_LITE_INDEX_8: + *bytes_align = 1; + break; + + case VG_LITE_RGBA2222: + case VG_LITE_BGRA2222: + case VG_LITE_ABGR2222: + case VG_LITE_ARGB2222: + *mul = 1; + break; + + case VG_LITE_RGB888: + case VG_LITE_BGR888: + case VG_LITE_ABGR8565: + case VG_LITE_BGRA5658: + case VG_LITE_ARGB8565: + case VG_LITE_RGBA5658: + *mul = 3; + break; + + /* OpenVG format*/ + case VG_sRGBX_8888: + case VG_sRGBA_8888: + case VG_sRGBA_8888_PRE: + case VG_lRGBX_8888: + case VG_lRGBA_8888: + case VG_lRGBA_8888_PRE: + case VG_sXRGB_8888: + case VG_sARGB_8888: + case VG_sARGB_8888_PRE: + case VG_lXRGB_8888: + case VG_lARGB_8888: + case VG_lARGB_8888_PRE: + case VG_sBGRX_8888: + case VG_sBGRA_8888: + case VG_sBGRA_8888_PRE: + case VG_lBGRX_8888: + case VG_lBGRA_8888: + case VG_sXBGR_8888: + case VG_sABGR_8888: + case VG_lBGRA_8888_PRE: + case VG_sABGR_8888_PRE: + case VG_lXBGR_8888: + case VG_lABGR_8888: + case VG_lABGR_8888_PRE: + *mul = 4; + break; + + case VG_sRGBA_5551: + case VG_sRGBA_4444: + case VG_sARGB_1555: + case VG_sARGB_4444: + case VG_sBGRA_5551: + case VG_sBGRA_4444: + case VG_sABGR_1555: + case VG_sABGR_4444: + case VG_sRGB_565: + case VG_sBGR_565: + *mul = 2; + break; + + case VG_sL_8: + case VG_lL_8: + case VG_A_8: + break; + + case VG_BW_1: + case VG_A_4: + case VG_A_1: + *div = 2; + break; + + default: + break; + } +} +#endif