1 /* TSI 2023.xmo */
2 /*******************************************************************************
3 * Copyright (c) 2023 Think Silicon Single Member PC
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this header file and/or associated documentation files to use, copy,
7 * modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 * Materials, and to permit persons to whom the Materials are furnished to do
9 * so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Materials.
13 *
14 * MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS
15 * NEMAGFX API. THE UNMODIFIED, NORMATIVE VERSIONS OF THINK-SILICON NEMAGFX
16 * SPECIFICATIONS AND HEADER INFORMATION ARE LOCATED AT:
17 * https://think-silicon.com/products/software/nemagfx-api
18 *
19 * The software is provided 'as is', without warranty of any kind, express or
20 * implied, including but not limited to the warranties of merchantability,
21 * fitness for a particular purpose and noninfringement. In no event shall
22 * Think Silicon Single Member PC be liable for any claim, damages or other
23 * liability, whether in an action of contract, tort or otherwise, arising
24 * from, out of or in connection with the software or the use or other dealings
25 * in the software.
26 ******************************************************************************/
27
28
29 #ifndef NEMA_BLENDER_H__
30 #define NEMA_BLENDER_H__
31
32 #include "nema_sys_defs.h"
33 #include "nema_graphics.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 // Blending Factor Selector
40 //-----------------------------------------------------------------------------------------------------------------------
41 #define NEMA_BF_ZERO (0x0U) /**< 0 */
42 #define NEMA_BF_ONE (0x1U) /**< 1 */
43 #define NEMA_BF_SRCCOLOR (0x2U) /**< Sc */
44 #define NEMA_BF_INVSRCCOLOR (0x3U) /**< (1-Sc) */
45 #define NEMA_BF_SRCALPHA (0x4U) /**< Sa */
46 #define NEMA_BF_INVSRCALPHA (0x5U) /**< (1-Sa) */
47 #define NEMA_BF_DESTALPHA (0x6U) /**< Da */
48 #define NEMA_BF_INVDESTALPHA (0x7U) /**< (1-Da) */
49 #define NEMA_BF_DESTCOLOR (0x8U) /**< Dc */
50 #define NEMA_BF_INVDESTCOLOR (0x9U) /**< (1-Dc) */
51 #define NEMA_BF_CONSTCOLOR (0xaU) /**< Cc */
52 #define NEMA_BF_CONSTALPHA (0xbU) /**< Ca */
53
54 /* source factor destination factor */
55 #define NEMA_BL_SIMPLE ( (uint32_t)NEMA_BF_SRCALPHA | ((uint32_t)NEMA_BF_INVSRCALPHA <<8) ) /**< Sa * Sa + Da * (1 - Sa) */
56 #define NEMA_BL_CLEAR ( (uint32_t)NEMA_BF_ZERO /*| ((uint32_t)NEMA_BF_ZERO <<8)*/) /**< 0 */
57 #define NEMA_BL_SRC ( (uint32_t)NEMA_BF_ONE /*| ((uint32_t)NEMA_BF_ZERO <<8)*/) /**< Sa */
58 #define NEMA_BL_SRC_OVER ( (uint32_t)NEMA_BF_ONE | ((uint32_t)NEMA_BF_INVSRCALPHA <<8) ) /**< Sa + Da * (1 - Sa) */
59 #define NEMA_BL_DST_OVER ( (uint32_t)NEMA_BF_INVDESTALPHA | ((uint32_t)NEMA_BF_ONE <<8) ) /**< Sa * (1 - Da) + Da */
60 #define NEMA_BL_SRC_IN ( (uint32_t)NEMA_BF_DESTALPHA /*| ((uint32_t)NEMA_BF_ZERO <<8)*/) /**< Sa * Da */
61 #define NEMA_BL_DST_IN (/*(uint32_t)NEMA_BF_ZERO |*/ ((uint32_t)NEMA_BF_SRCALPHA <<8) ) /**< Da * Sa */
62 #define NEMA_BL_SRC_OUT ( (uint32_t)NEMA_BF_INVDESTALPHA/*| ((uint32_t)NEMA_BF_ZERO <<8)*/ ) /**< Sa * (1 - Da) */
63 #define NEMA_BL_DST_OUT (/*(uint32_t)NEMA_BF_ZERO |*/ ((uint32_t)NEMA_BF_INVSRCALPHA <<8) ) /**< Da * (1 - Sa) */
64 #define NEMA_BL_SRC_ATOP ( (uint32_t)NEMA_BF_DESTALPHA | ((uint32_t)NEMA_BF_INVSRCALPHA <<8) ) /**< Sa * Da + Da * (1 - Sa) */
65 #define NEMA_BL_DST_ATOP ( (uint32_t)NEMA_BF_INVDESTALPHA | ((uint32_t)NEMA_BF_SRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * Sa */
66 #define NEMA_BL_ADD ( (uint32_t)NEMA_BF_ONE | ((uint32_t)NEMA_BF_ONE <<8) ) /**< Sa + Da */
67 #define NEMA_BL_XOR ( (uint32_t)NEMA_BF_INVDESTALPHA | ((uint32_t)NEMA_BF_INVSRCALPHA <<8) ) /**< Sa * (1 - Da) + Da * (1 - Sa) */
68
69
70 #define NEMA_BLOP_NONE (0U) /**< No extra blending operation */
71 #define NEMA_BLOP_RECOLOR (0x00100000U) /**< Cconst*Aconst + Csrc*(1-Aconst). Overrides MODULATE_RGB. On NemaP GPU, recolor is available only when HW Rop Blender is enabled */
72 #define NEMA_BLOP_LUT (0x00200000U) /**< src_tex as index, src2_tex as palette */
73 #define NEMA_BLOP_STENCIL_XY (0x00400000U) /**< Use TEX3 as mask */
74 #define NEMA_BLOP_STENCIL_TXTY (0x00800000U) /**< Use TEX3 as mask */
75 #define NEMA_BLOP_NO_USE_ROPBL (0x01000000U) /**< Don't use Rop Blender even if present */
76 #define NEMA_BLOP_DST_CKEY_NEG (0x02000000U) /**< Apply Inverse Destination Color Keying - draw only when dst color doesn't match colorkey*/
77 #define NEMA_BLOP_SRC_PREMULT (0x04000000U) /**< Premultiply Source Color with Source Alpha (cannot be used with NEMA_BLOP_MODULATE_RGB) */
78 #define NEMA_BLOP_MODULATE_A (0x08000000U) /**< Modulate by Constant Alpha value*/
79 #define NEMA_BLOP_FORCE_A (0x10000000U) /**< Force Constant Alpha value */
80 #define NEMA_BLOP_MODULATE_RGB (0x20000000U) /**< Modulate by Constant Color (RGB) values */
81 #define NEMA_BLOP_SRC_CKEY (0x40000000U) /**< Apply Source Color Keying - draw only when src color doesn't match colorkey */
82 #define NEMA_BLOP_DST_CKEY (0x80000000U) /**< Apply Destination Color Keying - draw only when dst color matches colorkey */
83 #define NEMA_BLOP_MASK (0xfff00000U)
84
85 /** \brief Return blending mode given source and destination blending factors and additional blending operations
86 *
87 * \param src Source Blending Factor
88 * \param dst Destination Blending Factor
89 * \param ops Additional Blending Operations
90 * \return Final Blending Mode
91 *
92 */
nema_blending_mode(uint32_t src_bf,uint32_t dst_bf,uint32_t blops)93 static inline uint32_t nema_blending_mode(uint32_t src_bf, uint32_t dst_bf, uint32_t blops) {
94 return ( (src_bf) | (dst_bf << 8) | (blops&NEMA_BLOP_MASK) );
95 }
96
97 /** \brief Set blending mode
98 *
99 * \param blending_mode Blending mode to be set
100 * \param dst_tex Destination Texture
101 * \param fg_tex Foreground (source) Texture
102 * \param bg_tex Background (source2) Texture
103 *
104 */
105 void nema_set_blend(uint32_t blending_mode, nema_tex_t dst_tex, nema_tex_t fg_tex, nema_tex_t bg_tex);
106
107 /** \brief Set blending mode for filling
108 *
109 * \param blending_mode Blending mode to be set
110 *
111 */
nema_set_blend_fill(uint32_t blending_mode)112 static inline void nema_set_blend_fill(uint32_t blending_mode) {
113 nema_set_blend(blending_mode, NEMA_TEX0, NEMA_NOTEX, NEMA_NOTEX);
114 }
115
116 /** \brief Set blending mode for filling with composing
117 *
118 * \param blending_mode Blending mode to be set
119 *
120 */
nema_set_blend_fill_compose(uint32_t blending_mode)121 static inline void nema_set_blend_fill_compose(uint32_t blending_mode) {
122 nema_set_blend(blending_mode, NEMA_TEX0, NEMA_NOTEX, NEMA_TEX2);
123 }
124
125 /** \brief Set blending mode for blitting
126 *
127 * \param blending_mode Blending mode to be set
128 *
129 */
nema_set_blend_blit(uint32_t blending_mode)130 static inline void nema_set_blend_blit(uint32_t blending_mode) {
131 nema_set_blend(blending_mode, NEMA_TEX0, NEMA_TEX1, NEMA_NOTEX);
132 }
133
134 /** \brief Set blending mode for blitting with composing
135 *
136 * \param blending_mode Blending mode to be set
137 *
138 */
nema_set_blend_blit_compose(uint32_t blending_mode)139 static inline void nema_set_blend_blit_compose(uint32_t blending_mode) {
140 nema_set_blend(blending_mode, NEMA_TEX0, NEMA_TEX1, NEMA_TEX2);
141 }
142
143 /** \brief Set constant color
144 *
145 * \param rgba RGBA color
146 * \see nema_rgba()
147 *
148 */
149 void nema_set_const_color(uint32_t rgba);
150
151
152 /** \brief Set recolor color. Overrides constant color
153 *
154 * \param rgba RGBA color
155 * \see nema_rgba(), nema_set_const_color()
156 *
157 */
158 void nema_set_recolor_color(uint32_t rgba);
159
160 /** \brief Set source color key
161 *
162 * \param rgba RGBA color key
163 * \see nema_rgba()
164 *
165 */
166 void nema_set_src_color_key(uint32_t rgba);
167
168 /** \brief Set destination color key
169 *
170 * \param rgba RGBA color key
171 * \see nema_rgba()
172 *
173 */
174 void nema_set_dst_color_key(uint32_t rgba);
175
176
177 /** \brief Enable/disable ovedraw debugging. Disables gradient and texture, forces blending mode to NEMA_BL_ADD
178 *
179 * \param enable Enables overdraw debugging if non-zero
180 *
181 */
182 void nema_debug_overdraws(uint32_t enable);
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif // NEMA_BLENDER_H__
189