hal_gfx_blender.h
Go to the documentation of this file.
1 
2 /** @addtogroup GRAPHICS_SDK Graphics
3  * @{
4  */
5 
6 /** @defgroup HAL_GFX_BLENDER Hal gfx blender
7  * @brief GPU blender interfaces.
8  * @{
9  */
10 
11 #ifndef HAL_GFX_BLENDER_H__
12 #define HAL_GFX_BLENDER_H__
13 
14 #include "hal_gfx_sys_defs.h"
15 #include "hal_gfx_graphics.h"
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 /**
21  * @defgroup HAL_GFX_BLENDER_MACRO Defines
22  * @{
23  */
24 // Blending Factor Selector
25 //-----------------------------------------------------------------------------------------------------------------------
26 #define HAL_GFX_BF_ZERO (0x0U) /**< 0 */
27 #define HAL_GFX_BF_ONE (0x1U) /**< 1 */
28 #define HAL_GFX_BF_SRCCOLOR (0x2U) /**< Sc */
29 #define HAL_GFX_BF_INVSRCCOLOR (0x3U) /**< (1-Sc) */
30 #define HAL_GFX_BF_SRCALPHA (0x4U) /**< Sa */
31 #define HAL_GFX_BF_INVSRCALPHA (0x5U) /**< (1-Sa) */
32 #define HAL_GFX_BF_DESTALPHA (0x6U) /**< Da */
33 #define HAL_GFX_BF_INVDESTALPHA (0x7U) /**< (1-Da) */
34 #define HAL_GFX_BF_DESTCOLOR (0x8U) /**< Dc */
35 #define HAL_GFX_BF_INVDESTCOLOR (0x9U) /**< (1-Dc) */
36 #define HAL_GFX_BF_CONSTCOLOR (0xaU) /**< Cc */
37 #define HAL_GFX_BF_CONSTALPHA (0xbU) /**< Ca */
38 
39 /* source factor destination factor */
40 #define HAL_GFX_BL_SIMPLE ( (uint32_t)HAL_GFX_BF_SRCALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * Sa + Da * (1 - Sa) */
41 #define HAL_GFX_BL_CLEAR ( (uint32_t)HAL_GFX_BF_ZERO /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< 0 */
42 #define HAL_GFX_BL_SRC ( (uint32_t)HAL_GFX_BF_ONE /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< Sa */
43 #define HAL_GFX_BL_SRC_OVER ( (uint32_t)HAL_GFX_BF_ONE | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa + Da * (1 - Sa) */
44 #define HAL_GFX_BL_DST_OVER ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_ONE <<8) ) /**< Sa * (1 - Da) + Da */
45 #define HAL_GFX_BL_SRC_IN ( (uint32_t)HAL_GFX_BF_DESTALPHA /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< Sa * Da */
46 #define HAL_GFX_BL_DST_IN (/*(uint32_t)HAL_GFX_BF_ZERO |*/ ((uint32_t)HAL_GFX_BF_SRCALPHA <<8) ) /**< Da * Sa */
47 #define HAL_GFX_BL_SRC_OUT ( (uint32_t)HAL_GFX_BF_INVDESTALPHA/*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/ ) /**< Sa * (1 - Da) */
48 #define HAL_GFX_BL_DST_OUT (/*(uint32_t)HAL_GFX_BF_ZERO |*/ ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Da * (1 - Sa) */
49 #define HAL_GFX_BL_SRC_ATOP ( (uint32_t)HAL_GFX_BF_DESTALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * Da + Da * (1 - Sa) */
50 #define HAL_GFX_BL_DST_ATOP ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_SRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * Sa */
51 #define HAL_GFX_BL_ADD ( (uint32_t)HAL_GFX_BF_ONE | ((uint32_t)HAL_GFX_BF_ONE <<8) ) /**< Sa + Da */
52 #define HAL_GFX_BL_XOR ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * (1 - Sa) */
53 
54 
55 #define HAL_GFX_BLOP_NONE (0U) /**< No extra blending operation */
56 #define HAL_GFX_BLOP_STENCIL_TXTY (0x00800000U) /**< Use TEX3 as mask */
57 #define HAL_GFX_BLOP_STENCIL_XY (0x00400000U) /**< Use TEX3 as mask */
58 #define HAL_GFX_BLOP_NO_USE_ROPBL (0x01000000U) /**< Don't use Rop Blender even if present */
59 #define HAL_GFX_BLOP_DST_CKEY_NEG (0x02000000U) /**< Apply Inverse Destination Color Keying - draw only when dst color doesn't match colorkey*/
60 #define HAL_GFX_BLOP_SRC_PREMULT (0x04000000U) /**< Premultiply Source Color with Source Alpha (cannot be used with HAL_GFX_BLOP_MODULATE_RGB) */
61 #define HAL_GFX_BLOP_MODULATE_A (0x08000000U) /**< Modulate by Constant Alpha value*/
62 #define HAL_GFX_BLOP_FORCE_A (0x10000000U) /**< Force Constant Alpha value */
63 #define HAL_GFX_BLOP_MODULATE_RGB (0x20000000U) /**< Modulate by Constant Color (RGB) values */
64 #define HAL_GFX_BLOP_SRC_CKEY (0x40000000U) /**< Apply Source Color Keying - draw only when src color doesn't match colorkey */
65 #define HAL_GFX_BLOP_DST_CKEY (0x80000000U) /**< Apply Destination Color Keying - draw only when dst color matches colorkey */
66 #define HAL_GFX_BLOP_MASK (0xffc00000U) /**< blending operation mask */
67 /** @} */
68 
69 /**
70  * @defgroup HAL_GFX_BLENDER_FUNCTION Functions
71  * @{
72  */
73 /**
74  *****************************************************************************************
75  * @brief Return blending mode given source and destination blending factors and additional blending operations
76  *
77  * @param[in] src: Source Blending Factor
78  * @param[in] dst: Destination Blending Factor
79  * @param[in] ops: Additional Blending Operations
80  *
81  * @return Final Blending Mode
82  *****************************************************************************************
83  */
84 static inline uint32_t hal_gfx_blending_mode(uint32_t src_bf, uint32_t dst_bf, uint32_t blops) {
85  return ( (src_bf) | (dst_bf << 8) | (blops&HAL_GFX_BLOP_MASK) );
86 }
87 
88 /**
89  *****************************************************************************************
90  * @brief Set blending mode
91  * @note Blit mode only supports foreground texture slot blending and foreground with background texture slot blending
92  *
93  * @param[in] blending_mode: Blending mode to be set
94  * @param[in] dst_tex: Destination Texture
95  * @param[in] fg_tex: Foreground (source) Texture
96  * @param[in] bg_tex: Background (source2) Texture
97  *
98  *****************************************************************************************
99  */
100 void hal_gfx_set_blend(uint32_t blending_mode, hal_gfx_tex_t dst_tex, hal_gfx_tex_t fg_tex, hal_gfx_tex_t bg_tex);
101 
102 /**
103  *****************************************************************************************
104  * @brief Set blending mode for filling
105  *
106  * @param[in] blending_mode: Blending mode to be set
107  *
108  *****************************************************************************************
109  */
110 static inline void hal_gfx_set_blend_fill(uint32_t blending_mode) {
112 }
113 
114 /**
115  *****************************************************************************************
116  * @brief Set blending mode for filling with composing
117  *
118  * @param[in] blending_mode: Blending mode to be set
119  *
120  *****************************************************************************************
121  */
122 static inline void hal_gfx_set_blend_fill_compose(uint32_t blending_mode) {
124 }
125 
126 /**
127  *****************************************************************************************
128  * @brief Set blending mode for blitting
129  *
130  * @param[in] blending_mode: Blending mode to be set
131  *
132  *****************************************************************************************
133  */
134 static inline void hal_gfx_set_blend_blit(uint32_t blending_mode) {
136 }
137 
138 /**
139  *****************************************************************************************
140  * @brief Set blending mode for blitting with composing
141  *
142  * @param[in] blending_mode: Blending mode to be set
143  *
144  *****************************************************************************************
145  */
146 static inline void hal_gfx_set_blend_blit_compose(uint32_t blending_mode) {
148 }
149 
150 /**
151  *****************************************************************************************
152  * @brief Set constant color
153  *
154  * @param[in] rgba: RGBA color (format: R[0,7] G[8,15] B[16,23] A[24,31])
155  *
156  *****************************************************************************************
157  */
158 void hal_gfx_set_const_color(uint32_t rgba);
159 
160 /**
161  *****************************************************************************************
162  * @brief Set source color key
163  *
164  * @param[in] rgba: RGBA color key (format: R[0,7] G[8,15] B[16,23] A[24,31])
165  *
166  *****************************************************************************************
167  */
168 void hal_gfx_set_src_color_key(uint32_t rgba);
169 
170 /**
171  *****************************************************************************************
172  * @brief Set destination color key
173  *
174  * @param[in] rgba: RGBA color key (format: R[0,7] G[8,15] B[16,23] A[24,31])
175  *
176  *****************************************************************************************
177  */
178 void hal_gfx_set_dst_color_key(uint32_t rgba);
179 
180 /**
181  *****************************************************************************************
182  * @brief Enable/disable ovedraw debugging. Disables gradient and texture, forces blending mode to HAL_GFX_BL_ADD
183  *
184  * @param[in] enable: Enables overdraw debugging if non-zero
185  *
186  *****************************************************************************************
187  */
188 void hal_gfx_debug_overdraws(uint32_t enable);
189 /** @} */
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif // HAL_GFX_BLENDER_H__
196 
197 /** @} */
198 /** @} */
199 
hal_gfx_debug_overdraws
void hal_gfx_debug_overdraws(uint32_t enable)
Enable/disable ovedraw debugging. Disables gradient and texture, forces blending mode to HAL_GFX_BL_A...
hal_gfx_set_blend_blit_compose
static void hal_gfx_set_blend_blit_compose(uint32_t blending_mode)
Set blending mode for blitting with composing.
Definition: hal_gfx_blender.h:146
HAL_GFX_TEX1
@ HAL_GFX_TEX1
Definition: hal_gfx_graphics.h:32
hal_gfx_sys_defs.h
hal_gfx_graphics.h
HAL_GFX_TEX2
@ HAL_GFX_TEX2
Definition: hal_gfx_graphics.h:33
hal_gfx_set_dst_color_key
void hal_gfx_set_dst_color_key(uint32_t rgba)
Set destination color key.
HAL_GFX_TEX0
@ HAL_GFX_TEX0
Definition: hal_gfx_graphics.h:31
hal_gfx_blending_mode
static uint32_t hal_gfx_blending_mode(uint32_t src_bf, uint32_t dst_bf, uint32_t blops)
Return blending mode given source and destination blending factors and additional blending operations...
Definition: hal_gfx_blender.h:84
hal_gfx_set_blend_blit
static void hal_gfx_set_blend_blit(uint32_t blending_mode)
Set blending mode for blitting.
Definition: hal_gfx_blender.h:134
HAL_GFX_BLOP_MASK
#define HAL_GFX_BLOP_MASK
Definition: hal_gfx_blender.h:66
HAL_GFX_NOTEX
@ HAL_GFX_NOTEX
Definition: hal_gfx_graphics.h:30
hal_gfx_set_blend_fill_compose
static void hal_gfx_set_blend_fill_compose(uint32_t blending_mode)
Set blending mode for filling with composing.
Definition: hal_gfx_blender.h:122
hal_gfx_set_src_color_key
void hal_gfx_set_src_color_key(uint32_t rgba)
Set source color key.
hal_gfx_set_blend_fill
static void hal_gfx_set_blend_fill(uint32_t blending_mode)
Set blending mode for filling.
Definition: hal_gfx_blender.h:110
hal_gfx_set_blend
void hal_gfx_set_blend(uint32_t blending_mode, hal_gfx_tex_t dst_tex, hal_gfx_tex_t fg_tex, hal_gfx_tex_t bg_tex)
Set blending mode.
hal_gfx_set_const_color
void hal_gfx_set_const_color(uint32_t rgba)
Set constant color.
hal_gfx_tex_t
hal_gfx_tex_t
Graphics Texture.
Definition: hal_gfx_graphics.h:29