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_KEYFRAME_ANIMATION_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_KEYFRAME_ANIMATION_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "animation/rs_animation_common.h" 23 #include "animation/rs_animation_timing_curve.h" 24 #include "animation/rs_property_animation.h" 25 26 namespace OHOS { 27 namespace Rosen { 28 static constexpr int FRACTION_INDEX = 0; 29 static constexpr int VALUE_INDEX = 1; 30 static constexpr int INTERPOLATOR_INDEX = 2; 31 32 class RSRenderKeyframeAnimation; 33 34 class RSC_EXPORT RSKeyframeAnimation : public RSPropertyAnimation { 35 public: 36 RSKeyframeAnimation(std::shared_ptr<RSPropertyBase> property); 37 virtual ~RSKeyframeAnimation() = default; 38 39 void AddKeyFrame(float fraction, const std::shared_ptr<RSPropertyBase>& value, 40 const RSAnimationTimingCurve& timingCurve); 41 42 void AddKeyFrames(const 43 std::vector<std::tuple<float, std::shared_ptr<RSPropertyBase>, RSAnimationTimingCurve>>& keyframes); 44 45 void AddKeyFrame(int startDuration, int endDuration, const std::shared_ptr<RSPropertyBase>& value, 46 const RSAnimationTimingCurve& timingCurve); 47 48 void SetDurationKeyframe(bool isDuration); 49 IsSupportInteractiveAnimator()50 bool IsSupportInteractiveAnimator() override { return false; } 51 protected: 52 void OnStart() override; 53 54 void InitInterpolationValue() override; 55 56 private: 57 void StartRenderAnimation(const std::shared_ptr<RSRenderKeyframeAnimation>& animation); 58 59 void StartUIAnimation(const std::shared_ptr<RSRenderKeyframeAnimation>& animation); 60 61 std::vector<std::tuple<float, std::shared_ptr<RSPropertyBase>, RSAnimationTimingCurve>> keyframes_; 62 63 std::vector<std::tuple<int, int, std::shared_ptr<RSPropertyBase>, RSAnimationTimingCurve>> durationKeyframes_; 64 65 bool isDurationKeyframe_ { false }; 66 67 friend class RSImplicitKeyframeAnimationParam; 68 }; 69 } // namespace Rosen 70 } // namespace OHOS 71 72 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_KEYFRAME_ANIMATION_H 73