• 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  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
180  * @since 11
181  * @version 1.0
182  */
183 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradient(const OH_Drawing_Point* centerPt,
184     const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode tileMode);
185 
186 /**
187  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a image shader.
188  *
189  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
190  * @param image Indicates the pointer to an <b>OH_Drawing_Image</b> object.
191  * @param tileX Indicates the tileX.
192  * @param tileY Indicates the tileY.
193  * @param samplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object.
194  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object.
195  *                          If matrix is nullptr, defaults to the identity matrix.
196  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
197  * @since 12
198  * @version 1.0
199  */
200 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateImageShader(OH_Drawing_Image* image,
201     OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions* samplingOptions,
202     const OH_Drawing_Matrix* matrix);
203 
204 /**
205  * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a conical gradient given two circles.
206  *
207  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
208  * @param startPt Indicates the center of the start circle for the gradient.
209  * @param startRadius Indicates the radius of the start circle for this gradient.
210  * @param endPt Indicates the center of the start circle for the gradient.
211  * @param endRadius Indicates the radius of the start circle for this gradient.
212  * @param colors Indicates the colors to be distributed between the two points.
213  * @param pos Indicates the relative position of each corresponding color in the colors array.
214  * @param size Indicates the number of colors and pos.
215  * @param tileMode Indicates the tile mode.
216  * @param matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object,
217                             which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object.
218                             If matrix is nullptr, defaults to the identity matrix.
219  * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created.
220  *         If nullptr is returned, the creation fails.
221  *         The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr.
222  * @since 12
223  * @version 1.0
224  */
225 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(const OH_Drawing_Point2D* startPt,
226     float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos,
227     uint32_t size, OH_Drawing_TileMode tileMode, const OH_Drawing_Matrix* matrix);
228 
229 /**
230  * @brief Destroys an <b>OH_Drawing_ShaderEffect</b> object and reclaims the memory occupied by the object.
231  *
232  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
233  * @param shaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object.
234  * @since 11
235  * @version 1.0
236  */
237 void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect* shaderEffect);
238 
239 #ifdef __cplusplus
240 }
241 #endif
242 /** @} */
243 #endif
244