diff --git a/gfx/layers/AnimationHelper.cpp b/gfx/layers/AnimationHelper.cpp index 0428a856d947..d483d931bbd5 100644 --- a/gfx/layers/AnimationHelper.cpp +++ b/gfx/layers/AnimationHelper.cpp @@ -26,14 +26,14 @@ void CompositorAnimationStorage::Clear() { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); mAnimatedValues.Clear(); - mAnimations.Clear(); + mAnimations.clear(); } void CompositorAnimationStorage::ClearById(const uint64_t& aId) { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); mAnimatedValues.Remove(aId); - mAnimations.Remove(aId); + mAnimations.erase(aId); } AnimatedValue* CompositorAnimationStorage::GetAnimatedValue( @@ -126,7 +126,8 @@ void CompositorAnimationStorage::SetAnimatedValue(uint64_t aId, void CompositorAnimationStorage::SetAnimations(uint64_t aId, const AnimationArray& aValue) { MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); - mAnimations.Put(aId, AnimationHelper::ExtractAnimations(aValue)); + mAnimations[aId] = std::make_unique( + AnimationHelper::ExtractAnimations(aValue)); } enum class CanSkipCompose { @@ -581,38 +582,37 @@ bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage, bool isAnimating = false; // Do nothing if there are no compositor animations - if (!aStorage->AnimationsCount()) { + if (!aStorage->HasAnimations()) { return isAnimating; } // Sample the animations in CompositorAnimationStorage - for (auto iter = aStorage->ConstAnimationsTableIter(); !iter.Done(); - iter.Next()) { - auto& animationStorageData = iter.Data(); - if (animationStorageData.mAnimation.IsEmpty()) { + for (const auto& iter : aStorage->Animations()) { + const auto& animationStorageData = iter.second; + if (animationStorageData->mAnimation.IsEmpty()) { continue; } isAnimating = true; nsTArray> animationValues; - AnimatedValue* previousValue = aStorage->GetAnimatedValue(iter.Key()); + AnimatedValue* previousValue = aStorage->GetAnimatedValue(iter.first); AnimationHelper::SampleResult sampleResult = AnimationHelper::SampleAnimationForEachNode( aPreviousFrameTime, aCurrentFrameTime, previousValue, - animationStorageData.mAnimation, animationValues); + animationStorageData->mAnimation, animationValues); if (sampleResult != AnimationHelper::SampleResult::Sampled) { continue; } const PropertyAnimationGroup& lastPropertyAnimationGroup = - animationStorageData.mAnimation.LastElement(); + animationStorageData->mAnimation.LastElement(); // Store the AnimatedValue switch (lastPropertyAnimationGroup.mProperty) { case eCSSProperty_background_color: { aStorage->SetAnimatedValue( - iter.Key(), previousValue, + iter.first, previousValue, Servo_AnimationValue_GetColor(animationValues[0], NS_RGBA(0, 0, 0, 0))); break; @@ -620,7 +620,7 @@ bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage, case eCSSProperty_opacity: { MOZ_ASSERT(animationValues.Length() == 1); aStorage->SetAnimatedValue( - iter.Key(), previousValue, + iter.first, previousValue, Servo_AnimationValue_GetOpacity(animationValues[0])); break; } @@ -632,21 +632,21 @@ bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage, case eCSSProperty_offset_distance: case eCSSProperty_offset_rotate: case eCSSProperty_offset_anchor: { - MOZ_ASSERT(animationStorageData.mTransformData); + MOZ_ASSERT(animationStorageData->mTransformData); const TransformData& transformData = - *animationStorageData.mTransformData; + *animationStorageData->mTransformData; MOZ_ASSERT(transformData.origin() == nsPoint()); gfx::Matrix4x4 transform = ServoAnimationValueToMatrix4x4( animationValues, transformData, - animationStorageData.mCachedMotionPath); + animationStorageData->mCachedMotionPath); gfx::Matrix4x4 frameTransform = transform; transform.PostScale(transformData.inheritedXScale(), transformData.inheritedYScale(), 1); - aStorage->SetAnimatedValue(iter.Key(), previousValue, + aStorage->SetAnimatedValue(iter.first, previousValue, std::move(transform), std::move(frameTransform), transformData); break; diff --git a/gfx/layers/AnimationHelper.h b/gfx/layers/AnimationHelper.h index 4c993c8fffc3..9d2effd617fc 100644 --- a/gfx/layers/AnimationHelper.h +++ b/gfx/layers/AnimationHelper.h @@ -16,6 +16,7 @@ #include "mozilla/TimingParams.h" #include "mozilla/Variant.h" #include "X11UndefineNone.h" +#include namespace mozilla { struct AnimationValue; @@ -108,7 +109,7 @@ struct AnimatedValue final { // mechanism). class CompositorAnimationStorage final { typedef nsClassHashtable AnimatedValueTable; - typedef nsDataHashtable + typedef std::unordered_map> AnimationsTable; NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositorAnimationStorage) @@ -158,14 +159,9 @@ class CompositorAnimationStorage final { */ void SetAnimations(uint64_t aId, const AnimationArray& aAnimations); - /** - * Return the iterator of animations table - */ - AnimationsTable::Iterator ConstAnimationsTableIter() const { - return mAnimations.ConstIter(); - } + const AnimationsTable& Animations() const { return mAnimations; } - uint32_t AnimationsCount() const { return mAnimations.Count(); } + bool HasAnimations() const { return !mAnimations.empty(); } /** * Clear AnimatedValues and Animations data