• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SKIA_SHADER_EFFECT_H
17 #define SKIA_SHADER_EFFECT_H
18 
19 #include "include/core/SkShader.h"
20 
21 #include "impl_interface/shader_effect_impl.h"
22 #include "include/effects/SkRuntimeEffect.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaShaderEffect : public ShaderEffectImpl {
28 public:
29     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
30 
31     SkiaShaderEffect() noexcept;
~SkiaShaderEffect()32     ~SkiaShaderEffect() override {};
33 
GetType()34     AdapterType GetType() const override
35     {
36         return AdapterType::SKIA_ADAPTER;
37     }
38 
39     void InitWithColor(ColorQuad color) override;
40 
41     void InitWithColorSpace(const Color4f& color, std::shared_ptr<ColorSpace> colorSpace) override;
42 
43     void InitWithBlend(const ShaderEffect& s1, const ShaderEffect& s2, BlendMode mode) override;
44 
45     void InitWithImage(const Image& image, TileMode tileX, TileMode tileY, const SamplingOptions& sampling,
46         const Matrix& matrix) override;
47 
48     void InitWithPicture(const Picture& picture, TileMode tileX, TileMode tileY, FilterMode mode, const Matrix& matrix,
49         const Rect& rect) override;
50 
51     void InitWithLinearGradient(const Point& startPt, const Point& endPt, const std::vector<ColorQuad>& colors,
52         const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override;
53 
54     void InitWithRadialGradient(const Point& centerPt, scalar radius, const std::vector<ColorQuad>& colors,
55         const std::vector<scalar>& pos, TileMode mode, const Matrix *matrix) override;
56 
57     void InitWithTwoPointConical(const Point& startPt, scalar startRadius, const Point& endPt,
58         scalar endRadius, const std::vector<ColorQuad>& colors, const std::vector<scalar>& pos, TileMode mode,
59         const Matrix *matrix) override;
60 
61     void InitWithSweepGradient(const Point& centerPt, const std::vector<ColorQuad>& colors,
62         const std::vector<scalar>& pos, TileMode mode, scalar startAngle, scalar endAngle,
63         const Matrix *matrix) override;
64 
65     void InitWithSdf(const SDFShapeBase& shape) override;
66 
67     sk_sp<SkShader> GetShader() const;
68     /*
69      * @brief  Update the member variable to skShader, adaptation layer calls.
70      */
71     void SetSkShader(const sk_sp<SkShader>& skShader);
72 
73     std::shared_ptr<Data> Serialize() const override;
74     bool Deserialize(std::shared_ptr<Data> data) override;
75 private:
76     sk_sp<SkShader> shader_;
77 };
78 } // namespace Drawing
79 } // namespace Rosen
80 } // namespace OHOS
81 #endif