Ignore:
Timestamp:
Jun 21, 2022, 8:12:18 PM (3 years ago)
Author:
Matt Woodrow
Message:

Don't allocate device pixel ratio scaled backing stores for layers that contain only unscaled bitmap content
https://bugs.webkit.org/show_bug.cgi?id=241450

Reviewed by Simon Fraser.

  • Source/WebCore/platform/graphics/GraphicsLayer.cpp:

(WebCore::GraphicsLayer::GraphicsLayer):

  • Source/WebCore/platform/graphics/GraphicsLayer.h:

(WebCore::GraphicsLayer::setAppliesDeviceScale):
(WebCore::GraphicsLayer::appliesDeviceScale const):
(WebCore::GraphicsLayer::deviceScaleFactor const):

  • Source/WebCore/rendering/RenderLayerBacking.cpp:

(WebCore::PaintedContentsInfo::isUnscaledBitmapOnly):
(WebCore::PaintedContentsInfo::contentsTypeDetermination):
(WebCore::RenderLayerBacking::updateConfiguration):
(WebCore::RenderLayerBacking::isUnscaledBitmapOnly const):

  • Source/WebCore/rendering/RenderLayerBacking.h:

Adds isUnscaledBitmapOnly to check if a layer contains only a <canvas>/image,
and no other rasterized content, and that the bitmap is drawn unscaled.
If so, uses setAppliesDeviceScale to disable hidpi backing stores for this layer.

  • Source/WebCore/platform/graphics/LayerTreeAsTextOptions.h:
  • Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::GraphicsLayerCA::dumpAdditionalProperties const):

  • Source/WebCore/testing/Internals.cpp:

(WebCore::toLayerTreeAsTextOptions):

  • Source/WebCore/testing/Internals.h:
  • Source/WebCore/testing/Internals.idl:

Adds new internals.LAYER_TREE_INCLUDES_DEVICE_SCALE flag for layer tree dumping, in order
to test whether a layer has a high dpi backing store or not.

  • LayoutTests/compositing/canvas/hidpi-canvas-backing-store-expected.txt: Added.
  • LayoutTests/compositing/canvas/hidpi-canvas-backing-store-invalidation-expected.txt: Added.
  • LayoutTests/compositing/canvas/hidpi-canvas-backing-store-invalidation.html: Added.
  • LayoutTests/compositing/canvas/hidpi-canvas-backing-store.html: Added.

Adds new test for low-dpi backing store for a layer containing only a canvas, and an invalidation
test to check that we go back to hidpi when we add a rasterized outline.

Canonical link: https://commits.webkit.org/251723@main

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r295630 r295718  
    112112        SimpleContainer,
    113113        DirectlyCompositedImage,
    114         Painted
     114        UnscaledBitmapOnly,
     115        Painted,
    115116    };
    116117
     
    157158    }
    158159
     160    bool isUnscaledBitmapOnly()
     161    {
     162        return contentsTypeDetermination() == ContentsTypeDetermination::UnscaledBitmapOnly;
     163    }
     164
    159165    RenderLayerBacking& m_backing;
    160166    RequestState m_boxDecorations { RequestState::Unknown };
     
    210216    else if (m_backing.isDirectlyCompositedImage())
    211217        m_contentsType = ContentsTypeDetermination::DirectlyCompositedImage;
     218    else if (m_backing.isUnscaledBitmapOnly())
     219        m_contentsType = ContentsTypeDetermination::UnscaledBitmapOnly;
    212220    else
    213221        m_contentsType = ContentsTypeDetermination::Painted;
     
    10681076    if (contentsInfo.isDirectlyCompositedImage())
    10691077        updateImageContents(contentsInfo);
     1078
     1079    bool unscaledBitmap = contentsInfo.isUnscaledBitmapOnly();
     1080    if (unscaledBitmap == m_graphicsLayer->appliesDeviceScale()) {
     1081        m_graphicsLayer->setAppliesDeviceScale(!unscaledBitmap);
     1082        layerConfigChanged = true;
     1083    }
    10701084
    10711085    if (is<RenderEmbeddedObject>(renderer()) && downcast<RenderEmbeddedObject>(renderer()).allowsAcceleratedCompositing()) {
     
    29132927}
    29142928
     2929bool RenderLayerBacking::isUnscaledBitmapOnly() const
     2930{
     2931    if (!is<RenderImage>(renderer()) && !is<RenderHTMLCanvas>(renderer()))
     2932        return false;
     2933
     2934    if (m_owningLayer.hasVisibleBoxDecorationsOrBackground())
     2935        return false;
     2936
     2937    auto contents = contentsBox();
     2938    if (contents.location() != LayoutPoint(0, 0))
     2939        return false;
     2940
     2941    if (is<RenderImage>(renderer())) {
     2942        auto& imageRenderer = downcast<RenderImage>(renderer());
     2943        if (auto* cachedImage = imageRenderer.cachedImage()) {
     2944            if (!cachedImage->hasImage())
     2945                return false;
     2946
     2947            auto* image = cachedImage->imageForRenderer(&imageRenderer);
     2948            if (!is<BitmapImage>(image))
     2949                return false;
     2950
     2951            if (downcast<BitmapImage>(*image).orientationForCurrentFrame() != ImageOrientation::None)
     2952                return false;
     2953
     2954            return contents.size() == image->size();
     2955        }
     2956        return false;
     2957    }
     2958
     2959    auto& canvasRenderer = downcast<RenderHTMLCanvas>(renderer());
     2960    if (snappedIntRect(contents).size() == canvasRenderer.canvasElement().size())
     2961        return true;
     2962    return false;
     2963}
     2964
    29152965void RenderLayerBacking::contentChanged(ContentChangeType changeType)
    29162966{
    29172967    PaintedContentsInfo contentsInfo(*this);
    2918     if ((changeType == ImageChanged) && contentsInfo.isDirectlyCompositedImage()) {
    2919         updateImageContents(contentsInfo);
    2920         return;
     2968    if (changeType == ImageChanged) {
     2969        if (contentsInfo.isDirectlyCompositedImage()) {
     2970            updateImageContents(contentsInfo);
     2971            return;
     2972        }
     2973        if (contentsInfo.isUnscaledBitmapOnly()) {
     2974            compositor().scheduleCompositingLayerUpdate();
     2975            return;
     2976        }
    29212977    }
    29222978
Note: See TracChangeset for help on using the changeset viewer.