hal_gfx_blender.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_gfx_blender.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of Graphics library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup GRAPHICS_SDK Graphics
39  * @{
40  */
41 
42 /** @addtogroup HAL_GFX HAL GFX
43  * @{
44  */
45 
46 /** @defgroup HAL_GFX_BLENDER GFX BLENDER
47  * @brief GPU blender interfaces.
48  * @{
49  */
50 
51 #ifndef HAL_GFX_BLENDER_H__
52 #define HAL_GFX_BLENDER_H__
53 
54 #include "hal_gfx_sys_defs.h"
55 #include "hal_gfx_graphics.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 /**
61  * @defgroup HAL_GFX_BLENDER_MACRO Defines
62  * @{
63  */
64 // Blending Factor Selector
65 //-----------------------------------------------------------------------------------------------------------------------
66 #define HAL_GFX_BF_ZERO (0x0U) /**< 0 */
67 #define HAL_GFX_BF_ONE (0x1U) /**< 1 */
68 #define HAL_GFX_BF_SRCCOLOR (0x2U) /**< Sc */
69 #define HAL_GFX_BF_INVSRCCOLOR (0x3U) /**< (1-Sc) */
70 #define HAL_GFX_BF_SRCALPHA (0x4U) /**< Sa */
71 #define HAL_GFX_BF_INVSRCALPHA (0x5U) /**< (1-Sa) */
72 #define HAL_GFX_BF_DESTALPHA (0x6U) /**< Da */
73 #define HAL_GFX_BF_INVDESTALPHA (0x7U) /**< (1-Da) */
74 #define HAL_GFX_BF_DESTCOLOR (0x8U) /**< Dc */
75 #define HAL_GFX_BF_INVDESTCOLOR (0x9U) /**< (1-Dc) */
76 #define HAL_GFX_BF_CONSTCOLOR (0xaU) /**< Cc */
77 #define HAL_GFX_BF_CONSTALPHA (0xbU) /**< Ca */
78 
79 /* source factor destination factor */
80 #define HAL_GFX_BL_SIMPLE ( (uint32_t)HAL_GFX_BF_SRCALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * Sa + Da * (1 - Sa) */
81 #define HAL_GFX_BL_CLEAR ( (uint32_t)HAL_GFX_BF_ZERO /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< 0 */
82 #define HAL_GFX_BL_SRC ( (uint32_t)HAL_GFX_BF_ONE /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< Sa */
83 #define HAL_GFX_BL_SRC_OVER ( (uint32_t)HAL_GFX_BF_ONE | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa + Da * (1 - Sa) */
84 #define HAL_GFX_BL_DST_OVER ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_ONE <<8) ) /**< Sa * (1 - Da) + Da */
85 #define HAL_GFX_BL_SRC_IN ( (uint32_t)HAL_GFX_BF_DESTALPHA /*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/) /**< Sa * Da */
86 #define HAL_GFX_BL_DST_IN (/*(uint32_t)HAL_GFX_BF_ZERO |*/ ((uint32_t)HAL_GFX_BF_SRCALPHA <<8) ) /**< Da * Sa */
87 #define HAL_GFX_BL_SRC_OUT ( (uint32_t)HAL_GFX_BF_INVDESTALPHA/*| ((uint32_t)HAL_GFX_BF_ZERO <<8)*/ ) /**< Sa * (1 - Da) */
88 #define HAL_GFX_BL_DST_OUT (/*(uint32_t)HAL_GFX_BF_ZERO |*/ ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Da * (1 - Sa) */
89 #define HAL_GFX_BL_SRC_ATOP ( (uint32_t)HAL_GFX_BF_DESTALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * Da + Da * (1 - Sa) */
90 #define HAL_GFX_BL_DST_ATOP ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_SRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * Sa */
91 #define HAL_GFX_BL_ADD ( (uint32_t)HAL_GFX_BF_ONE | ((uint32_t)HAL_GFX_BF_ONE <<8) ) /**< Sa + Da */
92 #define HAL_GFX_BL_XOR ( (uint32_t)HAL_GFX_BF_INVDESTALPHA | ((uint32_t)HAL_GFX_BF_INVSRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * (1 - Sa) */
93 
94 
95 #define HAL_GFX_BLOP_NONE (0U) /**< No extra blending operation */
96 #define HAL_GFX_BLOP_STENCIL_TXTY (0x00800000U) /**< Use TEX3 as mask */
97 #define HAL_GFX_BLOP_STENCIL_XY (0x00400000U) /**< Use TEX3 as mask */
98 #define HAL_GFX_BLOP_NO_USE_ROPBL (0x01000000U) /**< Don't use Rop Blender even if present */
99 #define HAL_GFX_BLOP_DST_CKEY_NEG (0x02000000U) /**< Apply Inverse Destination Color Keying - draw only when dst color doesn't match colorkey*/
100 #define HAL_GFX_BLOP_SRC_PREMULT (0x04000000U) /**< Premultiply Source Color with Source Alpha (cannot be used with HAL_GFX_BLOP_MODULATE_RGB) */
101 #define HAL_GFX_BLOP_MODULATE_A (0x08000000U) /**< Modulate by Constant Alpha value*/
102 #define HAL_GFX_BLOP_FORCE_A (0x10000000U) /**< Force Constant Alpha value */
103 #define HAL_GFX_BLOP_MODULATE_RGB (0x20000000U) /**< Modulate by Constant Color (RGB) values */
104 #define HAL_GFX_BLOP_SRC_CKEY (0x40000000U) /**< Apply Source Color Keying - draw only when src color doesn't match colorkey */
105 #define HAL_GFX_BLOP_DST_CKEY (0x80000000U) /**< Apply Destination Color Keying - draw only when dst color matches colorkey */
106 #define HAL_GFX_BLOP_MASK (0xffc00000U) /**< blending operation mask */
107 /** @} */
108 
109 /**
110  * @defgroup HAL_GFX_BLENDER_FUNCTION Functions
111  * @{
112  */
113 /**
114  *****************************************************************************************
115  * @brief Return blending mode given source and destination blending factors and additional blending operations
116  *
117  * @param[in] src_bf: Source Blending Factor
118  * @param[in] dst_bf: Destination Blending Factor
119  * @param[in] blops: Additional Blending Operations
120  *
121  * @return Final Blending Mode
122  *****************************************************************************************
123  */
124 static inline uint32_t hal_gfx_blending_mode(uint32_t src_bf, uint32_t dst_bf, uint32_t blops) {
125  return ( (src_bf) | (dst_bf << 8) | (blops&HAL_GFX_BLOP_MASK) );
126 }
127 
128 /**
129  *****************************************************************************************
130  * @brief Set blending mode
131  * @note Blit mode only supports foreground texture slot blending and foreground with background texture slot blending
132  *
133  * @param[in] blending_mode: Blending mode to be set
134  * @param[in] dst_tex: Destination Texture
135  * @param[in] fg_tex: Foreground (source) Texture
136  * @param[in] bg_tex: Background (source2) Texture
137  *
138  *****************************************************************************************
139  */
140 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);
141 
142 /**
143  *****************************************************************************************
144  * @brief Set blending mode for filling
145  *
146  * @param[in] blending_mode: Blending mode to be set
147  *
148  *****************************************************************************************
149  */
150 static inline void hal_gfx_set_blend_fill(uint32_t blending_mode) {
152 }
153 
154 /**
155  *****************************************************************************************
156  * @brief Set blending mode for filling with composing
157  *
158  * @param[in] blending_mode: Blending mode to be set
159  *
160  *****************************************************************************************
161  */
162 static inline void hal_gfx_set_blend_fill_compose(uint32_t blending_mode) {
164 }
165 
166 /**
167  *****************************************************************************************
168  * @brief Set blending mode for blitting
169  *
170  * @param[in] blending_mode: Blending mode to be set
171  *
172  *****************************************************************************************
173  */
174 static inline void hal_gfx_set_blend_blit(uint32_t blending_mode) {
176 }
177 
178 /**
179  *****************************************************************************************
180  * @brief Set blending mode for blitting with composing
181  *
182  * @param[in] blending_mode: Blending mode to be set
183  *
184  *****************************************************************************************
185  */
186 static inline void hal_gfx_set_blend_blit_compose(uint32_t blending_mode) {
188 }
189 
190 /**
191  *****************************************************************************************
192  * @brief Set constant color
193  *
194  * @param[in] rgba: RGBA color (format: R[0,7] G[8,15] B[16,23] A[24,31])
195  *
196  *****************************************************************************************
197  */
198 void hal_gfx_set_const_color(uint32_t rgba);
199 
200 /**
201  *****************************************************************************************
202  * @brief Set source color key
203  *
204  * @param[in] rgba: RGBA color key (format: R[0,7] G[8,15] B[16,23] A[24,31])
205  *
206  *****************************************************************************************
207  */
208 void hal_gfx_set_src_color_key(uint32_t rgba);
209 
210 /**
211  *****************************************************************************************
212  * @brief Set destination color key
213  *
214  * @param[in] rgba: RGBA color key (format: R[0,7] G[8,15] B[16,23] A[24,31])
215  *
216  *****************************************************************************************
217  */
218 void hal_gfx_set_dst_color_key(uint32_t rgba);
219 
220 /**
221  *****************************************************************************************
222  * @brief Enable/disable ovedraw debugging. Disables gradient and texture, forces blending mode to HAL_GFX_BL_ADD
223  *
224  * @param[in] enable: Enables overdraw debugging if non-zero
225  *
226  *****************************************************************************************
227  */
228 void hal_gfx_debug_overdraws(uint32_t enable);
229 /** @} */
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif // HAL_GFX_BLENDER_H__
236 
237 /** @} */
238 /** @} */
239 /** @} */
240 
hal_gfx_debug_overdraws
void hal_gfx_debug_overdraws(uint32_t enable)
Enable/disable ovedraw debugging.
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:186
HAL_GFX_TEX1
@ HAL_GFX_TEX1
Texture 1.
Definition: hal_gfx_graphics.h:72
hal_gfx_sys_defs.h
hal_gfx_graphics.h
Header file containing functions prototypes of Graphics library.
HAL_GFX_TEX2
@ HAL_GFX_TEX2
Texture 2.
Definition: hal_gfx_graphics.h:73
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
Texture 0.
Definition: hal_gfx_graphics.h:71
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:124
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:174
HAL_GFX_BLOP_MASK
#define HAL_GFX_BLOP_MASK
blending operation mask
Definition: hal_gfx_blender.h:106
HAL_GFX_NOTEX
@ HAL_GFX_NOTEX
No Texture.
Definition: hal_gfx_graphics.h:70
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:162
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:150
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:69