Changeset 194607 in webkit


Ignore:
Timestamp:
Jan 5, 2016, 2:09:20 PM (9 years ago)
Author:
Simon Fraser
Message:

Adjust tile coverage with margin tiles, and tidy up the indicator
https://bugs.webkit.org/show_bug.cgi?id=152742

Reviewed by Beth Dakin.

Source/WebCore:

The tile coverage rect was unfeasibly large when margin tiles are present, and
could be bigger than the layer itself, making the indicator look odd.

Fix by improving the logic in TileController::adjustTileCoverageRect(): this
now first extends the visible rect for scrolling, and then constrains it
within the bounds with margin padding. It also unites with the passed-in
coverageRect, ensuring that we don't lose information about overhang for
margin tile coverage.

Second, update the tiled scrolling indicator when the visible rect changes,
and coalesce the map updates on a timer.

  • platform/graphics/TiledBacking.h:
  • platform/graphics/ca/GraphicsLayerCA.cpp:

(WebCore::GraphicsLayerCA::adjustCoverageRect):

  • platform/graphics/ca/TileController.cpp:

(WebCore::TileController::setVisibleRect):
(WebCore::TileController::setTiledScrollingIndicatorPosition):
(WebCore::expandRectWithinRect):
(WebCore::TileController::adjustTileCoverageRect):
(WebCore::TileController::updateTileCoverageMap):
(WebCore::TileController::computeTileCoverageRect): Deleted.

  • platform/graphics/ca/TileController.h:
  • platform/graphics/ca/TileCoverageMap.cpp:

(WebCore::TileCoverageMap::TileCoverageMap):
(WebCore::TileCoverageMap::setNeedsUpdate):
(WebCore::TileCoverageMap::updateTimerFired):

  • platform/graphics/ca/TileCoverageMap.h:

LayoutTests:

