Changeset 119736 in webkit


Ignore:
Timestamp:
Jun 7, 2012, 10:57:00 AM (13 years ago)
Author:
Simon Fraser
Message:

Optimize FrameView::scrollXForFixedPosition() / scrollYForFixedPosition()
https://bugs.webkit.org/show_bug.cgi?id=88475

Reviewed by Sam Weinig.

FrameView's scrollXForFixedPosition() and scrollYForFixedPosition()
methods were often called together, but they do duplicate work,
including calling into platform widget code which might be slow.

Fix by converting scrollOffsetForFixedPosition() from being a wrapper
that just calls scrollXForFixedPosition() and scrollYForFixedPosition()
to the method that does all the work, calling just once into platform
widget code.

Changed callers to use scrollOffsetForFixedPosition() rather than make
two separate method calls.

Added ScrollView::layoutSize() and visibleSize() methods for
convenience.

Removed FrameView::scrollXForFixedPosition and FrameView::scrollYForFixedPosition
to avoid inefficient callers in future.

No new tests; refactoring only.

  • page/FrameView.cpp:

(WebCore::fixedPositionScrollOffset):
(WebCore::FrameView::scrollOffsetForFixedPosition):

  • page/FrameView.h: Removed scrollXForFixedPosition and scrollYForFixedPosition.
  • platform/ScrollView.cpp:

(WebCore::ScrollView::layoutSize):

  • platform/ScrollView.h:

(WebCore::ScrollView::visibleSize):

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::backgroundClipRect):

  • rendering/RenderLayer.h:

(WebCore::ClipRect::move):

  • rendering/RenderLayerCompositor.cpp:

(WebCore::RenderLayerCompositor::requiresCompositingForPosition):

  • rendering/RenderView.cpp:

