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_IMAGE_FILTER_H
17 #define SKIA_IMAGE_FILTER_H
18 
19 #include "include/core/SkColorFilter.h"
20 #include "include/core/SkImageFilter.h"
21 
22 #include "impl_interface/image_filter_impl.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class SkiaImageFilter : public ImageFilterImpl {
28 public:
29     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
30 
31     SkiaImageFilter() noexcept;
~SkiaImageFilter()32     ~SkiaImageFilter() override {};
33 
GetType()34     AdapterType GetType() const override
35     {
36         return AdapterType::SKIA_ADAPTER;
37     }
38 
39     void InitWithBlur(scalar sigmaX, scalar sigmaY, TileMode mode, const std::shared_ptr<ImageFilter> f,
40         ImageBlurType blurType, const Rect& cropRect) override;
41     void InitWithColor(const ColorFilter& colorFilter, const std::shared_ptr<ImageFilter> f,
42         const Rect& cropRect) override;
43     void InitWithColorBlur(const ColorFilter& colorFilter, scalar sigmaX, scalar sigmaY,
44         ImageBlurType blurType, const Rect& cropRect) override;
45     void InitWithOffset(scalar dx, scalar dy, const std::shared_ptr<ImageFilter> f, const Rect& cropRect) override;
46     void InitWithArithmetic(const std::vector<scalar>& coefficients, bool enforcePMColor,
47         const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2, const Rect& cropRect) override;
48     void InitWithCompose(const std::shared_ptr<ImageFilter> f1, const std::shared_ptr<ImageFilter> f2) override;
49     void InitWithGradientBlur(float radius, const std::vector<std::pair<float, float>>& fractionStops,
50         GradientDir direction, GradientBlurType blurType,
51         const std::shared_ptr<ImageFilter> f) override;
52     void InitWithBlend(BlendMode mode, const Rect& cropRect, std::shared_ptr<ImageFilter> background,
53         std::shared_ptr<ImageFilter> foreground = nullptr) override;
54     void InitWithShader(std::shared_ptr<ShaderEffect> shader, const Rect& cropRect) override;
55     sk_sp<SkImageFilter> GetImageFilter() const;
56     /*
57      * @brief  Update the member variable to filter, adaptation layer calls.
58      */
59     void SetSkImageFilter(const sk_sp<SkImageFilter>& filter);
60 
61     std::shared_ptr<Data> Serialize() const override;
62     bool Deserialize(std::shared_ptr<Data> data) override;
63 private:
64     sk_sp<SkImageFilter> filter_;
65 };
66 } // namespace Drawing
67 } // namespace Rosen
68 } // namespace OHOS
69 #endif