• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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_ANIMATION_RS_SYMBOL_ANIMATION_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_SYMBOL_ANIMATION_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "animation/rs_animation_timing_curve.h"
24 #include "animation/rs_symbol_node_config.h"
25 #include "common/rs_vector2.h"
26 #include "common/rs_vector4.h"
27 #include "draw/path.h"
28 #include "include/text/hm_symbol_config_ohos.h"
29 #include "modifier/rs_property.h"
30 #include "modifier/rs_property_modifier.h"
31 #include "symbol_animation_config.h"
32 #include "ui/rs_canvas_node.h"
33 #include "ui/rs_node.h"
34 
35 namespace OHOS {
36 namespace Rosen {
37 class RSC_EXPORT RSSymbolAnimation {
38 public:
39     RSSymbolAnimation();
40     virtual ~RSSymbolAnimation();
SetNode(std::shared_ptr<RSNode> & rsNode)41     void SetNode(std::shared_ptr<RSNode>& rsNode)
42     {
43         rsNode_ = rsNode;
44     }
45 
46     // set symbol animation manager
47     bool SetSymbolAnimation(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
48 
49 private:
50     bool SetSymbolGeometry(const std::shared_ptr<RSNode>& rsNode, const Vector4f& bounds);
51     // SetPublicAnimation is interface for animation that can be spliced by atomizated animations
52     bool SetPublicAnimation(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
53     bool GetAnimationGroupParameters(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig,
54         std::vector<std::vector<Drawing::DrawingPiecewiseParameter>>& parameters,
55         Drawing::DrawingEffectStrategy& effectStrategy);
56     void UpdateSymbolGeometry(const std::shared_ptr<RSNode>& rsNode, const Vector4f& bounds);
57     // choose the animation is a public animation or special animation
58     bool ChooseAnimation(const std::shared_ptr<RSNode>& rsNode,
59         std::vector<Drawing::DrawingPiecewiseParameter>& parameters,
60         const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
61     bool SetKeyframeAlphaAnimation(const std::shared_ptr<RSNode>& rsNode,
62         std::vector<Drawing::DrawingPiecewiseParameter>& parameters,
63         const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
64 
65     void InitSupportAnimationTable();
66 
67     // to start animations for one path group
68     void GroupAnimationStart(
69         const std::shared_ptr<RSNode>& rsNode, std::vector<std::shared_ptr<RSAnimation>>& animations);
70 
71     // Set Node Center Offset
72     void SetNodePivot(const std::shared_ptr<RSNode>& rsNode);
73 
74     // splice atomizated animation construct
75     void SpliceAnimation(const std::shared_ptr<RSNode>& rsNode,
76         std::vector<Drawing::DrawingPiecewiseParameter>& parameters);
77 
78     // atomizated animation construct
79     void ScaleAnimationBase(const std::shared_ptr<RSNode>& rsNode,
80         std::shared_ptr<RSAnimatableProperty<Vector2f>>& scaleProperty,
81         Drawing::DrawingPiecewiseParameter& scaleParameter, std::vector<std::shared_ptr<RSAnimation>>& animations);
82     void AlphaAnimationBase(const std::shared_ptr<RSNode>& rsNode,
83         std::shared_ptr<RSAnimatableProperty<float>>& alphaProperty,
84         Drawing::DrawingPiecewiseParameter& alphaParamter, std::vector<std::shared_ptr<RSAnimation>>& animations);
85 
86     // drawing a path group : symbol drawing or path drawing
87     void GroupDrawing(const std::shared_ptr<RSCanvasNode>& canvasNode, TextEngine::SymbolNode& symbolNode,
88         const Vector4f& offsets);
89 
90     void SetIconProperty(Drawing::Brush& brush, Drawing::Pen& pen, Drawing::DrawingSColor& color);
91 
92     Vector4f CalculateOffset(const Drawing::Path& path, const float offsetX, const float offsetY);
93 
94     void DrawPathOnCanvas(
95         ExtendRecordingCanvas* recordingCanvas, TextEngine::SymbolNode& symbolNode, const Vector4f& offsets);
96     bool CalcTimePercents(std::vector<float>& timePercents, const uint32_t totalDuration,
97         const std::vector<Drawing::DrawingPiecewiseParameter>& oneGroupParas);
98 
99     std::shared_ptr<RSAnimation> KeyframeAlphaSymbolAnimation(const std::shared_ptr<RSNode>& rsNode,
100         const Drawing::DrawingPiecewiseParameter& oneStageParas,
101         const uint32_t duration, const std::vector<float>& timePercents);
102     bool GetKeyframeAlphaAnimationParas(std::vector<Drawing::DrawingPiecewiseParameter>& oneGroupParas,
103         uint32_t& totalDuration, std::vector<float>& timePercents);
104 
105     // Set Replace Animation which include disappear stage and appear stage
106     bool SetReplaceAnimation(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
107     // Set Disappear stage of replace animation
108     bool SetReplaceDisappear(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
109     // Set appear stage of replace animation
110     bool SetReplaceAppear(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig,
111         bool isStartAnimation=true);
112     // Set Disappear config of replace animation
113     bool SetDisappearConfig(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig,
114         std::shared_ptr<TextEngine::SymbolAnimationConfig>& disappearConfig);
115 
116     // Determine whether to create a node based on the existing canvasNodesListMap node
117     bool CreateSymbolNode(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig,
118         const Vector4f& offsets, uint32_t index);
119 
120     // process node before animation include clean invalid node and config info
121     void NodeProcessBeforeAnimation(
122         const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig);
123     // pop invalid node before replace animation, replace animation have special rsnode lifecycle.
124     void PopNodeFromReplaceList(uint64_t symbolSpanId);
125 
126     std::shared_ptr<RSNode> rsNode_ = nullptr;
127     // scale symbol animation
128     std::shared_ptr<RSAnimatableProperty<Vector2f>> scaleProperty_ = nullptr;
129     std::shared_ptr<RSAnimatableProperty<Vector2f>> pivotProperty_ = nullptr;
130 
131     // variableColor symbol animation
132     std::vector<std::shared_ptr<RSAnimatableProperty<float>>> alphaPropertyStages_;
133 
134     // animation support splice base animation
135     std::vector<Drawing::DrawingEffectStrategy> publicSupportAnimations_ = {};
136     // animation support up&down interface
137     std::vector<Drawing::DrawingEffectStrategy> upAndDownSupportAnimations_ = {};
138 };
139 } // namespace Rosen
140 } // namespace OHOS
141 
142 #endif
143