1 /* 2 * Copyright (c) 2021-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 SHADER_EFFECT_H 17 #define SHADER_EFFECT_H 18 19 #include "drawing/engine_adapter/impl_interface/shader_effect_impl.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 namespace Drawing { 24 enum class TileMode { 25 CLAMP, 26 REPEAT, 27 MIRROR, 28 DECAL, 29 }; 30 31 class ShaderEffect { 32 public: 33 enum class ShaderEffectType { 34 NO_TYPE, 35 COLOR, 36 BLEND, 37 IMAGE, 38 PICTURE, 39 LINEAR_GRADIENT, 40 RADIAL_GRADIENT, 41 CONICAL_GRADIENT, 42 SWEEP_GRADIENT, 43 }; 44 45 static std::shared_ptr<ShaderEffect> CreateColorShader(ColorQuad color); 46 static std::shared_ptr<ShaderEffect> CreateBlendShader(ShaderEffect& dst, ShaderEffect& src, BlendMode mode); 47 static std::shared_ptr<ShaderEffect> CreateImageShader( 48 const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling, const Matrix& matrix); 49 static std::shared_ptr<ShaderEffect> CreatePictureShader(const Picture& picture, TileMode tileX, TileMode tileY, 50 FilterMode mode, const Matrix& matrix, const Rect& rect); 51 static std::shared_ptr<ShaderEffect> CreateLinearGradient(const Point& startPt, const Point& endPt, 52 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode); 53 static std::shared_ptr<ShaderEffect> CreateRadialGradient(const Point& centerPt, scalar radius, 54 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode); 55 static std::shared_ptr<ShaderEffect> CreateTwoPointConical(const Point& startPt, scalar startRadius, 56 const Point& endPt, scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, 57 TileMode mode); 58 static std::shared_ptr<ShaderEffect> CreateSweepGradient(const Point& centerPt, 59 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode, scalar startAngle, 60 scalar endAngle); 61 62 virtual ~ShaderEffect() = default; 63 ShaderEffectType GetType() const; GetDrawingType()64 virtual DrawingType GetDrawingType() const 65 { 66 return DrawingType::COMMON; 67 } 68 69 template<typename T> GetImpl()70 const std::shared_ptr<T> GetImpl() const 71 { 72 return impl_->DowncastingTo<T>(); 73 } 74 75 ShaderEffect(ShaderEffectType t, ColorQuad color) noexcept; 76 ShaderEffect(ShaderEffectType t, ShaderEffect& dst, ShaderEffect& src, BlendMode mode) noexcept; 77 ShaderEffect(ShaderEffectType t, const Image& image, TileMode tileX, TileMode tileY, 78 const SamplingOptions& sampling, const Matrix& matrix) noexcept; 79 ShaderEffect(ShaderEffectType t, const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, 80 const Matrix& matrix, const Rect& rect) noexcept; 81 ShaderEffect(ShaderEffectType t, const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors, 82 const std::vector<scalar>& pos, TileMode mode) noexcept; 83 ShaderEffect(ShaderEffectType t, const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors, 84 const std::vector<scalar>& pos, TileMode mode) noexcept; 85 ShaderEffect(ShaderEffectType t, const Point& startPt, scalar startRadius, const Point& endPt, scalar endRadius, 86 const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode) noexcept; 87 ShaderEffect(ShaderEffectType t, const Point& centerPt, const std::vector<ColorQuad>& colors, 88 const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle) noexcept; 89 90 protected: 91 ShaderEffect() noexcept; 92 93 private: 94 ShaderEffectType type_; 95 std::shared_ptr<ShaderEffectImpl> impl_; 96 }; 97 } // namespace Drawing 98 } // namespace Rosen 99 } // namespace OHOS 100 #endif 101