已合并
添加关键帧动画合并逻辑 #29806
添加关键帧动画合并逻辑 #29806
已合并
zouwei创建于 4月28日
2 个文件变更+37-4
Mrosen/modules/render_service_client/core/animation/rs_keyframe_animation.cpp+14-3
@@ -23,7 +23,9 @@
23#include "platform/common/rs_log.h"23#include "platform/common/rs_log.h"
24 24 
25static constexpr int DURATION_MIN = 0;25static constexpr int DURATION_MIN = 0;
26static constexpr int DURATION_VALUE_INDEX = 2;26static constexpr int START_DURATION_INDEX = 0;
27static constexpr int END_DURATION_INDEX = 1;
28static constexpr int PROPERTY_VALUE_INDEX = 2;
27 29 
28namespace OHOS {30namespace OHOS {
29namespace Rosen {31namespace Rosen {
@@ -67,6 +69,15 @@ void RSKeyframeAnimation::AddKeyFrame(int startDuration, int endDuration,
67 return;69 return;
68 }70 }
69 71 
72 for (auto& it : durationKeyframes_) {
73 auto start = std::get<START_DURATION_INDEX>(it);
74 auto end = std::get<END_DURATION_INDEX>(it);
75 if (startDuration == start && endDuration == end) {
76 std::get<PROPERTY_VALUE_INDEX>(it) = value;
chensiyi_CE
chensiyi_CEchensiyi_CE5月6日

属性后设置覆盖前设置,且没有属性类型校验。

likedislike
zouwei
zouwei
5月6日 评论:
likedislike
chensiyi_CE
chensiyi_CE
5月6日 评论:
likedislike
77 return;
78 }
79 }
80 
70 durationKeyframes_.push_back({ startDuration, endDuration, value, timingCurve });81 durationKeyframes_.push_back({ startDuration, endDuration, value, timingCurve });
71}82}
72 83 
@@ -86,8 +97,8 @@ void RSKeyframeAnimation::InitInterpolationValue()
86 durationKeyframes_.insert(durationKeyframes_.begin(),97 durationKeyframes_.insert(durationKeyframes_.begin(),
87 { DURATION_MIN, DURATION_MIN, GetOriginValue(), RSAnimationTimingCurve::LINEAR });98 { DURATION_MIN, DURATION_MIN, GetOriginValue(), RSAnimationTimingCurve::LINEAR });
88 99 
89 startValue_ = std::get<DURATION_VALUE_INDEX>(durationKeyframes_.front());100 startValue_ = std::get<PROPERTY_VALUE_INDEX>(durationKeyframes_.front());
90 endValue_ = std::get<DURATION_VALUE_INDEX>(durationKeyframes_.back());101 endValue_ = std::get<PROPERTY_VALUE_INDEX>(durationKeyframes_.back());
91 RSPropertyAnimation::InitInterpolationValue();102 RSPropertyAnimation::InitInterpolationValue();
92 return;103 return;
93 }104 }
Mrosen/test/render_service/render_service_client/unittest/animation/rs_keyframe_animation_test.cpp+23-1
@@ -54,4 +54,26 @@ HWTEST_F(RSKeyframeAnimationTest, AddKeyFrameTest001, Level1)
54 rsKeyframeAnimation.AddKeyFrame(1.f, value, timingCurve);54 rsKeyframeAnimation.AddKeyFrame(1.f, value, timingCurve);
55 ASSERT_NE(value, nullptr);55 ASSERT_NE(value, nullptr);
56}56}
57}57 
58/**
59 * @tc.name: AddKeyFrameTest002
60 * @tc.desc: Test AddKeyFrame to cover if else branches
61 * @tc.type: FUNC
62 */
63HWTEST_F(RSKeyframeAnimationTest, AddKeyFrameTest002, Level1)
64{
65 auto value = std::make_shared<RSProperty<float>>();
66 OHOS::sptr<OHOS::IRemoteObject> connectToRenderRemote;
67 auto rsUIContext = RSUIContextManager::MutableInstance().CreateRSUIContext(connectToRenderRemote);
68 RSKeyframeAnimation rsKeyframeAnimation(rsUIContext, value);
69 RSAnimationTimingCurve timingCurve;
70 
71 rsKeyframeAnimation.AddKeyFrame(10, 20, value, timingCurve);
72 rsKeyframeAnimation.AddKeyFrame(30, 40, value, timingCurve);
73 rsKeyframeAnimation.AddKeyFrame(30, 50, value, timingCurve);
74 rsKeyframeAnimation.AddKeyFrame(40, 50, value, timingCurve);
75 rsKeyframeAnimation.AddKeyFrame(40, 50, value, timingCurve);
76 
77 EXPECT_EQ(rsKeyframeAnimation.durationKeyframes_.size(), 4);
78}
79} // namespace OHOS::Rosen