• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Drawing
18  * @{
19  *
20  * @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
21  *
22  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
23  *
24  * @since 11
25  * @version 1.0
26  */
27 
28 /**
29  * @file drawing_shader_effect.h
30  *
31  * @brief Declares functions related to the <b>shaderEffect</b> object in the drawing module.
32  *
33  * @kit ArkGraphics2D
34  * @library libnative_drawing.so
35  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
36  * @since 11
37  * @version 1.0
38  */
39 
40 #ifndef C_INCLUDE_DRAWING_SHADER_EFFECT_H
41 #define C_INCLUDE_DRAWING_SHADER_EFFECT_H
42 
43 #include "drawing_types.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Enumerates tile mode.
51  *
52  * @since 11
53  * @version 1.0
54  */
55 typedef enum {
56     /**
57      * Replicate the edge color if the shader effect draws outside of its original bounds.
58      */
59     CLAMP,
60     /**
61      * Repeat the shader effect image horizontally and vertically.
62      */
63     REPEAT,
64     /**
65      * Repeat the shader effect image horizontally and vertically, alternating mirror images
66      * so that adjacent images always seam.
67      */
68     MIRROR,
69     /**
70      * Only draw within the original domain, return transparent-black everywhere else.
71      */
72     DECAL,
73 } OH_Drawing_TileMode;
74 
75 /**
76  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a shader with single color.
77  *
78  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
79  * @param color Indicates the color used by the shader.
80  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
81  *         If nullptr is returned, the creation fails.
82  *         The possible cause of the failure is that the available memory is empty.
83  * @since 12
84  * @version 1.0
85  */
86 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateColorShader(const uint32_t color);
87 
88 /**
89  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a linear gradient between the two specified points.
90  *
91  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
92  * @param startPt Indicates the start point for the gradient.
93  * @param endPt Indicates the end point for the gradient.
94  * @param colors Indicates the colors to be distributed between the two points.
95  * @param pos Indicates the relative position of each corresponding color in the colors array.
96  * @param size Indicates the number of colors and pos.
97  * @param tileMode Indicates the tile mode.
98  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
99  * @since 11
100  * @version 1.0
101  */
102 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradient(const OH_Drawing_Point* startPt,
103     const OH_Drawing_Point* endPt, const uint32_t* colors,
104     const float* pos, uint32_t size, OH_Drawing_TileMode tileMode);
105 
106 /**
107  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a linear gradient between the two specified points.
108  *
109  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
110  * @param startPt Indicates the start point for the gradient.
111  * @param endPt Indicates the end point for the gradient.
112  * @param colors Indicates the colors to be distributed between the two points.
113  * @param pos Indicates the relative position of each corresponding color in the colors array.
114  *            If pos is nullptr, the colors are evenly distributed between the start and end point.
115  * @param size Indicates the number of colors and pos(if pos is not nullptr).
116  * @param tileMode Indicates the tile mode.
117  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
118                             which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object.
119                             If matrix is nullptr, defaults to the identity matrix.
120  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
121  *         If nullptr is returned, the creation fails.
122  *         The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr.
123  * @since 12
124  * @version 1.0
125  */
126 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix(
127     const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos,
128     uint32_t size, OH_Drawing_TileMode tileMode, const OH_Drawing_Matrix* matrix);
129 
130 /**
131  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius.
132  *
133  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
134  * @param centerPt Indicates the center of the circle for the gradient.
135  * @param radius Indicates the radius of the circle for this gradient.
136  * @param colors Indicates the colors to be distributed between the two points.
137  * @param pos Indicates the relative position of each corresponding color in the colors array.
138  * @param size Indicates the number of colors and pos.
139  * @param tileMode Indicates the tile mode.
140  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
141  * @since 11
142  * @version 1.0
143  */
144 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradient(const OH_Drawing_Point* centerPt, float radius,
145     const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode tileMode);
146 
147 /**
148  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius.
149  *
150  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
151  * @param centerPt Indicates the center of the circle for the gradient.
152  * @param radius Indicates the radius of the circle for this gradient.
153  * @param colors Indicates the colors to be distributed between the two points.
154  * @param pos Indicates the relative position of each corresponding color in the colors array.
155  * @param size Indicates the number of colors and pos.
156  * @param tileMode Indicates the tile mode.
157  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
158                             which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object.
159                             If matrix is nullptr, defaults to the identity matrix.
160  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
161  *         If nullptr is returned, the creation fails.
162  *         The possible cause of the failure is any of centerPt, colors and pos is nullptr.
163  * @since 12
164  * @version 1.0
165  */
166 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradientWithLocalMatrix(
167     const OH_Drawing_Point2D* centerPt, float radius, const uint32_t* colors, const float* pos, uint32_t size,
168     OH_Drawing_TileMode tileMode, const OH_Drawing_Matrix* matrix);
169 
170 /**
171  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a sweep gradient given a center.
172  *
173  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
174  * @param centerPt Indicates the center of the circle for the gradient.
175  * @param colors Indicates the colors to be distributed between the two points.
176  * @param pos Indicates the relative position of each corresponding color in the colors array.
177  * @param size Indicates the number of colors and pos.
178  * @param tileMode Indicates the tile mode.
179  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
180                             which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object.
181                             If matrix is nullptr, defaults to the identity matrix.
182  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
183  * @since 20
184  * @version 1.0
185  */
186 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradientWithLocalMatrix(
187     const OH_Drawing_Point* centerPt, const uint32_t* colors, const float* pos, uint32_t size,
188     OH_Drawing_TileMode tileMode, const OH_Drawing_Matrix* matrix);
189 
190 /**
191  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a sweep gradient given a center.
192  *
193  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
194  * @param centerPt Indicates the center of the circle for the gradient.
195  * @param colors Indicates the colors to be distributed between the two points.
196  * @param pos Indicates the relative position of each corresponding color in the colors array.
197  * @param size Indicates the number of colors and pos.
198  * @param tileMode Indicates the tile mode.
199  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
200  * @since 11
201  * @version 1.0
202  */
203 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradient(const OH_Drawing_Point* centerPt,
204     const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode tileMode);
205 
206 /**
207  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a image shader.
208  *
209  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
210  * @param image Indicates the pointer to an <b>OH_Drawing_Image</b> object.
211  * @param tileX Indicates the tileX.
212  * @param tileY Indicates the tileY.
213  * @param samplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object.
214  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
215  *                          If matrix is nullptr, defaults to the identity matrix.
216  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
217  * @since 12
218  * @version 1.0
219  */
220 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateImageShader(OH_Drawing_Image* image,
221     OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions* samplingOptions,
222     const OH_Drawing_Matrix* matrix);
223 
224 /**
225  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a pixel map shader.
226  *
227  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
228  * @param pixelMap Indicates the pointer to an <b>OH_Drawing_PixelMap</b> object.
229  * @param tileX Indicates the horizontal tile mode.
230  * @param tileY Indicates the vertical tile mode.
231  * @param samplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object. It cannot be null.
232  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
233  *                          If matrix is nullptr, defaults to the identity matrix.
234  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
235  * @since 20
236  * @version 1.0
237  */
238 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreatePixelMapShader(OH_Drawing_PixelMap* pixelMap,
239     OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions* samplingOptions,
240     const OH_Drawing_Matrix* matrix);
241 
242 /**
243  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a conical gradient given two circles.
244  *
245  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
246  * @param startPt Indicates the center of the start circle for the gradient.
247  * @param startRadius Indicates the radius of the start circle for this gradient.
248  * @param endPt Indicates the center of the start circle for the gradient.
249  * @param endRadius Indicates the radius of the start circle for this gradient.
250  * @param colors Indicates the colors to be distributed between the two points.
251  * @param pos Indicates the relative position of each corresponding color in the colors array.
252  * @param size Indicates the number of colors and pos.
253  * @param tileMode Indicates the tile mode.
254  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
255                             which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object.
256                             If matrix is nullptr, defaults to the identity matrix.
257  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
258  *         If nullptr is returned, the creation fails.
259  *         The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr.
260  * @since 12
261  * @version 1.0
262  */
263 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(const OH_Drawing_Point2D* startPt,
264     float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos,
265     uint32_t size, OH_Drawing_TileMode tileMode, const OH_Drawing_Matrix* matrix);
266 
267 /**
268  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates by two shaders.
269  *
270  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
271  * @param dst Indicates the destination ShaderEffect pointer.
272  * @param src Indicates the source ShaderEffect pointer.
273  * @param mode Indicates the blend mode.
274  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
275  *         If nullptr is returned, the creation fails.
276  *         The possible cause of the failure is that the available memory is empty or any of dst and src is nullptr.
277  * @since 20
278  * @version 1.0
279  */
280 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateCompose(OH_Drawing_ShaderEffect* dst,
281     OH_Drawing_ShaderEffect* src, OH_Drawing_BlendMode mode);
282 
283 /**
284  * @brief Destroys an <b>OH_Drawing_ShaderEffect</b> object and reclaims the memory occupied by the object.
285  *
286  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
287  * @param shaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object.
288  * @since 11
289  * @version 1.0
290  */
291 void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect* shaderEffect);
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 /** @} */
297 #endif
298