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 RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PATH_ANIMATION_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PATH_ANIMATION_H 18 19 #include "animation/rs_interpolator.h" 20 #include "animation/rs_render_property_animation.h" 21 #include "common/rs_macros.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 class RSPath; 26 27 class RSB_EXPORT RSRenderPathAnimation : public RSRenderPropertyAnimation { 28 static constexpr float UNDEFINED_FLOAT = 0.0f; 29 public: 30 RSRenderPathAnimation(AnimationId id, const PropertyId& propertyId, 31 const std::shared_ptr<RSRenderPropertyBase>& originPosition, 32 const std::shared_ptr<RSRenderPropertyBase>& startPosition, 33 const std::shared_ptr<RSRenderPropertyBase>& endPosition, float originRotation, 34 const std::shared_ptr<RSPath>& animationPath); 35 36 ~RSRenderPathAnimation() = default; 37 38 void SetInterpolator(const std::shared_ptr<RSInterpolator>& interpolator); 39 40 const std::shared_ptr<RSInterpolator>& GetInterpolator() const; 41 42 void SetRotationMode(const RotationMode& rotationMode); 43 44 RotationMode GetRotationMode() const; 45 46 void SetBeginFraction(float fraction); 47 48 float GetBeginFraction() const; 49 50 void SetEndFraction(float fraction); 51 52 float GetEndFraction() const; 53 54 void SetIsNeedPath(const bool isNeedPath); 55 56 void SetPathNeedAddOrigin(bool needAddOrigin); 57 58 void SetRotationId(const PropertyId id); 59 60 bool Marshalling(Parcel& parcel) const override; 61 62 static RSRenderPathAnimation* Unmarshalling(Parcel& parcel); 63 64 protected: 65 RSRenderPathAnimation() = default; 66 67 void OnAnimate(float fraction) override; 68 69 void OnRemoveOnCompletion() override; 70 71 void InitValueEstimator() override; 72 73 private: 74 bool ParseParam(Parcel& parcel) override; 75 void SetPathValue(const Vector2f& value, float tangent); 76 void SetPathValue(const Vector4f& value, float tangent); 77 78 void SetRotationValue(const float tangent); 79 80 void SetRotation(const float tangent); 81 82 void GetPosTanValue(float fraction, Vector2f& position, float& tangent); 83 84 void UpdateVector2fPathValue(Vector2f& value); 85 void UpdateVector4fPathValue(Vector4f& value, const Vector2f& position); 86 87 float originRotation_ { UNDEFINED_FLOAT }; 88 float beginFraction_ { FRACTION_MIN }; 89 float endFraction_ { FRACTION_MAX }; 90 bool isNeedPath_ { true }; 91 bool needAddOrigin_ { false }; 92 PropertyId rotationId_; 93 RotationMode rotationMode_ { RotationMode::ROTATE_NONE }; 94 std::shared_ptr<RSRenderPropertyBase> startValue_ {}; 95 std::shared_ptr<RSRenderPropertyBase> endValue_ {}; 96 std::shared_ptr<RSInterpolator> interpolator_ { RSInterpolator::DEFAULT }; 97 std::shared_ptr<RSPath> animationPath_; 98 }; 99 } // namespace Rosen 100 } // namespace OHOS 101 102 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_PATH_ANIMATION_H 103