1 /*
2  * Copyright (c) 2022 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_GRAPHICS_MODIFIER_PAINTER_H
16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_GRAPHICS_MODIFIER_PAINTER_H
17 
18 #include <memory>
19 
20 #ifndef USE_ROSEN_DRAWING
21 #include "include/core/SkRRect.h"
22 #endif
23 #include "render_service_client/core/modifier/rs_extended_modifier.h"
24 #include "render_service_client/core/modifier/rs_property.h"
25 
26 #include "core/components/common/properties/color.h"
27 #ifdef USE_ROSEN_DRAWING
28 #include "core/components_ng/render/drawing_forward.h"
29 #endif
30 
31 namespace OHOS::Ace::NG {
32 using RSDrawingContext = Rosen::RSDrawingContext;
33 
34 // common parent class of graphic effect modifiers
35 class GraphicModifier : public Rosen::RSForegroundStyleModifier {
36 public:
37     void SetCustomData(float data);
38 
39     void SetCornerRadius(const Rosen::Vector4f& radius);
40 
41 protected:
42 #ifndef USE_ROSEN_DRAWING
43     SkRRect MakeRRect(const RSDrawingContext& context) const;
44 #else
45     RSRoundRect MakeRRect(const RSDrawingContext& context) const;
46 #endif
47 
48     std::shared_ptr<Rosen::RSAnimatableProperty<float>> property_;
49     std::shared_ptr<Rosen::RSAnimatableProperty<Rosen::Vector4f>> radius_;
50 };
51 
52 class GrayScaleModifier : public GraphicModifier {
53 public:
54     void Draw(RSDrawingContext& context) const override;
55 };
56 
57 class BrightnessModifier : public GraphicModifier {
58 public:
59     void Draw(RSDrawingContext& context) const override;
60 };
61 
62 class ContrastModifier : public GraphicModifier {
63 public:
64     void Draw(RSDrawingContext& context) const override;
65 };
66 
67 class SaturateModifier : public GraphicModifier {
68 public:
69     void Draw(RSDrawingContext& context) const override;
70 };
71 
72 class SepiaModifier : public GraphicModifier {
73 public:
74     void Draw(RSDrawingContext& context) const override;
75 };
76 
77 class InvertModifier : public GraphicModifier {
78 public:
79     void Draw(RSDrawingContext& context) const override;
80 };
81 
82 class HueRotateModifier : public GraphicModifier {
83 public:
84     void Draw(RSDrawingContext& context) const override;
85 };
86 
87 class ColorBlend : public Rosen::RSAnimatableArithmetic<ColorBlend> {
88 public:
89     ColorBlend() = default;
ColorBlend(const Color & color)90     explicit ColorBlend(const Color& color) : colorBlend_(color) {}
91 
Add(const ColorBlend & value)92     ColorBlend Add(const ColorBlend& value) const override
93     {
94         return ColorBlend(colorBlend_ + value.colorBlend_);
95     }
96 
Minus(const ColorBlend & value)97     ColorBlend Minus(const ColorBlend& value) const override
98     {
99         return ColorBlend(colorBlend_ - value.colorBlend_);
100     }
101 
Multiply(const float scale)102     ColorBlend Multiply(const float scale) const override
103     {
104         return ColorBlend(colorBlend_ * scale);
105     }
106 
IsEqual(const ColorBlend & value)107     bool IsEqual(const ColorBlend& value) const override
108     {
109         return colorBlend_ == value.colorBlend_;
110     }
111 
GetColor()112     Color GetColor()
113     {
114         return colorBlend_;
115     }
116     Color colorBlend_;
117 };
118 
119 class ColorBlendModifier : public GraphicModifier {
120 public:
121     void Draw(RSDrawingContext& context) const override;
122 
123     void SetCustomData(const ColorBlend& data);
124 
125 private:
126     std::shared_ptr<Rosen::RSAnimatableProperty<ColorBlend>> colorProp_;
127 };
128 } // namespace OHOS::Ace::NG
129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_RENDER_GRAPHICS_MODIFIER_PAINTER_H