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 * @kit ArkGraphics2D 37 * @library libnative_drawing.so 38 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 39 * @since 11 40 * @version 1.0 41 */ 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 OH_Drawing_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, const float* pos, uint32_t size, OH_Drawing_TileMode); 104 105 /** 106 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a linear gradient between the two specified points. 107 * 108 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 109 * @param startPt Indicates the start point for the gradient. 110 * @param endPt Indicates the end point for the gradient. 111 * @param colors Indicates the colors to be distributed between the two points. 112 * @param pos Indicates the relative position of each corresponding color in the colors array. 113 * If pos is nullptr, the colors are evenly distributed between the start and end point. 114 * @param size Indicates the number of colors and pos(if pos is not nullptr). 115 * @param OH_Drawing_TileMode Indicates the tile mode. 116 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 117 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 118 If matrix is nullptr, defaults to the identity matrix. 119 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 120 * If nullptr is returned, the creation fails. 121 * The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr. 122 * @since 12 123 * @version 1.0 124 */ 125 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateLinearGradientWithLocalMatrix( 126 const OH_Drawing_Point2D* startPt, const OH_Drawing_Point2D* endPt, const uint32_t* colors, const float* pos, 127 uint32_t size, OH_Drawing_TileMode, const OH_Drawing_Matrix*); 128 129 /** 130 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius. 131 * 132 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 133 * @param centerPt Indicates the center of the circle for the gradient. 134 * @param radius Indicates the radius of the circle for this gradient. 135 * @param colors Indicates the colors to be distributed between the two points. 136 * @param pos Indicates the relative position of each corresponding color in the colors array. 137 * @param size Indicates the number of colors and pos. 138 * @param OH_Drawing_TileMode Indicates the tile mode. 139 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 140 * @since 11 141 * @version 1.0 142 */ 143 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradient(const OH_Drawing_Point* centerPt, float radius, 144 const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); 145 146 /** 147 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a radial gradient given the center and radius. 148 * 149 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 150 * @param centerPt Indicates the center of the circle for the gradient. 151 * @param radius Indicates the radius of the circle for this gradient. 152 * @param colors Indicates the colors to be distributed between the two points. 153 * @param pos Indicates the relative position of each corresponding color in the colors array. 154 * @param size Indicates the number of colors and pos. 155 * @param OH_Drawing_TileMode Indicates the tile mode. 156 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 157 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 158 If matrix is nullptr, defaults to the identity matrix. 159 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 160 * If nullptr is returned, the creation fails. 161 * The possible cause of the failure is any of centerPt, colors and pos is nullptr. 162 * @since 12 163 * @version 1.0 164 */ 165 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateRadialGradientWithLocalMatrix( 166 const OH_Drawing_Point2D* centerPt, float radius, const uint32_t* colors, const float* pos, uint32_t size, 167 OH_Drawing_TileMode, const OH_Drawing_Matrix*); 168 169 /** 170 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a sweep gradient given a center. 171 * 172 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 173 * @param centerPt Indicates the center of the circle for the gradient. 174 * @param colors Indicates the colors to be distributed between the two points. 175 * @param pos Indicates the relative position of each corresponding color in the colors array. 176 * @param size Indicates the number of colors and pos. 177 * @param OH_Drawing_TileMode Indicates the tile mode. 178 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 179 * @since 11 180 * @version 1.0 181 */ 182 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateSweepGradient(const OH_Drawing_Point* centerPt, 183 const uint32_t* colors, const float* pos, uint32_t size, OH_Drawing_TileMode); 184 185 /** 186 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a image shader. 187 * 188 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 189 * @param OH_Drawing_Image Indicates the pointer to an <b>OH_Drawing_Image</b> object. 190 * @param tileX Indicates the tileX. 191 * @param tileY Indicates the tileY. 192 * @param OH_Drawing_SamplingOptions Indicates the pointer to an <b>OH_Drawing_SamplingOptions</b> object. 193 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object. 194 * If matrix is nullptr, defaults to the identity matrix. 195 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 196 * @since 12 197 * @version 1.0 198 */ 199 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateImageShader(OH_Drawing_Image*, 200 OH_Drawing_TileMode tileX, OH_Drawing_TileMode tileY, const OH_Drawing_SamplingOptions*, const OH_Drawing_Matrix*); 201 202 /** 203 * @brief Creates an <b>OH_Drawing_ShaderEffect</b> that generates a conical gradient given two circles. 204 * 205 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 206 * @param startPt Indicates the center of the start circle for the gradient. 207 * @param startRadius Indicates the radius of the start circle for this gradient. 208 * @param endPt Indicates the center of the start circle for the gradient. 209 * @param endRadius Indicates the radius of the start circle for this gradient. 210 * @param colors Indicates the colors to be distributed between the two points. 211 * @param pos Indicates the relative position of each corresponding color in the colors array. 212 * @param size Indicates the number of colors and pos. 213 * @param OH_Drawing_TileMode Indicates the tile mode. 214 * @param OH_Drawing_Matrix Indicates the pointer to an <b>OH_Drawing_Matrix</b> object, 215 which represents the local matrix of the created <b>OH_Drawing_ShaderEffect</b> object. 216 If matrix is nullptr, defaults to the identity matrix. 217 * @return Returns the pointer to the <b>OH_Drawing_ShaderEffect</b> object created. 218 * If nullptr is returned, the creation fails. 219 * The possible cause of the failure is any of startPt, endPt, colors and pos is nullptr. 220 * @since 12 221 * @version 1.0 222 */ 223 OH_Drawing_ShaderEffect* OH_Drawing_ShaderEffectCreateTwoPointConicalGradient(const OH_Drawing_Point2D* startPt, 224 float startRadius, const OH_Drawing_Point2D* endPt, float endRadius, const uint32_t* colors, const float* pos, 225 uint32_t size, OH_Drawing_TileMode, const OH_Drawing_Matrix*); 226 227 /** 228 * @brief Destroys an <b>OH_Drawing_ShaderEffect</b> object and reclaims the memory occupied by the object. 229 * 230 * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing 231 * @param OH_Drawing_ShaderEffect Indicates the pointer to an <b>OH_Drawing_ShaderEffect</b> object. 232 * @since 11 233 * @version 1.0 234 */ 235 void OH_Drawing_ShaderEffectDestroy(OH_Drawing_ShaderEffect*); 236 237 #ifdef __cplusplus 238 } 239 #endif 240 /** @} */ 241 #endif 242