Bug 1640525 - Avoid looking up AnimatedValue twice. r=boris

We've already tried to looking up the existing AnimatedValue so that when we
want to replace the old one in the hash table we can reuse the existing one.
With this manner, we no longer need to copy TransformData if we don't need to
do.

Differential Revision: https://phabricator.services.mozilla.com/D76633
This commit is contained in:
Hiroyuki Ikezoe 2020-05-26 21:56:20 +00:00
Родитель 5df8c99574
Коммит cb41bbc2c4
3 изменённых файлов: 79 добавлений и 35 удалений

Просмотреть файл

@ -75,39 +75,52 @@ OMTAValue CompositorAnimationStorage::GetOMTAValue(const uint64_t& aId) const {
}
void CompositorAnimationStorage::SetAnimatedValue(
uint64_t aId, gfx::Matrix4x4&& aTransformInDevSpace,
gfx::Matrix4x4&& aFrameTransform, const TransformData& aData) {
uint64_t aId, AnimatedValue* aPreviousValue,
gfx::Matrix4x4&& aTransformInDevSpace, gfx::Matrix4x4&& aFrameTransform,
const TransformData& aData) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
auto count = mAnimatedValues.Count();
AnimatedValue* value = mAnimatedValues.LookupOrAdd(
aId, std::move(aTransformInDevSpace), std::move(aFrameTransform), aData);
if (count == mAnimatedValues.Count()) {
MOZ_ASSERT(value->Is<AnimationTransform>());
*value = AnimatedValue(std::move(aTransformInDevSpace),
std::move(aFrameTransform), aData);
if (!aPreviousValue) {
MOZ_ASSERT(!mAnimatedValues.Contains(aId));
mAnimatedValues.Put(
aId, MakeUnique<AnimatedValue>(std::move(aTransformInDevSpace),
std::move(aFrameTransform), aData));
return;
}
MOZ_ASSERT(aPreviousValue->Is<AnimationTransform>());
MOZ_ASSERT(aPreviousValue == GetAnimatedValue(aId));
aPreviousValue->SetTransform(std::move(aTransformInDevSpace),
std::move(aFrameTransform), aData);
}
void CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
AnimatedValue* aPreviousValue,
nscolor aColor) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
auto count = mAnimatedValues.Count();
AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId, aColor);
if (count == mAnimatedValues.Count()) {
MOZ_ASSERT(value->Is<nscolor>());
*value = AnimatedValue(aColor);
if (!aPreviousValue) {
MOZ_ASSERT(!mAnimatedValues.Contains(aId));
mAnimatedValues.Put(aId, MakeUnique<AnimatedValue>(aColor));
return;
}
MOZ_ASSERT(aPreviousValue->Is<nscolor>());
MOZ_ASSERT(aPreviousValue == GetAnimatedValue(aId));
aPreviousValue->SetColor(aColor);
}
void CompositorAnimationStorage::SetAnimatedValue(uint64_t aId,
const float& aOpacity) {
AnimatedValue* aPreviousValue,
float aOpacity) {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
auto count = mAnimatedValues.Count();
AnimatedValue* value = mAnimatedValues.LookupOrAdd(aId, aOpacity);
if (count == mAnimatedValues.Count()) {
MOZ_ASSERT(value->Is<float>());
*value = AnimatedValue(aOpacity);
if (!aPreviousValue) {
MOZ_ASSERT(!mAnimatedValues.Contains(aId));
mAnimatedValues.Put(aId, MakeUnique<AnimatedValue>(aOpacity));
return;
}
MOZ_ASSERT(aPreviousValue->Is<float>());
MOZ_ASSERT(aPreviousValue == GetAnimatedValue(aId));
aPreviousValue->SetOpacity(aOpacity);
}
void CompositorAnimationStorage::SetAnimations(uint64_t aId,
@ -599,14 +612,16 @@ bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage,
switch (lastPropertyAnimationGroup.mProperty) {
case eCSSProperty_background_color: {
aStorage->SetAnimatedValue(
iter.Key(), Servo_AnimationValue_GetColor(animationValues[0],
NS_RGBA(0, 0, 0, 0)));
iter.Key(), previousValue,
Servo_AnimationValue_GetColor(animationValues[0],
NS_RGBA(0, 0, 0, 0)));
break;
}
case eCSSProperty_opacity: {
MOZ_ASSERT(animationValues.Length() == 1);
aStorage->SetAnimatedValue(
iter.Key(), Servo_AnimationValue_GetOpacity(animationValues[0]));
iter.Key(), previousValue,
Servo_AnimationValue_GetOpacity(animationValues[0]));
break;
}
case eCSSProperty_rotate:
@ -631,7 +646,8 @@ bool AnimationHelper::SampleAnimations(CompositorAnimationStorage* aStorage,
transform.PostScale(transformData.inheritedXScale(),
transformData.inheritedYScale(), 1);
aStorage->SetAnimatedValue(iter.Key(), std::move(transform),
aStorage->SetAnimatedValue(iter.Key(), previousValue,
std::move(transform),
std::move(frameTransform), transformData);
break;
}

Просмотреть файл

@ -68,6 +68,26 @@ struct AnimatedValue final {
explicit AnimatedValue(nscolor aValue) : mValue(AsVariant(aValue)) {}
void SetTransform(gfx::Matrix4x4&& aTransformInDevSpace,
gfx::Matrix4x4&& aFrameTransform,
const TransformData& aData) {
MOZ_ASSERT(mValue.is<AnimationTransform>());
AnimationTransform& previous = mValue.as<AnimationTransform>();
previous.mTransformInDevSpace = std::move(aTransformInDevSpace);
previous.mFrameTransform = std::move(aFrameTransform);
if (previous.mData != aData) {
previous.mData = aData;
}
}
void SetOpacity(float aOpacity) {
MOZ_ASSERT(mValue.is<float>());
mValue.as<float>() = aOpacity;
}
void SetColor(nscolor aColor) {
MOZ_ASSERT(mValue.is<nscolor>());
mValue.as<nscolor>() = aColor;
}
private:
AnimatedValueType mValue;
};
@ -95,21 +115,27 @@ class CompositorAnimationStorage final {
public:
/**
* Set the animation transform based on the unique id and also
* set up |aFrameTransform| and |aData| for OMTA testing
* set up |aFrameTransform| and |aData| for OMTA testing.
* If |aPreviousValue| is not null, the animation transform replaces the value
* in the |aPreviousValue|.
* NOTE: |aPreviousValue| should be the value for the |aId|.
*/
void SetAnimatedValue(uint64_t aId, gfx::Matrix4x4&& aTransformInDevSpace,
void SetAnimatedValue(uint64_t aId, AnimatedValue* aPreviousValue,
gfx::Matrix4x4&& aTransformInDevSpace,
gfx::Matrix4x4&& aFrameTransform,
const TransformData& aData);
/**
* Set the animation opacity based on the unique id
* Similar to above but for opacity.
*/
void SetAnimatedValue(uint64_t aId, const float& aOpacity);
void SetAnimatedValue(uint64_t aId, AnimatedValue* aPreviousValue,
float aOpacity);
/**
* Set the animation color based on the unique id
* Similar to above but for color.
*/
void SetAnimatedValue(uint64_t aId, nscolor aColor);
void SetAnimatedValue(uint64_t aId, AnimatedValue* aPreviousValue,
nscolor aColor);
/**
* Return the animated value if a given id can map to its animated value

Просмотреть файл

@ -578,7 +578,7 @@ static Matrix4x4 FrameTransformToTransformInDevice(
static void ApplyAnimatedValue(
Layer* aLayer, CompositorAnimationStorage* aStorage,
nsCSSPropertyID aProperty,
nsCSSPropertyID aProperty, AnimatedValue* aPreviousValue,
const nsTArray<RefPtr<RawServoAnimationValue>>& aValues) {
MOZ_ASSERT(!aValues.IsEmpty());
@ -591,7 +591,8 @@ static void ApplyAnimatedValue(
nscolor color =
Servo_AnimationValue_GetColor(aValues[0], NS_RGBA(0, 0, 0, 0));
aLayer->AsColorLayer()->SetColor(gfx::ToDeviceColor(color));
aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(), color);
aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
aPreviousValue, color);
layerCompositor->SetShadowOpacity(aLayer->GetOpacity());
layerCompositor->SetShadowOpacitySetByAnimation(false);
@ -604,7 +605,8 @@ static void ApplyAnimatedValue(
float opacity = Servo_AnimationValue_GetOpacity(aValues[0]);
layerCompositor->SetShadowOpacity(opacity);
layerCompositor->SetShadowOpacitySetByAnimation(true);
aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(), opacity);
aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
aPreviousValue, opacity);
layerCompositor->SetShadowBaseTransform(aLayer->GetBaseTransform());
layerCompositor->SetShadowTransformSetByAnimation(false);
@ -630,7 +632,7 @@ static void ApplyAnimatedValue(
layerCompositor->SetShadowBaseTransform(transform);
layerCompositor->SetShadowTransformSetByAnimation(true);
aStorage->SetAnimatedValue(aLayer->GetCompositorAnimationsId(),
std::move(transform),
aPreviousValue, std::move(transform),
std::move(frameTransform), transformData);
layerCompositor->SetShadowOpacity(aLayer->GetOpacity());
@ -681,7 +683,7 @@ bool AsyncCompositionManager::SampleAnimations(Layer* aLayer,
// a single same layer, so using the transform data of the last element
// should be fine.
ApplyAnimatedValue(layer, storage, lastPropertyAnimationGroup.mProperty,
animationValues);
previousValue, animationValues);
break;
case AnimationHelper::SampleResult::Skipped:
switch (lastPropertyAnimationGroup.mProperty) {