(WebCore::RenderView::computeRectForRepaint):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r119733 r119736  
     12012-06-07  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Optimize FrameView::scrollXForFixedPosition() / scrollYForFixedPosition()
     4        https://bugs.webkit.org/show_bug.cgi?id=88475
     5
     6        Reviewed by Sam Weinig.
     7       
     8        FrameView's scrollXForFixedPosition() and scrollYForFixedPosition()
     9        methods were often called together, but they do duplicate work,
     10        including calling into platform widget code which might be slow.
     11       
     12        Fix by converting scrollOffsetForFixedPosition() from being a wrapper
     13        that just calls scrollXForFixedPosition() and scrollYForFixedPosition()
     14        to the method that does all the work, calling just once into platform
     15        widget code.
     16       
     17        Changed callers to use scrollOffsetForFixedPosition() rather than make
     18        two separate method calls.
     19       
     20        Added ScrollView::layoutSize() and visibleSize() methods for
     21        convenience.
     22       
     23        Removed FrameView::scrollXForFixedPosition and FrameView::scrollYForFixedPosition
     24        to avoid inefficient callers in future.
     25
     26        No new tests; refactoring only.
     27
     28        * page/FrameView.cpp:
     29        (WebCore::fixedPositionScrollOffset):
     30        (WebCore::FrameView::scrollOffsetForFixedPosition):
     31        * page/FrameView.h: Removed scrollXForFixedPosition and scrollYForFixedPosition.
     32        * platform/ScrollView.cpp:
     33        (WebCore::ScrollView::layoutSize):
     34        * platform/ScrollView.h:
     35        (WebCore::ScrollView::visibleSize):
     36        * rendering/RenderLayer.cpp:
     37        (WebCore::RenderLayer::backgroundClipRect):
     38        * rendering/RenderLayer.h:
     39        (WebCore::ClipRect::move):
     40        * rendering/RenderLayerCompositor.cpp:
     41        (WebCore::RenderLayerCompositor::requiresCompositingForPosition):
     42        * rendering/RenderView.cpp:
     43        (WebCore::RenderView::computeRectForRepaint):
     44
    1452012-06-07  Raymes Khoury  <raymes@chromium.org>
    246
  • trunk/Source/WebCore/page/FrameView.cpp

    r119378 r119736  
    13731373}
    13741374
    1375 int FrameView::scrollXForFixedPosition() const
    1376 {
    1377     int visibleContentWidth = visibleContentRect().width();
    1378     int maxX = contentsWidth() - visibleContentWidth;
    1379 
    1380     if (maxX == 0)
     1375static int fixedPositionScrollOffset(int scrollPosition, int maxValue, int scrollOrigin, float dragFactor)
     1376{
     1377    if (!maxValue)
    13811378        return 0;
    13821379
    1383     int x = scrollX();
    1384 
    1385     if (!scrollOrigin().x()) {
    1386         if (x < 0)
    1387             x = 0;
    1388         else if (x > maxX)
    1389             x = maxX;
     1380    if (!scrollOrigin) {
     1381        if (scrollPosition < 0)
     1382            scrollPosition = 0;
     1383        else if (scrollPosition > maxValue)
     1384            scrollPosition = maxValue;
    13901385    } else {
    1391         if (x > 0)
    1392             x = 0;
    1393         else if (x < -maxX)
    1394             x = -maxX;
    1395     }
    1396 
    1397     if (!m_frame)
    1398         return x;
    1399 
    1400     float frameScaleFactor = m_frame->frameScaleFactor();
    1401 
    1402     // When the page is scaled, the scaled "viewport" with respect to which fixed object are positioned
    1403     // doesn't move as fast as the content view, so that when the content is scrolled all the way to the
    1404     // end, the bottom of the scaled "viewport" touches the bottom of the real viewport.
    1405     float dragFactor = fixedElementsLayoutRelativeToFrame() ? 1 : (contentsWidth() - visibleContentWidth * frameScaleFactor) / maxX;
    1406 
    1407     return x * dragFactor / frameScaleFactor;
    1408 }
    1409 
    1410 int FrameView::scrollYForFixedPosition() const
    1411 {
    1412     int visibleContentHeight = visibleContentRect().height();
    1413 
    1414     int maxY = contentsHeight() - visibleContentHeight;
    1415     if (maxY == 0)
    1416         return 0;
    1417 
    1418     int y = scrollY();
    1419 
    1420     if (!scrollOrigin().y()) {
    1421         if (y < 0)
    1422             y = 0;
    1423         else if (y > maxY)
    1424             y = maxY;
    1425     } else {
    1426         if (y > 0)
    1427             y = 0;
    1428         else if (y < -maxY)
    1429             y = -maxY;
    1430     }
    1431 
    1432     if (!m_frame)
    1433         return y;
    1434 
    1435     float frameScaleFactor = m_frame->frameScaleFactor();
    1436     float dragFactor = fixedElementsLayoutRelativeToFrame() ? 1 : (contentsHeight() - visibleContentHeight * frameScaleFactor) / maxY;
    1437     return y * dragFactor / frameScaleFactor;
     1386        if (scrollPosition > 0)
     1387            scrollPosition = 0;
     1388        else if (scrollPosition < -maxValue)
     1389            scrollPosition = -maxValue;
     1390    }
     1391   
     1392    return scrollPosition * dragFactor;
    14381393}
    14391394
    14401395IntSize FrameView::scrollOffsetForFixedPosition() const
    14411396{
    1442     return IntSize(scrollXForFixedPosition(), scrollYForFixedPosition());
     1397    IntRect visibleContentRect = this->visibleContentRect();
     1398    IntSize contentsSize = this->contentsSize();
     1399    IntPoint scrollPosition = this->scrollPosition();
     1400    IntPoint scrollOrigin = this->scrollOrigin();
     1401   
     1402    IntSize maxOffset(contentsSize.width() - visibleContentRect.width(), contentsSize.height() - visibleContentRect.height());
     1403   
     1404    float frameScaleFactor = m_frame ? m_frame->frameScaleFactor() : 1;
     1405
     1406    FloatSize dragFactor = fixedElementsLayoutRelativeToFrame() ? FloatSize(1, 1) : FloatSize(
     1407        (contentsSize.width() - visibleContentRect.width() * frameScaleFactor) / maxOffset.width(),
     1408        (contentsSize.height() - visibleContentRect.height() * frameScaleFactor) / maxOffset.height());
     1409
     1410    int x = fixedPositionScrollOffset(scrollPosition.x(), maxOffset.width(), scrollOrigin.x(), dragFactor.width() / frameScaleFactor);
     1411    int y = fixedPositionScrollOffset(scrollPosition.y(), maxOffset.height(), scrollOrigin.y(), dragFactor.height() / frameScaleFactor);
     1412
     1413    return IntSize(x, y);
    14431414}
    14441415
  • trunk/Source/WebCore/page/FrameView.h

    r116799 r119736  
    201201    // Functions for querying the current scrolled position, negating the effects of overhang
    202202    // and adjusting for page scale.
    203     int scrollXForFixedPosition() const;
    204     int scrollYForFixedPosition() const;
    205203    IntSize scrollOffsetForFixedPosition() const;
    206204
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r117069 r119736  
    253253#endif
    254254
     255IntSize ScrollView::layoutSize() const
     256{
     257    return m_fixedLayoutSize.isEmpty() || !m_useFixedLayout ? visibleSize() : m_fixedLayoutSize;
     258}
     259
    255260int ScrollView::layoutWidth() const
    256261{
  • trunk/Source/WebCore/platform/ScrollView.h

    r117069 r119736  
    147147    virtual void setFixedVisibleContentRect(const IntRect& visibleContentRect) { m_fixedVisibleContentRect = visibleContentRect; }
    148148    IntRect fixedVisibleContentRect() const { return m_fixedVisibleContentRect; }
     149    IntSize visibleSize() const { return visibleContentRect().size(); }
    149150    int visibleWidth() const { return visibleContentRect().width(); }
    150151    int visibleHeight() const { return visibleContentRect().height(); }
     
    152153    // Functions for getting/setting the size webkit should use to layout the contents. By default this is the same as the visible
    153154    // content size. Explicitly setting a layout size value will cause webkit to layout the contents using this size instead.
     155    IntSize layoutSize() const;
    154156    int layoutWidth() const;
    155157    int layoutHeight() const;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r119676 r119736  
    39033903    // Note: infinite clipRects should not be scrolled here, otherwise they will accidentally no longer be considered infinite.
    39043904    if (parentRects.fixed() && rootLayer->renderer() == view && backgroundClipRect != PaintInfo::infiniteRect())
    3905         backgroundClipRect.move(view->frameView()->scrollXForFixedPosition(), view->frameView()->scrollYForFixedPosition());
     3905        backgroundClipRect.move(view->frameView()->scrollOffsetForFixedPosition());
    39063906
    39073907    return backgroundClipRect;
  • trunk/Source/WebCore/rendering/RenderLayer.h

    r119676 r119736  
    112112    }
    113113    void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); }
     114    void move(const LayoutSize& size) { m_rect.move(size); }
    114115
    115116    bool isEmpty() const { return m_rect.isEmpty(); }
  • trunk/Source/WebCore/rendering/RenderLayerCompositor.cpp

    r119529 r119736  
    18051805    // Fixed position elements that are invisible in the current view don't get their own layer.
    18061806    FrameView* frameView = m_renderView->frameView();
    1807     if (frameView && !layer->absoluteBoundingBox().intersects(IntRect(frameView->scrollXForFixedPosition(), frameView->scrollYForFixedPosition(), frameView->layoutWidth(), frameView->layoutHeight())))
     1807    if (frameView && !layer->absoluteBoundingBox().intersects(IntRect(IntPoint(frameView->scrollOffsetForFixedPosition()), frameView->layoutSize())))
    18081808        return false;
    18091809
  • trunk/Source/WebCore/rendering/RenderView.cpp

    r119548 r119736  
    391391
    392392    if (fixed && m_frameView)
    393         rect.move(m_frameView->scrollXForFixedPosition(), m_frameView->scrollYForFixedPosition());
     393        rect.move(m_frameView->scrollOffsetForFixedPosition());
    394394       
    395395    // Apply our transform if we have one (because of full page zooming).
Note: See TracChangeset for help on using the changeset viewer.