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