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 // choose the animation is a public animation or special animation 57 bool ChooseAnimation(const std::shared_ptr<RSNode>& rsNode, 58 std::vector<Drawing::DrawingPiecewiseParameter>& parameters, 59 const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig); 60 bool SetKeyframeAlphaAnimation(const std::shared_ptr<RSNode>& rsNode, 61 std::vector<Drawing::DrawingPiecewiseParameter>& parameters, 62 const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig); 63 64 void InitSupportAnimationTable(); 65 66 // to start animations for one path group 67 void GroupAnimationStart( 68 const std::shared_ptr<RSNode>& rsNode, std::vector<std::shared_ptr<RSAnimation>>& animations); 69 70 // Set Node Center Offset 71 void SetNodePivot(const std::shared_ptr<RSNode>& rsNode); 72 73 // splice atomizated animation construct 74 void SpliceAnimation(const std::shared_ptr<RSNode>& rsNode, 75 std::vector<Drawing::DrawingPiecewiseParameter>& parameters, 76 const Drawing::DrawingEffectStrategy& effectStrategy); 77 78 void BounceAnimation( 79 const std::shared_ptr<RSNode>& rsNode, std::vector<Drawing::DrawingPiecewiseParameter>& parameters); 80 void AppearAnimation( 81 const std::shared_ptr<RSNode>& rsNode, std::vector<Drawing::DrawingPiecewiseParameter>& parameters); 82 83 // add scaleModifier to rsNode 84 bool AddScaleBaseModifier(const std::shared_ptr<RSNode>& rsNode, 85 Drawing::DrawingPiecewiseParameter& scaleParameter, 86 std::shared_ptr<RSAnimatableProperty<Vector2f>>& scaleProperty); 87 88 // atomizated animation construct 89 void ScaleAnimationBase(std::shared_ptr<RSAnimatableProperty<Vector2f>>& scaleProperty, 90 Drawing::DrawingPiecewiseParameter& scaleParameter, std::vector<std::shared_ptr<RSAnimation>>& animations); 91 void AlphaAnimationBase(const std::shared_ptr<RSNode>& rsNode, Drawing::DrawingPiecewiseParameter& alphaParamter, 92 std::vector<std::shared_ptr<RSAnimation>>& animations); 93 94 // drawing a path group : symbol drawing or path drawing 95 void GroupDrawing(const std::shared_ptr<RSCanvasNode>& canvasNode, TextEngine::SymbolNode& symbolNode, 96 const Vector4f& offsets, bool isMultiLayer); 97 98 void SetIconProperty(Drawing::Brush& brush, Drawing::Pen& pen, Drawing::DrawingSColor& color); 99 100 Vector4f CalculateOffset(const Drawing::Path& path, const float offsetX, const float offsetY); 101 void DrawSymbolOnCanvas( 102 ExtendRecordingCanvas* recordingCanvas, TextEngine::SymbolNode& symbolNode, const Vector4f& offsets); 103 void DrawPathOnCanvas( 104 ExtendRecordingCanvas* recordingCanvas, TextEngine::SymbolNode& symbolNode, const Vector4f& offsets); 105 bool CalcTimePercents(std::vector<float>& timePercents, const uint32_t totalDuration, 106 const std::vector<Drawing::DrawingPiecewiseParameter>& oneGroupParas); 107 108 std::shared_ptr<RSAnimation> KeyframeAlphaSymbolAnimation(const std::shared_ptr<RSNode>& rsNode, 109 const Drawing::DrawingPiecewiseParameter& oneStageParas, 110 const uint32_t duration, const std::vector<float>& timePercents); 111 bool GetKeyframeAlphaAnimationParas(std::vector<Drawing::DrawingPiecewiseParameter>& oneGroupParas, 112 uint32_t& totalDuration, std::vector<float>& timePercents); 113 114 // Set Replace Animation which include disappear stage and appear stage 115 bool SetReplaceAnimation(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig); 116 // Set Disappear stage of replace animation 117 bool SetReplaceDisappear(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig); 118 // Set appear stage of replace animation 119 bool SetReplaceAppear(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig, 120 bool isStartAnimation=true); 121 // Set Disappear config of replace animation 122 bool SetDisappearConfig(const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig, 123 std::shared_ptr<TextEngine::SymbolAnimationConfig>& disappearConfig); 124 125 // process node before animation include clean invalid node and config info 126 void NodeProcessBeforeAnimation( 127 const std::shared_ptr<TextEngine::SymbolAnimationConfig>& symbolAnimationConfig); 128 // pop invalid node before replace animation, replace animation have special rsnode lifecycle. 129 void PopNodeFromReplaceList(uint64_t symbolSpanId); 130 std::shared_ptr<RSNode> rsNode_ = nullptr; 131 // scale symbol animation 132 std::shared_ptr<RSAnimatableProperty<Vector2f>> scaleProperty_ = nullptr; 133 std::shared_ptr<RSAnimatableProperty<Vector2f>> pivotProperty_ = nullptr; 134 135 // variableColor symbol animation 136 std::vector<std::shared_ptr<RSAnimatableProperty<float>>> alphaPropertyStages_; 137 138 // animation support splice base animation 139 std::vector<Drawing::DrawingEffectStrategy> publicSupportAnimations_ = {}; 140 // animation support up&down interface 141 std::vector<Drawing::DrawingEffectStrategy> upAndDownSupportAnimations_ = {}; 142 }; 143 } // namespace Rosen 144 } // namespace OHOS 145 146 #endif 147