Skip to content

Commit 932e27e

Browse files
magomezpgorszkowski-igalia
authored andcommitted
Take into account scaling operations when deciding backingStore scale factor
1 parent d4efa23 commit 932e27e

4 files changed

Lines changed: 74 additions & 1 deletion

File tree

Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "NicosiaAnimation.h"
2222

2323
#include "LayoutSize.h"
24+
#include "ScaleTransformOperation.h"
2425
#include "TranslateTransformOperation.h"
2526
#include <wtf/Scope.h>
2627

@@ -474,4 +475,28 @@ bool Animations::hasRunningTransformAnimations() const
474475
});
475476
}
476477

478+
float Animations::maximumScaleFactor() const
479+
{
480+
// Traverse all the keyframes keeping the max values used for scaling.
481+
double scale = 1;
482+
for (auto& animation : m_animations) {
483+
auto& keyframes = animation.keyframes();
484+
485+
if (keyframes.property() != AnimatedProperty::Transform)
486+
continue;
487+
488+
for (size_t i = 0; i < keyframes.size(); i++) {
489+
const auto& transformOperations = static_cast<const TransformAnimationValue&>(keyframes.at(i)).value();
490+
for (size_t j = 0; j < transformOperations.size(); j++) {
491+
auto* transformOperation = transformOperations.at(j);
492+
if (TransformOperation::isScaleTransformOperationType(transformOperation->type())) {
493+
auto* scaleTransformOperation = static_cast<const ScaleTransformOperation*>(transformOperation);
494+
scale = std::max(scale, std::max(scaleTransformOperation->x(), scaleTransformOperation->y()));
495+
}
496+
}
497+
}
498+
}
499+
return scale;
500+
}
501+
477502
} // namespace Nicosia

Source/WebCore/platform/graphics/nicosia/NicosiaAnimation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Animations {
103103
Vector<Animation>& animations() { return m_animations; }
104104

105105
bool hasActiveAnimationsOfType(WebCore::AnimatedProperty type) const;
106+
float maximumScaleFactor() const;
106107

107108
bool hasRunningAnimations() const;
108109
bool hasRunningTransformAnimations() const;

Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,10 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
864864

865865
// Determine the backing store presence. Content is painted later, in the updateContentBuffers() traversal.
866866
if (shouldHaveBackingStore()) {
867+
// The layer has a backingStore. Check whether we need to apply a concrete scale factor to it
868+
// because of some animation or transformation. If we don't do this, the backingStore will always
869+
// have a factor of 1, which will produce blurry results when the layer is scaled up.
870+
updateAnimationOrTransformScaleFactor();
867871
if (!m_nicosia.backingStore) {
868872
m_nicosia.backingStore = Nicosia::BackingStore::create();
869873
m_nicosia.delta.backingStoreChanged = true;
@@ -1076,7 +1080,7 @@ void CoordinatedGraphicsLayer::deviceOrPageScaleFactorChanged()
10761080

10771081
float CoordinatedGraphicsLayer::effectiveContentsScale()
10781082
{
1079-
return selfOrAncestorHaveNonAffineTransforms() ? 1 : deviceScaleFactor() * pageScaleFactor();
1083+
return selfOrAncestorHaveNonAffineTransforms() ? 1 : deviceScaleFactor() * pageScaleFactor() * m_animationOrTransformScaleFactor;
10801084
}
10811085

10821086
IntRect CoordinatedGraphicsLayer::transformedVisibleRect()
@@ -1436,6 +1440,12 @@ bool CoordinatedGraphicsLayer::addAnimation(const KeyframeValueList& valueList,
14361440
m_animations.add(Nicosia::Animation(keyframesName, valueList, boxSize, *anim, m_lastAnimationStartTime, 0_s, Nicosia::Animation::AnimationState::Playing));
14371441
m_animationStartedTimer.startOneShot(0_s);
14381442
didChangeAnimations();
1443+
1444+
// If the animation is of type AnimatedProperty::Transform, it may be a scale animation. Check whether
1445+
// we need to update the scale factor due to a new scale animation being added.
1446+
if (valueList.property() == AnimatedProperty::Transform)
1447+
updateAnimationScaleFactor();
1448+
14391449
return true;
14401450
}
14411451

@@ -1449,6 +1459,9 @@ void CoordinatedGraphicsLayer::removeAnimation(const String& animationName, std:
14491459
{
14501460
m_animations.remove(animationName);
14511461
didChangeAnimations();
1462+
// An animation has been removed, and it could be a scale animation, so check whether
1463+
// we need to update the animation scale factor.
1464+
updateAnimationScaleFactor();
14521465
}
14531466

14541467
void CoordinatedGraphicsLayer::suspendAnimations(MonotonicTime time)
@@ -1491,6 +1504,34 @@ PlatformLayer* CoordinatedGraphicsLayer::platformLayer() const
14911504
}
14921505
#endif
14931506

1507+
void CoordinatedGraphicsLayer::updateAnimationScaleFactor()
1508+
{
1509+
m_animationScaleFactor = m_animations.maximumScaleFactor();
1510+
}
1511+
1512+
void CoordinatedGraphicsLayer::updateAnimationOrTransformScaleFactor()
1513+
{
1514+
TransformationMatrix::Decomposed2Type decomposed2;
1515+
1516+
float parentScale = 1.0;
1517+
if (parent()) {
1518+
if (!downcast<CoordinatedGraphicsLayer>(*parent()).m_layerTransform.combinedForChildren().decompose2(decomposed2))
1519+
return;
1520+
parentScale = std::max(decomposed2.scaleX, decomposed2.scaleY);
1521+
}
1522+
1523+
if (!transform().decompose2(decomposed2))
1524+
return;
1525+
float localScale = std::max(decomposed2.scaleX, decomposed2.scaleY);
1526+
1527+
float newScale = parentScale * std::max(m_animationScaleFactor, localScale);
1528+
1529+
if (newScale != m_animationOrTransformScaleFactor) {
1530+
m_animationOrTransformScaleFactor = newScale;
1531+
m_pendingContentsScaleAdjustment = true;
1532+
}
1533+
}
1534+
14941535
static void dumpInnerLayer(TextStream& textStream, const String& label, CoordinatedGraphicsLayer* layer, OptionSet<LayerTreeAsTextOptions> options)
14951536
{
14961537
if (!layer)

Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer {
230230
RefPtr<BitmapTexture> acquireTextureForAcceleratedBuffer(const IntSize&);
231231
#endif
232232

233+
void updateAnimationScaleFactor();
234+
void updateAnimationOrTransformScaleFactor();
235+
233236
Nicosia::PlatformLayer::LayerID m_id;
234237
GraphicsLayerTransform m_layerTransform;
235238
TransformationMatrix m_cachedInverseTransform;
@@ -279,6 +282,9 @@ class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer {
279282

280283
RefPtr<AnimatedBackingStoreHost> m_animatedBackingStoreHost;
281284
RefPtr<CoordinatedGraphicsLayer> m_backdropLayer;
285+
286+
float m_animationScaleFactor { 1.0 };
287+
float m_animationOrTransformScaleFactor { 1.0 };
282288
};
283289

284290
} // namespace WebCore

0 commit comments

Comments
 (0)