diff options
Diffstat (limited to 'Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp')
-rw-r--r-- | Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp b/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp index 37385c0..b72d761 100644 --- a/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp +++ b/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp @@ -253,6 +253,7 @@ GraphicsLayerCA::GraphicsLayerCA(GraphicsLayerClient* client) , m_contentsLayerPurpose(NoContentsLayer) , m_contentsLayerHasBackgroundColor(false) , m_uncommittedChanges(NoChange) + , m_contentsScale(1) { m_layer = PlatformCALayer::create(PlatformCALayer::LayerTypeWebLayer, this); @@ -857,6 +858,9 @@ void GraphicsLayerCA::commitLayerChangesBeforeSublayers() if (m_uncommittedChanges & AcceleratesDrawingChanged) updateAcceleratesDrawing(); + + if (m_uncommittedChanges & ContentsScaleChanged) + updateContentsScale(); } void GraphicsLayerCA::commitLayerChangesAfterSublayers() @@ -1897,6 +1901,44 @@ GraphicsLayerCA::LayerMap* GraphicsLayerCA::animatedLayerClones(AnimatedProperty return (property == AnimatedPropertyBackgroundColor) ? m_contentsLayerClones.get() : primaryLayerClones(); } +void GraphicsLayerCA::setContentsScale(float scale) +{ + float newScale = clampedContentsScaleForScale(scale); + if (newScale == m_contentsScale) + return; + + m_contentsScale = newScale; + noteLayerPropertyChanged(ContentsScaleChanged); +} + +float GraphicsLayerCA::clampedContentsScaleForScale(float scale) const +{ + // Define some limits as a sanity check for the incoming scale value + // those too small to see. + const float maxScale = 5.0f; + const float minScale = 0.01f; + + // Avoid very slight scale changes that would be doing extra work for no benefit + const float maxAllowableDelta = 0.05f; + + // Clamp + float result = max(minScale, min(scale, maxScale)); + + // If it hasn't changed much, don't do any work + return ((fabs(result - m_contentsScale) / m_contentsScale) < maxAllowableDelta) ? m_contentsScale : result; +} + +void GraphicsLayerCA::updateContentsScale() +{ + bool needTiledLayer = requiresTiledLayer(m_size); + if (needTiledLayer != m_usingTiledLayer) + swapFromOrToTiledLayer(needTiledLayer); + + m_layer->setContentsScale(m_contentsScale); + if (drawsContent()) + m_layer->setNeedsDisplay(); +} + void GraphicsLayerCA::setDebugBackgroundColor(const Color& color) { if (color.isValid()) @@ -1950,12 +1992,11 @@ bool GraphicsLayerCA::requiresTiledLayer(const FloatSize& size) const void GraphicsLayerCA::swapFromOrToTiledLayer(bool useTiledLayer) { - if (useTiledLayer == m_usingTiledLayer) - return; - + ASSERT(useTiledLayer != m_usingTiledLayer); RefPtr<PlatformCALayer> oldLayer = m_layer; m_layer = PlatformCALayer::create(useTiledLayer ? PlatformCALayer::LayerTypeWebTiledLayer : PlatformCALayer::LayerTypeWebLayer, this); + m_layer->setContentsScale(m_contentsScale); m_usingTiledLayer = useTiledLayer; @@ -2230,6 +2271,7 @@ PassRefPtr<PlatformCALayer> GraphicsLayerCA::cloneLayer(PlatformCALayer *layer, newLayer->setDoubleSided(layer->isDoubleSided()); newLayer->setOpaque(layer->isOpaque()); newLayer->setBackgroundColor(layer->backgroundColor()); + newLayer->setContentsScale(layer->contentsScale()); if (cloneLevel == IntermediateCloneLevel) { newLayer->setOpacity(layer->opacity()); |