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