Skip to content

Commit a9b32a7

Browse files
committed
Take into account scaling operations when deciding backingStore scale factor
1 parent ac8eaf7 commit a9b32a7

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

@@ -481,4 +482,28 @@ bool Animations::hasRunningTransformAnimations() const
481482
});
482483
}
483484

485+
float Animations::maximumScaleFactor() const
486+
{
487+
// Traverse all the keyframes keeping the max values used for scaling.
488+
double scale = 1;
489+
for (auto& animation : m_animations) {
490+
auto& keyframes = animation.keyframes();
491+
492+
if (keyframes.property() != AnimatedProperty::Transform)
493+
continue;
494+
495+
for (size_t i = 0; i < keyframes.size(); i++) {
496+
const auto& transformOperations = static_cast<const TransformAnimationValue&>(keyframes.at(i)).value();
497+
for (size_t j = 0; j < transformOperations.size(); j++) {
498+
auto* transformOperation = transformOperations.at(j);
499+
if (TransformOperation::isScaleTransformOperationType(transformOperation->type())) {
500+
auto* scaleTransformOperation = static_cast<const ScaleTransformOperation*>(transformOperation);
501+
scale = std::max(scale, std::max(scaleTransformOperation->x(), scaleTransformOperation->y()));
502+
}
503+
}
504+
}
505+
}
506+
return scale;
507+
}
508+
484509
} // 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
@@ -860,6 +860,10 @@ void CoordinatedGraphicsLayer::flushCompositingStateForThisLayerOnly()
860860

861861
// Determine the backing store presence. Content is painted later, in the updateContentBuffers() traversal.
862862
if (shouldHaveBackingStore()) {
863+
// The layer has a backingStore. Check whether we need to apply a concrete scale factor to it
864+
// because of some animation or transformation. If we don't do this, the backingStore will always
865+
// have a factor of 1, which will produce blurry results when the layer is scaled up.
866+
updateAnimationOrTransformScaleFactor();
863867
if (!m_nicosia.backingStore) {
864868
m_nicosia.backingStore = Nicosia::BackingStore::create();
865869
m_nicosia.delta.backingStoreChanged = true;
@@ -1077,7 +1081,7 @@ void CoordinatedGraphicsLayer::deviceOrPageScaleFactorChanged()
10771081

10781082
float CoordinatedGraphicsLayer::effectiveContentsScale()
10791083
{
1080-
return selfOrAncestorHaveNonAffineTransforms() ? 1 : deviceScaleFactor() * pageScaleFactor();
1084+
return selfOrAncestorHaveNonAffineTransforms() ? 1 : deviceScaleFactor() * pageScaleFactor() * m_animationOrTransformScaleFactor;
10811085
}
10821086

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

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

14551468
void CoordinatedGraphicsLayer::suspendAnimations(MonotonicTime time)
@@ -1492,6 +1505,34 @@ PlatformLayer* CoordinatedGraphicsLayer::platformLayer() const
14921505
}
14931506
#endif
14941507

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