• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H
17 #define RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H
18 
19 #include "common/rs_macros.h"
20 #include "modifier/rs_property.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 class RSC_EXPORT RSModifier : public std::enable_shared_from_this<RSModifier> {
25 public:
RSModifier(const std::shared_ptr<RSPropertyBase> & property)26     explicit RSModifier(const std::shared_ptr<RSPropertyBase>& property)
27         : property_(property ? property : std::make_shared<RSPropertyBase>())
28     {}
29 
30     virtual ~RSModifier() = default;
31 
GetProperty()32     std::shared_ptr<RSPropertyBase> GetProperty()
33     {
34         return property_;
35     }
36 
GetPropertyId()37     PropertyId GetPropertyId()
38     {
39         return property_->id_;
40     }
41 
42 protected:
RSModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)43     RSModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
44         : property_(property ? property : std::make_shared<RSPropertyBase>())
45     {
46         property_->type_ = type;
47     }
48 
GetModifierType()49     virtual RSModifierType GetModifierType() const
50     {
51         return RSModifierType::INVALID;
52     }
53 
54     void AttachProperty(const std::shared_ptr<RSPropertyBase>& property);
55 
AttachToNode(const std::shared_ptr<RSNode> target)56     void AttachToNode(const std::shared_ptr<RSNode> target)
57     {
58         property_->target_ = std::weak_ptr<RSNode>(target);
59         OnAttachToNode(target);
60     }
61 
DetachFromNode()62     void DetachFromNode()
63     {
64         property_->target_.reset();
65     }
66 
SetMotionPathOption(const std::shared_ptr<RSMotionPathOption> & motionPathOption)67     void SetMotionPathOption(const std::shared_ptr<RSMotionPathOption>& motionPathOption)
68     {
69         property_->SetMotionPathOption(motionPathOption);
70     }
71 
GetRenderProperty()72     std::shared_ptr<RSRenderPropertyBase> GetRenderProperty() const
73     {
74         return property_->GetRenderProperty();
75     }
76 
77     virtual std::shared_ptr<RSRenderModifier> CreateRenderModifier() const = 0;
78 
UpdateToRender()79     virtual void UpdateToRender() {}
80 
OnAttachToNode(const std::weak_ptr<RSNode> & target)81     virtual void OnAttachToNode(const std::weak_ptr<RSNode>& target) {}
82 
83     void SetDirty(const bool isDirty);
84 
85     void ResetRSNodeExtendModifierDirty();
86 
87     bool isDirty_ { false };
88     std::shared_ptr<RSPropertyBase> property_;
89 
90     friend class RSModifierExtractor;
91     friend class RSModifierManager;
92     friend class RSNode;
93     friend class RSPathAnimation;
94     friend class RSPropertyBase;
95 };
96 
97 class RSC_EXPORT RSGeometryModifier : public RSModifier {
98 public:
RSGeometryModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)99     RSGeometryModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
100         : RSModifier(property, type)
101     {}
102 
103     virtual ~RSGeometryModifier() = default;
104 };
105 
106 class RSC_EXPORT RSBackgroundModifier : public RSModifier {
107 public:
RSBackgroundModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)108     RSBackgroundModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
109         : RSModifier(property, type)
110     {}
111 
112     virtual ~RSBackgroundModifier() = default;
113 };
114 
115 class RSC_EXPORT RSContentModifier : public RSModifier {
116 public:
RSContentModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)117     RSContentModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
118         : RSModifier(property, type)
119     {}
120 
121     virtual ~RSContentModifier() = default;
122 };
123 
124 class RSC_EXPORT RSForegroundModifier : public RSModifier {
125 public:
RSForegroundModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)126     RSForegroundModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
127         : RSModifier(property, type)
128     {}
129 
130     virtual ~RSForegroundModifier() = default;
131 };
132 
133 class RSC_EXPORT RSOverlayModifier : public RSModifier {
134 public:
RSOverlayModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)135     RSOverlayModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
136         : RSModifier(property, type)
137     {}
138 
139     virtual ~RSOverlayModifier() = default;
140 };
141 
142 class RSC_EXPORT RSAppearanceModifier : public RSModifier {
143 public:
RSAppearanceModifier(const std::shared_ptr<RSPropertyBase> & property,const RSModifierType type)144     RSAppearanceModifier(const std::shared_ptr<RSPropertyBase>& property, const RSModifierType type)
145         : RSModifier(property, type)
146     {}
147 
148     virtual ~RSAppearanceModifier() = default;
149 };
150 } // namespace Rosen
151 } // namespace OHOS
152 
153 #endif // RENDER_SERVICE_CLIENT_CORE_MODIFIER_RS_MODIFIER_H
154