New baselines. simple-document-with-margin-tiles.html needs to wait for over 0.5s
for the FrameView::enableSpeculativeTilingIfNeeded() timer to fire before
dumping coverage (ouch).

  • tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-expected.txt:
  • tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-with-handler-expected.txt:
  • tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-expected.txt:
  • tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-with-handler-expected.txt:
  • tiled-drawing/simple-document-with-margin-tiles.html:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r194605 r194607  
     12016-01-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Adjust tile coverage with margin tiles, and tidy up the indicator
     4        https://bugs.webkit.org/show_bug.cgi?id=152742
     5
     6        Reviewed by Beth Dakin.
     7
     8        New baselines. simple-document-with-margin-tiles.html needs to wait for over 0.5s
     9        for the FrameView::enableSpeculativeTilingIfNeeded() timer to fire before
     10        dumping coverage (ouch).
     11
     12        * tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-expected.txt:
     13        * tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-with-handler-expected.txt:
     14        * tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-expected.txt:
     15        * tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-with-handler-expected.txt:
     16        * tiled-drawing/simple-document-with-margin-tiles.html:
     17
    1182016-01-05  Brady Eidson  <beidson@apple.com>
    219
  • trunk/LayoutTests/tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-expected.txt

    r187905 r194607  
    2222      (contentsOpaque 1)
    2323      (visible rect 0.00, 0.00 785.00 x 600.00)
    24       (coverage rect 0.00, 0.00 1570.00 x 1800.00)
     24      (coverage rect 0.00, 0.00 785.00 x 1800.00)
    2525      (intersects coverage rect 1)
    2626      (contentsScale 1.00)
  • trunk/LayoutTests/tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-with-handler-expected.txt

    r187905 r194607  
    2222      (contentsOpaque 1)
    2323      (visible rect 0.00, 0.00 785.00 x 600.00)
    24       (coverage rect 0.00, 0.00 1570.00 x 1800.00)
     24      (coverage rect 0.00, 0.00 785.00 x 1800.00)
    2525      (intersects coverage rect 1)
    2626      (contentsScale 1.00)
  • trunk/LayoutTests/tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-expected.txt

    r187905 r194607  
    2222      (contentsOpaque 1)
    2323      (visible rect 0.00, 70.00 785.00 x 600.00)
    24       (coverage rect 0.00, 0.00 1570.00 x 1800.00)
     24      (coverage rect 0.00, 0.00 785.00 x 1800.00)
    2525      (intersects coverage rect 1)
    2626      (contentsScale 1.00)
  • trunk/LayoutTests/tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-with-handler-expected.txt

    r187905 r194607  
    2222      (contentsOpaque 1)
    2323      (visible rect 0.00, 70.00 785.00 x 600.00)
    24       (coverage rect 0.00, 0.00 1570.00 x 1800.00)
     24      (coverage rect 0.00, 0.00 785.00 x 1800.00)
    2525      (intersects coverage rect 1)
    2626      (contentsScale 1.00)
  • trunk/LayoutTests/tiled-drawing/simple-document-with-margin-tiles-expected.txt

    r187905 r194607  
    1111      (contentsOpaque 1)
    1212      (visible rect 0.00, 0.00 785.00 x 585.00)
    13       (coverage rect -512.00, -512.00 1809.00 x 1609.00)
     13      (coverage rect -392.50, -512.00 1570.00 x 1755.00)
    1414      (intersects coverage rect 1)
    1515      (contentsScale 1.00)
  • trunk/LayoutTests/tiled-drawing/simple-document-with-margin-tiles.html

    r187905 r194607  
    1414    </style>
    1515    <script>
    16         if (window.testRunner)
     16        if (window.testRunner) {
    1717            testRunner.dumpAsText();
     18            testRunner.waitUntilDone();
     19        }
    1820
    1921        function doTest()
    2022        {
    21             if (window.internals) {
     23            if (window.internals)
    2224                window.internals.settings.setBackgroundShouldExtendBeyondPage(true);
    23                 document.getElementById('layers').innerText = internals.layerTreeAsText(document,
    24                     internals.LAYER_TREE_INCLUDES_VISIBLE_RECTS | internals.LAYER_TREE_INCLUDES_TILE_CACHES);
    25             }
     25
     26            // FrameView::enableSpeculativeTilingIfNeeded() uses a 0.5s timer to enable speculative tiling.
     27            window.setTimeout(function() {
     28                if (window.internals) {
     29                    document.getElementById('layers').innerText = internals.layerTreeAsText(document,
     30                        internals.LAYER_TREE_INCLUDES_VISIBLE_RECTS | internals.LAYER_TREE_INCLUDES_TILE_CACHES);
     31                }
     32               
     33                if (window.testRunner)
     34                    testRunner.notifyDone();
     35            }, 550);
    2636        }
    2737        window.addEventListener('load', doTest, false);
  • trunk/Source/WebCore/ChangeLog

    r194596 r194607  
     12016-01-05  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Adjust tile coverage with margin tiles, and tidy up the indicator
     4        https://bugs.webkit.org/show_bug.cgi?id=152742
     5
     6        Reviewed by Beth Dakin.
     7
     8        The tile coverage rect was unfeasibly large when margin tiles are present, and
     9        could be bigger than the layer itself, making the indicator look odd.
     10
     11        Fix by improving the logic in TileController::adjustTileCoverageRect(): this
     12        now first extends the visible rect for scrolling, and then constrains it
     13        within the bounds with margin padding. It also unites with the passed-in
     14        coverageRect, ensuring that we don't lose information about overhang for
     15        margin tile coverage.
     16
     17        Second, update the tiled scrolling indicator when the visible rect changes,
     18        and coalesce the map updates on a timer.
     19
     20        * platform/graphics/TiledBacking.h:
     21        * platform/graphics/ca/GraphicsLayerCA.cpp:
     22        (WebCore::GraphicsLayerCA::adjustCoverageRect):
     23        * platform/graphics/ca/TileController.cpp:
     24        (WebCore::TileController::setVisibleRect):
     25        (WebCore::TileController::setTiledScrollingIndicatorPosition):
     26        (WebCore::expandRectWithinRect):
     27        (WebCore::TileController::adjustTileCoverageRect):
     28        (WebCore::TileController::updateTileCoverageMap):
     29        (WebCore::TileController::computeTileCoverageRect): Deleted.
     30        * platform/graphics/ca/TileController.h:
     31        * platform/graphics/ca/TileCoverageMap.cpp:
     32        (WebCore::TileCoverageMap::TileCoverageMap):
     33        (WebCore::TileCoverageMap::setNeedsUpdate):
     34        (WebCore::TileCoverageMap::updateTimerFired):
     35        * platform/graphics/ca/TileCoverageMap.h:
     36
    1372016-01-05  Antti Koivisto  <antti@apple.com>
    238
  • trunk/Source/WebCore/platform/graphics/TiledBacking.h

    r190998 r194607  
    111111    virtual TileCoverage tileCoverage() const = 0;
    112112
    113     virtual FloatRect computeTileCoverageRect(const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) const = 0;
     113    virtual void adjustTileCoverageRect(FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) const = 0;
    114114
    115115    virtual IntSize tileSize() const = 0;
  • trunk/Source/WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

    r193382 r194607  
    3333#include "GraphicsLayerFactory.h"
    3434#include "Image.h"
     35#include "Logging.h"
    3536#include "PlatformCAFilters.h"
    3637#include "PlatformCALayer.h"
     
    12441245    switch (type()) {
    12451246    case Type::PageTiledBacking:
    1246         coverageRect = tiledBacking()->computeTileCoverageRect(size(), oldVisibleRect, rects.visibleRect, pageScaleFactor() * deviceScaleFactor());
     1247        tiledBacking()->adjustTileCoverageRect(coverageRect, size(), oldVisibleRect, rects.visibleRect, pageScaleFactor() * deviceScaleFactor());
    12471248        break;
    12481249    case Type::Normal:
  • trunk/Source/WebCore/platform/graphics/ca/TileController.cpp

    r194496 r194607  
    2828
    2929#include "IntRect.h"
     30#include "Logging.h"
    3031#include "PlatformCALayer.h"
    3132#include "Region.h"
     33#include "TextStream.h"
    3234#include "TileCoverageMap.h"
    3335#include "TileGrid.h"
     
    186188void TileController::setVisibleRect(const FloatRect& rect)
    187189{
     190    if (rect == m_visibleRect)
     191        return;
     192
    188193    m_visibleRect = rect;
     194    updateTileCoverageMap();
    189195}
    190196
     
    226232    if (!m_coverageMap)
    227233        return;
     234
    228235    m_coverageMap->setPosition(position);
    229     m_coverageMap->update();
     236    updateTileCoverageMap();
    230237}
    231238
     
    315322}
    316323
    317 FloatRect TileController::computeTileCoverageRect(const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& visibleRect, float contentsScale) const
     324#if !PLATFORM(IOS)
     325// Return 'rect' padded evenly on all sides to achieve 'newSize', but make the padding uneven to contain within constrainingRect.
     326static FloatRect expandRectWithinRect(const FloatRect& rect, const FloatSize& newSize, const FloatRect& constrainingRect)
     327{
     328    ASSERT(newSize.width() >= rect.width() && newSize.height() >= rect.height());
     329
     330    FloatSize extraSize = newSize - rect.size();
     331   
     332    FloatRect expandedRect = rect;
     333    expandedRect.inflateX(extraSize.width() / 2);
     334    expandedRect.inflateY(extraSize.height() / 2);
     335
     336    if (expandedRect.x() < constrainingRect.x())
     337        expandedRect.setX(constrainingRect.x());
     338    else if (expandedRect.maxX() > constrainingRect.maxX())
     339        expandedRect.setX(constrainingRect.maxX() - expandedRect.width());
     340   
     341    if (expandedRect.y() < constrainingRect.y())
     342        expandedRect.setY(constrainingRect.y());
     343    else if (expandedRect.maxY() > constrainingRect.maxY())
     344        expandedRect.setY(constrainingRect.maxY() - expandedRect.height());
     345   
     346    return intersection(expandedRect, constrainingRect);
     347}
     348#endif
     349
     350void TileController::adjustTileCoverageRect(FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& visibleRect, float contentsScale) const
    318351{
    319352    // If the page is not in a window (for example if it's in a background tab), we limit the tile coverage rect to the visible rect.
    320     if (!m_isInWindow)
    321         return visibleRect;
     353    if (!m_isInWindow) {
     354        coverageRect = visibleRect;
     355        return;
     356    }
    322357
    323358#if PLATFORM(IOS)
     
    325360    UNUSED_PARAM(previousVisibleRect);
    326361   
    327     if (m_tileCoverage == CoverageForVisibleArea || MemoryPressureHandler::singleton().isUnderMemoryPressure())
    328         return visibleRect;
     362    if (m_tileCoverage == CoverageForVisibleArea || MemoryPressureHandler::singleton().isUnderMemoryPressure()) {
     363        coverageRect = visibleRect;
     364        return;
     365    }
    329366
    330367    double horizontalMargin = tileSize().width() / contentsScale;
     
    352389
    353390    if (!m_velocity.horizontalVelocity && !m_velocity.verticalVelocity) {
    354         if (m_velocity.scaleChangeRate > 0)
    355             return visibleRect;
     391        if (m_velocity.scaleChangeRate > 0) {
     392            coverageRect = visibleRect;
     393            return;
     394        }
    356395        futureRect.setWidth(futureRect.width() + horizontalMargin);
    357396        futureRect.setHeight(futureRect.height() + verticalMargin);
     
    372411        futureRect.setY(0);
    373412
    374     return futureRect;
     413    coverageRect.unite(futureRect);
     414    return;
    375415#else
    376416    UNUSED_PARAM(contentsScale);
    377417
    378418    // FIXME: look at how far the document can scroll in each dimension.
    379     float coverageHorizontalSize = visibleRect.width();
    380     float coverageVerticalSize = visibleRect.height();
     419    FloatSize coverageSize = visibleRect.size();
    381420
    382421    bool largeVisibleRectChange = !previousVisibleRect.isEmpty() && !visibleRect.intersects(previousVisibleRect);
     
    385424    // These values were chosen because it's more common to have tall pages and to scroll vertically,
    386425    // so we keep more tiles above and below the current area.
     426    float widthScale = 1;
     427    float heightScale = 1;
    387428
    388429    if (m_tileCoverage & CoverageForHorizontalScrolling && !largeVisibleRectChange)
    389         coverageHorizontalSize *= 2;
     430        widthScale = 2;
    390431
    391432    if (m_tileCoverage & CoverageForVerticalScrolling && !largeVisibleRectChange)
    392         coverageVerticalSize *= 3;
    393 
    394     coverageVerticalSize += topMarginHeight() + bottomMarginHeight();
    395     coverageHorizontalSize += leftMarginWidth() + rightMarginWidth();
    396 
    397     // Can't use m_tileCacheLayer->bounds() here, because the size of the underlying platform layer
    398     // hasn't been updated for the current commit.
     433        heightScale = 3;
     434   
     435    coverageSize.scale(widthScale, heightScale);
     436
    399437    FloatRect coverageBounds = boundsForSize(newSize);
    400     float coverageLeft = visibleRect.x() - (coverageHorizontalSize - visibleRect.width()) / 2;
    401     coverageLeft = std::min(coverageLeft, coverageBounds.maxX() - coverageHorizontalSize);
    402     coverageLeft = std::max(coverageLeft, coverageBounds.x());
    403 
    404     float coverageTop = visibleRect.y() - (coverageVerticalSize - visibleRect.height()) / 2;
    405     coverageTop = std::min(coverageTop, coverageBounds.maxY() - coverageVerticalSize);
    406     coverageTop = std::max(coverageTop, coverageBounds.y());
    407 
    408     return FloatRect(coverageLeft, coverageTop, coverageHorizontalSize, coverageVerticalSize);
     438   
     439    FloatRect coverage = expandRectWithinRect(visibleRect, coverageSize, coverageBounds);
     440    LOG_WITH_STREAM(Scrolling, stream << "TileController::computeTileCoverageRect newSize=" << newSize << " mode " << m_tileCoverage << " expanded to " << coverageSize << " bounds with margin " << coverageBounds << " coverage " << coverage);
     441    coverageRect.unite(coverage);
    409442#endif
    410443}
     
    501534{
    502535    if (m_coverageMap)
    503         m_coverageMap->update();
     536        m_coverageMap->setNeedsUpdate();
    504537}
    505538
  • trunk/Source/WebCore/platform/graphics/ca/TileController.h

    r190998 r194607  
    107107    virtual int rightMarginWidth() const override;
    108108    virtual TileCoverage tileCoverage() const override { return m_tileCoverage; }
    109     virtual FloatRect computeTileCoverageRect(const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) const override;
     109    virtual void adjustTileCoverageRect(FloatRect& coverageRect, const FloatSize& newSize, const FloatRect& previousVisibleRect, const FloatRect& currentVisibleRect, float contentsScale) const override;
    110110    virtual bool unparentsOffscreenTiles() const override { return m_unparentsOffscreenTiles; }
    111111    virtual bool scrollingPerformanceLoggingEnabled() const override { return m_scrollingPerformanceLoggingEnabled; }
  • trunk/Source/WebCore/platform/graphics/ca/TileCoverageMap.cpp

    r190628 r194607  
    3535TileCoverageMap::TileCoverageMap(const TileController& controller)
    3636    : m_controller(controller)
     37    , m_updateTimer(*this, &TileCoverageMap::updateTimerFired)
    3738    , m_layer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeSimpleLayer, this))
    3839    , m_visibleRectIndicatorLayer(*controller.rootLayer().createCompatibleLayer(PlatformCALayer::LayerTypeLayer, nullptr))
     
    4748    m_layer.get().setContentsScale(m_controller.deviceScaleFactor());
    4849
     50    m_visibleRectIndicatorLayer.get().setName("visible rect indicator");
    4951    m_visibleRectIndicatorLayer.get().setBorderWidth(2);
    5052    m_visibleRectIndicatorLayer.get().setAnchorPoint(FloatPoint3D());
    5153    m_visibleRectIndicatorLayer.get().setBorderColor(Color(255, 0, 0));
    5254   
     55    m_coverageRectIndicatorLayer.get().setName("coverage indicator");
    5356    m_coverageRectIndicatorLayer.get().setBorderWidth(2);
    5457    m_coverageRectIndicatorLayer.get().setAnchorPoint(FloatPoint3D());
     
    6467{
    6568    m_layer.get().setOwner(nullptr);
     69}
     70
     71void TileCoverageMap::setNeedsUpdate()
     72{
     73    if (!m_updateTimer.isActive())
     74        m_updateTimer.startOneShot(0);
     75}
     76
     77void TileCoverageMap::updateTimerFired()
     78{
     79    update();
    6680}
    6781
  • trunk/Source/WebCore/platform/graphics/ca/TileCoverageMap.h

    r183354 r194607  
    3131#include "PlatformCALayer.h"
    3232#include "PlatformCALayerClient.h"
     33#include "Timer.h"
    3334#include <wtf/Noncopyable.h>
    3435#include <wtf/RetainPtr.h>
     
    5455    void setDeviceScaleFactor(float);
    5556
     57    void setNeedsUpdate();
     58
    5659private:
    5760    // PlatformCALayerClient
     
    6265    virtual float platformCALayerDeviceScaleFactor() const override;
    6366
     67    void updateTimerFired();
     68   
    6469    const TileController& m_controller;
     70   
     71    Timer m_updateTimer;
    6572
    6673    Ref<PlatformCALayer> m_layer;
Note: See TracChangeset for help on using the changeset viewer.