1 /* 2 * Copyright (c) 2023 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 RECORDING_SHADER_EFFECT_H 17 #define RECORDING_SHADER_EFFECT_H 18 19 #include "effect/shader_effect.h" 20 #include "recording/shader_effect_cmd_list.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 class RecordingShaderEffect : public ShaderEffect { 26 public: 27 /* 28 * @brief Creates a CreateColorShaderOpItem to add to the ShaderEffectCmdList. 29 * @param color 32-bit ARGB color value. 30 */ 31 static std::shared_ptr<RecordingShaderEffect> CreateColorShader(ColorQuad color); 32 33 /* 34 * @brief Creates a CreateBlendShaderOpItem to add to the ShaderEffectCmdList. 35 * @param dst To Blend. 36 * @param src To Blend. 37 * @param mode The mode of Blend. 38 */ 39 static std::shared_ptr<RecordingShaderEffect> CreateBlendShader(const ShaderEffect& dst, 40 const ShaderEffect& src, BlendMode mode); 41 42 /* 43 * @brief Creates a CreateImageShaderOpItem to add to the ShaderEffectCmdList. 44 * @param image Dimensions are taken from Image. 45 * @param tileX Tiling in the x direction. 46 * @param tileY Tiling in the y direction. 47 * @param sampling Sampling Options. 48 * @param matrix Image transformation matrix. 49 */ 50 static std::shared_ptr<RecordingShaderEffect> CreateImageShader( 51 const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling, const Matrix& matrix); 52 53 /* 54 * @brief Creates a CreatePictureShaderOpItem to add to the ShaderEffectCmdList. 55 * @param picture Shader will draw with this picture. 56 * @param tileX Tiling in the x direction. 57 * @param tileY Tiling in the y direction. 58 * @param mode How to filter the tiles. 59 * @param matrix Used when sampling. 60 * @param rect The tile rectangle in picture coordinates. 61 */ 62 static std::shared_ptr<RecordingShaderEffect> CreatePictureShader(const Picture& picture, 63 TileMode tileX, TileMode tileY, FilterMode mode, const Matrix& matrix, const Rect& rect); 64 65 /* 66 * @brief Creates a CreateLinearGradientOpItem to add to the ShaderEffectCmdList. 67 * @param startPt The start point for the gradient. 68 * @param endPt The end point for the gradient. 69 * @param colors The vector of colors, to be distributed between the two points. 70 * @param pos The vector of scalar. If null, the colors are evenly distributed between the start and end point. 71 If not null, the values must be between 0.0 and 1.0. 72 * @param mode The mode of tiling. 73 */ 74 static std::shared_ptr<RecordingShaderEffect> CreateLinearGradient(const Point& startPt, const Point& endPt, 75 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode); 76 77 /* 78 * @brief Creates a CreateRadialGradientOpItem to add to the ShaderEffectCmdList. 79 * @param centerPt The center point of the circle for this gradient. 80 * @param radius Must be positive, the radius of the gradient circle. 81 * @param colors The vector of colors, to be distributed between the center and the edge of the circle. 82 * @param pos The vector of scalar. If NULL, the colors are evenly distributed between the center 83 and edges of the circle. If not NULL, the value must be between 0.0 and 1.0. 84 * @param mode The mode of tiling. 85 */ 86 static std::shared_ptr<RecordingShaderEffect> CreateRadialGradient(const Point& centerPt, scalar radius, 87 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode); 88 /* 89 * @brief Creates a CreateTwoPointConicalOpItem to add to the ShaderEffectCmdList. 90 * @param startPt The center point for the start circle. 91 * @param startRadius The radius for the start circle. 92 * @param endPt The center point for the end circle. 93 * @param endRadius The radius for the end circle. 94 * @param colors The vector of colors, to be distributed between the start and end circle. 95 * @param pos The vector of scalar. If NULL, the colors are evenly distributed between the start and end 96 circle. If not NULL, the value must be between 0.0 and 1.0. 97 * @param mode The mode of tiling. 98 * @return 99 */ 100 static std::shared_ptr<RecordingShaderEffect> CreateTwoPointConical(const Point& startPt, scalar startRadius, 101 const Point& endPt, scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, 102 TileMode mode); 103 /* 104 * @brief Creates a CreateSweepGradientOpItem to add to the ShaderEffectCmdList. 105 * @param centerPt The center point for the sweep. 106 * @param colors The vector of colors, to be distributed around the center point. 107 * @param pos The vector of scalar. If NULL, the colors are evenly distributed between the start 108 and end circle. If not NULL, the value must be between 0.0 and 1.0. 109 * @param mode The mode of tiling. 110 * @param startAngle The start angle. 111 * @param endAngle The end angle. 112 */ 113 static std::shared_ptr<RecordingShaderEffect> CreateSweepGradient(const Point& centerPt, 114 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, scalar startAngle, 115 scalar endAngle); 116 117 RecordingShaderEffect() noexcept; 118 ~RecordingShaderEffect() override = default; 119 GetDrawingType()120 DrawingType GetDrawingType() const override 121 { 122 return DrawingType::RECORDING; 123 } 124 125 /* 126 * @brief Gets the pionter to ShaderEffectCmdList. 127 */ GetCmdList()128 std::shared_ptr<ShaderEffectCmdList> GetCmdList() const 129 { 130 return cmdList_; 131 } 132 133 private: 134 std::shared_ptr<ShaderEffectCmdList> cmdList_; 135 }; 136 137 } // namespace Drawing 138 } // namespace Rosen 139 } // namespace OHOS 140 #endif 141