Changeset 282335 in webkit


Ignore:
Timestamp:
Sep 13, 2021 10:20:57 AM (10 months ago)
Author:
commit-queue@webkit.org
Message:

image-rendering: pixelated does not work with WebGL (but does with Canvas2D)
https://bugs.webkit.org/show_bug.cgi?id=193895
<rdar://problem/47656086>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-09-13
Reviewed by Simon Fraser.

Source/WebCore:

Implement image-rendering: crisp-edges for WebGL canvas elements
normal on-screen compositing code path on Cocoa by using CA layer filtering
properties.

Similar to non-compositing code path, approximate image-rendering: pixelated
by making it an alias of crisp-edges.

Test: webgl/webgl-image-rendering.html

  • platform/graphics/GraphicsLayer.h:

(WebCore::GraphicsLayer::setContentsMinificationFilter):
(WebCore::GraphicsLayer::contentsMinificationFilter const):
(WebCore::GraphicsLayer::setContentsMagnificationFilter):
(WebCore::GraphicsLayer::contentsMagnificationFilter const):

  • platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::toPlatformCALayerFilterType):
(WebCore::GraphicsLayerCA::setContentsMinificationFilter):
(WebCore::GraphicsLayerCA::setContentsMagnificationFilter):
(WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
(WebCore::GraphicsLayerCA::updateContentsScalingFilters):
(WebCore::GraphicsLayerCA::updateContentsPlatformLayer):
(WebCore::GraphicsLayerCA::layerChangeAsString):

  • platform/graphics/ca/GraphicsLayerCA.h:
  • rendering/RenderHTMLCanvas.h:
  • rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
(WebCore::RenderLayerBacking::updateContentsScalingFilters):
(WebCore::RenderLayerBacking::updateConfigurationAfterStyleChange):
(WebCore::RenderLayerBacking::updateGeometry):
(WebCore::RenderLayerBacking::paintIntoLayer):

  • rendering/RenderLayerBacking.h:

LayoutTests:

Add a test comparing upscaling of WebGL canvas element and an image element
with the same contents when using image-rendering: properties.

  • platform/mac/webgl/webgl-image-rendering-expected.png: Added.
  • webgl/webgl-image-rendering-expected.txt: Added.
  • webgl/webgl-image-rendering.html: Added.
Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r282331 r282335  
     12021-09-13  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        image-rendering: pixelated does not work with WebGL (but does with Canvas2D)
     4        https://bugs.webkit.org/show_bug.cgi?id=193895
     5        <rdar://problem/47656086>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Add a test comparing upscaling of WebGL canvas element and an image element
     10        with the same contents when using image-rendering: properties.
     11
     12        * platform/mac/webgl/webgl-image-rendering-expected.png: Added.
     13        * webgl/webgl-image-rendering-expected.txt: Added.
     14        * webgl/webgl-image-rendering.html: Added.
     15
    1162021-09-13  Eric Hutchison  <ehutchison@apple.com>
    217
  • trunk/Source/WebCore/ChangeLog

    r282326 r282335  
     12021-09-13  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        image-rendering: pixelated does not work with WebGL (but does with Canvas2D)
     4        https://bugs.webkit.org/show_bug.cgi?id=193895
     5        <rdar://problem/47656086>
     6
     7        Reviewed by Simon Fraser.
     8
     9        Implement image-rendering: crisp-edges for WebGL canvas elements
     10        normal on-screen compositing code path on Cocoa by using CA layer filtering
     11        properties.
     12
     13        Similar to non-compositing code path, approximate image-rendering: pixelated
     14        by making it an alias of crisp-edges.
     15
     16        Test: webgl/webgl-image-rendering.html
     17
     18        * platform/graphics/GraphicsLayer.h:
     19        (WebCore::GraphicsLayer::setContentsMinificationFilter):
     20        (WebCore::GraphicsLayer::contentsMinificationFilter const):
     21        (WebCore::GraphicsLayer::setContentsMagnificationFilter):
     22        (WebCore::GraphicsLayer::contentsMagnificationFilter const):
     23        * platform/graphics/ca/GraphicsLayerCA.cpp:
     24        (WebCore::toPlatformCALayerFilterType):
     25        (WebCore::GraphicsLayerCA::setContentsMinificationFilter):
     26        (WebCore::GraphicsLayerCA::setContentsMagnificationFilter):
     27        (WebCore::GraphicsLayerCA::commitLayerChangesBeforeSublayers):
     28        (WebCore::GraphicsLayerCA::updateContentsScalingFilters):
     29        (WebCore::GraphicsLayerCA::updateContentsPlatformLayer):
     30        (WebCore::GraphicsLayerCA::layerChangeAsString):
     31        * platform/graphics/ca/GraphicsLayerCA.h:
     32        * rendering/RenderHTMLCanvas.h:
     33        * rendering/RenderLayerBacking.cpp:
     34        (WebCore::RenderLayerBacking::createPrimaryGraphicsLayer):
     35        (WebCore::RenderLayerBacking::updateContentsScalingFilters):
     36        (WebCore::RenderLayerBacking::updateConfigurationAfterStyleChange):
     37        (WebCore::RenderLayerBacking::updateGeometry):
     38        (WebCore::RenderLayerBacking::paintIntoLayer):
     39        * rendering/RenderLayerBacking.h:
     40
    1412021-09-13  Alan Bujtas  <zalan@apple.com>
    242
  • trunk/Source/WebCore/platform/graphics/GraphicsLayer.h

    r281238 r282335  
    541541    CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
    542542
     543    enum class ScalingFilter { Linear, Nearest, Trilinear };
     544    virtual void setContentsMinificationFilter(ScalingFilter filter) { m_contentsMinificationFilter = filter; }
     545    ScalingFilter contentsMinificationFilter() const { return m_contentsMinificationFilter; }
     546    virtual void setContentsMagnificationFilter(ScalingFilter filter) { m_contentsMagnificationFilter = filter; }
     547    ScalingFilter contentsMagnificationFilter() const { return m_contentsMagnificationFilter; }
     548
    543549    void dumpLayer(WTF::TextStream&, OptionSet<LayerTreeAsTextOptions> = { }) const;
    544550
     
    770776    FloatSize m_contentsTilePhase;
    771777    FloatSize m_contentsTileSize;
     778    ScalingFilter m_contentsMinificationFilter = ScalingFilter::Linear;
     779    ScalingFilter m_contentsMagnificationFilter = ScalingFilter::Linear;
    772780    FloatRoundedRect m_backdropFiltersRect;
    773781    std::optional<FloatRect> m_animationExtent;
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r281238 r282335  
    303303}
    304304
     305static PlatformCALayer::FilterType toPlatformCALayerFilterType(GraphicsLayer::ScalingFilter filter)
     306{
     307    switch (filter) {
     308    case GraphicsLayer::ScalingFilter::Linear:
     309        return PlatformCALayer::Linear;
     310    case GraphicsLayer::ScalingFilter::Nearest:
     311        return PlatformCALayer::Nearest;
     312    case GraphicsLayer::ScalingFilter::Trilinear:
     313        return PlatformCALayer::Trilinear;
     314    }
     315    ASSERT_NOT_REACHED();
     316    return PlatformCALayer::Linear;
     317}
     318
    305319bool GraphicsLayer::supportsLayerType(Type type)
    306320{
     
    13421356#endif
    13431357
     1358void GraphicsLayerCA::setContentsMinificationFilter(ScalingFilter filter)
     1359{
     1360    if (filter == m_contentsMinificationFilter)
     1361        return;
     1362    GraphicsLayer::setContentsMinificationFilter(filter);
     1363    noteLayerPropertyChanged(ContentsScalingFiltersChanged);
     1364}
     1365
     1366void GraphicsLayerCA::setContentsMagnificationFilter(ScalingFilter filter)
     1367{
     1368    if (filter == m_contentsMagnificationFilter)
     1369        return;
     1370    GraphicsLayer::setContentsMagnificationFilter(filter);
     1371    noteLayerPropertyChanged(ContentsScalingFiltersChanged);
     1372}
     1373
    13441374void GraphicsLayerCA::layerDidDisplay(PlatformCALayer* layer)
    13451375{
     
    20262056#endif
    20272057#endif
     2058    if (m_uncommittedChanges & ContentsScalingFiltersChanged)
     2059        updateContentsScalingFilters();
    20282060
    20292061    if (m_uncommittedChanges & ChildrenChanged) {
     
    24862518#endif
    24872519
     2520void GraphicsLayerCA::updateContentsScalingFilters()
     2521{
     2522    if (!m_contentsLayer)
     2523        return;
     2524    m_contentsLayer->setMinificationFilter(toPlatformCALayerFilterType(m_contentsMinificationFilter));
     2525    m_contentsLayer->setMagnificationFilter(toPlatformCALayerFilterType(m_contentsMagnificationFilter));
     2526}
     2527
    24882528bool GraphicsLayerCA::updateStructuralLayer()
    24892529{
     
    27592799
    27602800    updateContentsRects();
     2801    updateContentsScalingFilters();
    27612802}
    27622803
     
    41874228#endif
    41884229#endif
     4230    case LayerChange::ContentsScalingFiltersChanged: return "ContentsScalingFiltersChanged";
    41894231    }
    41904232    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.h

    r281238 r282335  
    156156    WEBCORE_EXPORT PlatformLayerID contentsLayerIDForModel() const override;
    157157#endif
     158    WEBCORE_EXPORT void setContentsMinificationFilter(ScalingFilter) override;
     159    WEBCORE_EXPORT void setContentsMagnificationFilter(ScalingFilter) override;
    158160
    159161    bool usesContentsLayer() const override { return m_contentsLayerPurpose != ContentsLayerPurpose::None; }
     
    464466#endif
    465467#endif
     468    void updateContentsScalingFilters();
    466469
    467470    enum StructuralLayerPurpose {
     
    579582#endif
    580583#endif
     584        ContentsScalingFiltersChanged           = 1LLU << 44,
    581585    };
    582586    typedef uint64_t LayerChangeFlags;
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r281364 r282335  
    541541    }
    542542#endif   
    543    
    544     updateOpacity(renderer().style());
    545     updateTransform(renderer().style());
    546     updateFilters(renderer().style());
     543    auto& style = renderer().style();
     544    updateOpacity(style);
     545    updateTransform(style);
     546    updateFilters(style);
    547547#if ENABLE(FILTERS_LEVEL_2)
    548     updateBackdropFilters(renderer().style());
     548    updateBackdropFilters(style);
    549549#endif
    550550#if ENABLE(CSS_COMPOSITING)
    551     updateBlendMode(renderer().style());
    552 #endif
    553     updateCustomAppearance(renderer().style());
     551    updateBlendMode(style);
     552#endif
     553    updateCustomAppearance(style);
     554    updateContentsScalingFilters(style);
    554555}
    555556
     
    780781}
    781782
     783void RenderLayerBacking::updateContentsScalingFilters(const RenderStyle& style)
     784{
     785    if (!renderer().isCanvas() || canvasCompositingStrategy(renderer()) != CanvasAsLayerContents)
     786        return;
     787    auto minificationFilter = GraphicsLayer::ScalingFilter::Linear;
     788    auto magnificationFilter = GraphicsLayer::ScalingFilter::Linear;
     789    switch (style.imageRendering()) {
     790    case ImageRendering::CrispEdges:
     791    case ImageRendering::Pixelated:
     792        // FIXME: In order to match other code-paths, we treat these the same.
     793        minificationFilter = GraphicsLayer::ScalingFilter::Nearest;
     794        magnificationFilter = GraphicsLayer::ScalingFilter::Nearest;
     795        break;
     796    default:
     797        break;
     798    }
     799    m_graphicsLayer->setContentsMinificationFilter(minificationFilter);
     800    m_graphicsLayer->setContentsMagnificationFilter(magnificationFilter);
     801}
     802
    782803static bool layerOrAncestorIsTransformedOrUsingCompositedScrolling(RenderLayer& layer)
    783804{
     
    960981#endif
    961982    updateCustomAppearance(style);
     983    updateContentsScalingFilters(style);
    962984}
    963985
     
    12851307    updateBlendMode(style);
    12861308#endif
     1309    updateContentsScalingFilters(style);
    12871310
    12881311    ASSERT(compositedAncestor == m_owningLayer.ancestorCompositingLayer());
  • trunk/Source/WebCore/rendering/RenderLayerBacking.h

    r281238 r282335  
    356356#endif
    357357    void updateCustomAppearance(const RenderStyle&);
     358    void updateContentsScalingFilters(const RenderStyle&);
    358359
    359360    // Return the opacity value that this layer should use for compositing.
Note: See TracChangeset for help on using the changeset viewer.