Changeset 96454 in webkit


Ignore:
Timestamp:
Sep 30, 2011 8:15:10 PM (13 years ago)
Author:
enne@google.com
Message:

[chromium] Track separate scroll deltas on the compositor thread
https://bugs.webkit.org/show_bug.cgi?id=69034

Reviewed by James Robinson.

Source/WebCore:

Test: new tests in CCLayerTreeHostImplTest/CCLayerTreeHostTest

Track scroll deltas and maximum scrolls on LayerChromium/CCLayerImpl.
The CCLayerImpl tree is now able to adjust these scroll deltas
independent of the main thread. To push them back to the main thread,
CCLayerTreeHostImpl collects them all and then bakes them into the
scroll position during a begin frame and commit call. This allows new
deltas to be collected while the scroll position containing the old
delta and the old scroll position will be overwritten during the next
commit.

Only the main frame is supported right now for pushing this scroll
delta back into the authoritative WebKit source to keep both sides in
sync.

Move tilingTransform() to the impl tree because drawTransform() is now
updated using scroll deltas and so the results from calculating draw
transforms needs to be dynamic so that children are updated properly.

Also, exposed DebugScopedSetImplThread public because it's used in a
few places.

  • platform/graphics/chromium/LayerChromium.cpp:

(WebCore::LayerChromium::pushPropertiesTo):

  • platform/graphics/chromium/LayerChromium.h:

(WebCore::LayerChromium::maxScrollPosition):
(WebCore::LayerChromium::setMaxScrollPosition):
(WebCore::LayerChromium::scrollDelta):
(WebCore::LayerChromium::scrollable):

  • platform/graphics/chromium/NonCompositedContentHost.cpp:

(WebCore::NonCompositedContentHost::setViewport):

  • platform/graphics/chromium/TiledLayerChromium.cpp:

(WebCore::TiledLayerChromium::pushPropertiesTo):

  • platform/graphics/chromium/TiledLayerChromium.h:
  • platform/graphics/chromium/cc/CCLayerImpl.cpp:

(WebCore::CCLayerImpl::scrollBy):

  • platform/graphics/chromium/cc/CCLayerImpl.h:

(WebCore::CCLayerImpl::maxScrollPosition):
(WebCore::CCLayerImpl::setMaxScrollPosition):
(WebCore::CCLayerImpl::scrollDelta):
(WebCore::CCLayerImpl::setScrollDelta):
(WebCore::CCLayerImpl::scrollable):

  • platform/graphics/chromium/cc/CCLayerTreeHost.cpp:

(WebCore::CCLayerTreeHost::applyScrollDeltas):

  • platform/graphics/chromium/cc/CCLayerTreeHost.h:
  • platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp:

(WebCore::calculateDrawTransformsAndVisibilityInternal):

  • platform/graphics/chromium/cc/CCLayerTreeHostCommon.h:
  • platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:

(WebCore::CCLayerTreeHostImpl::scrollRootLayer):
(WebCore::CCLayerTreeHostImpl::processScrollDeltas):

  • platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
  • platform/graphics/chromium/cc/CCProxy.h:
  • platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:

(WebCore::CCSingleThreadProxy::start):
(WebCore::CCSingleThreadProxy::context):
(WebCore::CCSingleThreadProxy::finishAllRendering):
(WebCore::CCSingleThreadProxy::initializeLayerRenderer):
(WebCore::CCSingleThreadProxy::setNeedsCommit):
(WebCore::CCSingleThreadProxy::stop):
(WebCore::CCSingleThreadProxy::recreateContextIfNeeded):
(WebCore::CCSingleThreadProxy::commitIfNeeded):
(WebCore::CCSingleThreadProxy::doComposite):

  • platform/graphics/chromium/cc/CCSingleThreadProxy.h:

(WebCore::DebugScopedSetImplThread::DebugScopedSetImplThread):
(WebCore::DebugScopedSetImplThread::~DebugScopedSetImplThread):

  • platform/graphics/chromium/cc/CCThreadProxy.cpp:

(WebCore::CCThreadProxy::createBeginFrameAndCommitTaskOnCCThread):
(WebCore::CCThreadProxy::beginFrameAndCommit):

  • platform/graphics/chromium/cc/CCThreadProxy.h:
  • platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:

(WebCore::CCTiledLayerImpl::tilingTransform):
(WebCore::CCTiledLayerImpl::draw):

  • platform/graphics/chromium/cc/CCTiledLayerImpl.h:

Source/WebKit/chromium:

Add testing support for scroll deltas on layers.

  • WebKit.gypi:
  • src/WebViewImpl.cpp:

(WebKit::WebViewImpl::applyScrollDelta):

  • src/WebViewImpl.h:
  • tests/CCLayerTreeHostImplTest.cpp: Added.

(WebCore::CCLayerTreeHostImplTest::CCLayerTreeHostImplTest):
(WebCore::CCLayerTreeHostImplTest::expectClearedScrollDeltasRecursive):
(WebCore::CCLayerTreeHostImplTest::expectContains):
(WebCore::TEST_F):

  • tests/CCLayerTreeHostTest.cpp:

(WTF::TestHooks::applyScrollDelta):
(WTF::MockLayerTreeHostClient::applyScrollDelta):
(WTF::CCLayerTreeHostTest::runTest):
(WTF::CCLayerTreeHostTest::doBeginTest):
(WTF::CCLayerTreeHostTestThreadOnly::runTest):
(WTF::CCLayerTreeHostTestScrollSimple::CCLayerTreeHostTestScrollSimple):
(WTF::CCLayerTreeHostTestScrollSimple::beginTest):
(WTF::CCLayerTreeHostTestScrollSimple::beginCommitOnCCThread):
(WTF::CCLayerTreeHostTestScrollSimple::drawLayersOnCCThread):
(WTF::CCLayerTreeHostTestScrollSimple::applyScrollDelta):
(WTF::CCLayerTreeHostTestScrollSimple::afterTest):
(WTF::TEST_F):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::CCLayerTreeHostTestScrollMultipleRedraw):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::beginTest):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::beginCommitOnCCThread):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::drawLayersOnCCThread):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::applyScrollDelta):
(WTF::CCLayerTreeHostTestScrollMultipleRedraw::afterTest):

  • tests/TreeSynchronizerTest.cpp:

(WebCore::TEST):

Location:
trunk/Source
Files:
1 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96452 r96454  
     12011-09-30  Adrienne Walker  <enne@google.com>
     2
     3        [chromium] Track separate scroll deltas on the compositor thread
     4        https://bugs.webkit.org/show_bug.cgi?id=69034
     5
     6        Reviewed by James Robinson.
     7
     8        Test: new tests in CCLayerTreeHostImplTest/CCLayerTreeHostTest
     9
     10        Track scroll deltas and maximum scrolls on LayerChromium/CCLayerImpl.
     11        The CCLayerImpl tree is now able to adjust these scroll deltas
     12        independent of the main thread. To push them back to the main thread,
     13        CCLayerTreeHostImpl collects them all and then bakes them into the
     14        scroll position during a begin frame and commit call. This allows new
     15        deltas to be collected while the scroll position containing the old
     16        delta and the old scroll position will be overwritten during the next
     17        commit.
     18
     19        Only the main frame is supported right now for pushing this scroll
     20        delta back into the authoritative WebKit source to keep both sides in
     21        sync.
     22
     23        Move tilingTransform() to the impl tree because drawTransform() is now
     24        updated using scroll deltas and so the results from calculating draw
     25        transforms needs to be dynamic so that children are updated properly.
     26
     27        Also, exposed DebugScopedSetImplThread public because it's used in a
     28        few places.
     29
     30        * platform/graphics/chromium/LayerChromium.cpp:
     31        (WebCore::LayerChromium::pushPropertiesTo):
     32        * platform/graphics/chromium/LayerChromium.h:
     33        (WebCore::LayerChromium::maxScrollPosition):
     34        (WebCore::LayerChromium::setMaxScrollPosition):
     35        (WebCore::LayerChromium::scrollDelta):
     36        (WebCore::LayerChromium::scrollable):
     37        * platform/graphics/chromium/NonCompositedContentHost.cpp:
     38        (WebCore::NonCompositedContentHost::setViewport):
     39        * platform/graphics/chromium/TiledLayerChromium.cpp:
     40        (WebCore::TiledLayerChromium::pushPropertiesTo):
     41        * platform/graphics/chromium/TiledLayerChromium.h:
     42        * platform/graphics/chromium/cc/CCLayerImpl.cpp:
     43        (WebCore::CCLayerImpl::scrollBy):
     44        * platform/graphics/chromium/cc/CCLayerImpl.h:
     45        (WebCore::CCLayerImpl::maxScrollPosition):
     46        (WebCore::CCLayerImpl::setMaxScrollPosition):
     47        (WebCore::CCLayerImpl::scrollDelta):
     48        (WebCore::CCLayerImpl::setScrollDelta):
     49        (WebCore::CCLayerImpl::scrollable):
     50        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
     51        (WebCore::CCLayerTreeHost::applyScrollDeltas):
     52        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
     53        * platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp:
     54        (WebCore::calculateDrawTransformsAndVisibilityInternal):
     55        * platform/graphics/chromium/cc/CCLayerTreeHostCommon.h:
     56        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
     57        (WebCore::CCLayerTreeHostImpl::scrollRootLayer):
     58        (WebCore::CCLayerTreeHostImpl::processScrollDeltas):
     59        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
     60        * platform/graphics/chromium/cc/CCProxy.h:
     61        * platform/graphics/chromium/cc/CCSingleThreadProxy.cpp:
     62        (WebCore::CCSingleThreadProxy::start):
     63        (WebCore::CCSingleThreadProxy::context):
     64        (WebCore::CCSingleThreadProxy::finishAllRendering):
     65        (WebCore::CCSingleThreadProxy::initializeLayerRenderer):
     66        (WebCore::CCSingleThreadProxy::setNeedsCommit):
     67        (WebCore::CCSingleThreadProxy::stop):
     68        (WebCore::CCSingleThreadProxy::recreateContextIfNeeded):
     69        (WebCore::CCSingleThreadProxy::commitIfNeeded):
     70        (WebCore::CCSingleThreadProxy::doComposite):
     71        * platform/graphics/chromium/cc/CCSingleThreadProxy.h:
     72        (WebCore::DebugScopedSetImplThread::DebugScopedSetImplThread):
     73        (WebCore::DebugScopedSetImplThread::~DebugScopedSetImplThread):
     74        * platform/graphics/chromium/cc/CCThreadProxy.cpp:
     75        (WebCore::CCThreadProxy::createBeginFrameAndCommitTaskOnCCThread):
     76        (WebCore::CCThreadProxy::beginFrameAndCommit):
     77        * platform/graphics/chromium/cc/CCThreadProxy.h:
     78        * platform/graphics/chromium/cc/CCTiledLayerImpl.cpp:
     79        (WebCore::CCTiledLayerImpl::tilingTransform):
     80        (WebCore::CCTiledLayerImpl::draw):
     81        * platform/graphics/chromium/cc/CCTiledLayerImpl.h:
     82
    1832011-09-30  David Hyatt  <hyatt@apple.com>
    284
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp

    r95901 r96454  
    289289    layer->setIsNonCompositedContent(m_isNonCompositedContent);
    290290    layer->setMasksToBounds(m_masksToBounds);
     291    layer->setMaxScrollPosition(m_maxScrollPosition);
    291292    layer->setName(m_name);
    292293    layer->setOpacity(m_opacity);
     
    296297    layer->setSublayerTransform(m_sublayerTransform);
    297298    layer->setTransform(m_transform);
    298     layer->setVisibleLayerRect(m_visibleLayerRect);
    299299
    300300    if (maskLayer())
  • trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h

    r96186 r96454  
    131131    void setScrollPosition(const IntPoint& scrollPosition) { m_scrollPosition = scrollPosition; }
    132132
     133    const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
     134    void setMaxScrollPosition(const IntSize& maxScrollPosition) { m_maxScrollPosition = maxScrollPosition; }
     135
     136    IntSize scrollDelta() const { return IntSize(); }
     137
     138    bool scrollable() const { return !maxScrollPosition().isZero(); }
     139
    133140    bool doubleSided() const { return m_doubleSided; }
    134141    void setDoubleSided(bool doubleSided) { m_doubleSided = doubleSided; setNeedsCommit(); }
     
    238245    IntRect m_visibleLayerRect;
    239246    IntPoint m_scrollPosition;
     247    IntSize m_maxScrollPosition;
    240248    FloatPoint m_position;
    241249    FloatPoint m_anchorPoint;
  • trunk/Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp

    r96186 r96454  
    535535        GLC(m_context.get(), m_context->disable(GraphicsContext3D::SCISSOR_TEST));
    536536
     537    IntRect visibleLayerRect = CCLayerTreeHostCommon::calculateVisibleLayerRect(targetSurfaceRect, layer->bounds(), layer->contentBounds(), layer->drawTransform());
     538    visibleLayerRect.move(toSize(layer->scrollPosition()));
     539    layer->setVisibleLayerRect(visibleLayerRect);
     540
    537541    // The layer should not be drawn if (1) it is not double-sided and (2) the back of the layer is facing the screen.
    538542    // This second condition is checked by computing the transformed normal of the layer.
  • trunk/Source/WebCore/platform/graphics/chromium/NonCompositedContentHost.cpp

    r95901 r96454  
    6666    m_viewportSize = viewportSize;
    6767    m_graphicsLayer->platformLayer()->setScrollPosition(scrollPosition);
     68    IntSize maxScroll = contentsSize - viewportSize;
     69    // The viewport may be larger than the contents in some cases, such as
     70    // having a vertical scrollbar but no horizontal overflow.
     71    maxScroll.clampNegativeToZero();
     72
     73    m_graphicsLayer->platformLayer()->setMaxScrollPosition(maxScroll);
    6874    m_graphicsLayer->setSize(contentsSize);
    6975
     
    107113
    108114} // namespace WebCore
    109 
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp

    r96186 r96454  
    221221}
    222222
    223 TransformationMatrix TiledLayerChromium::tilingTransform() const
    224 {
    225     TransformationMatrix transform = drawTransform();
    226 
    227     if (contentBounds().isEmpty())
    228         return transform;
    229 
    230     transform.scaleNonUniform(bounds().width() / static_cast<double>(contentBounds().width()),
    231                               bounds().height() / static_cast<double>(contentBounds().height()));
    232 
    233     // Tiler draws with a different origin from other layers.
    234     transform.translate(-contentBounds().width() / 2.0, -contentBounds().height() / 2.0);
    235 
    236     transform.translate(-scrollPosition().x(), -scrollPosition().y());
    237 
    238     return transform;
    239 }
    240 
    241223void TiledLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
    242224{
     
    249231    }
    250232
    251     tiledLayer->setTilingTransform(tilingTransform());
    252233    tiledLayer->setSkipsDraw(m_skipsDraw);
    253234    tiledLayer->setTextureOrientation(m_textureOrientation);
  • trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h

    r96186 r96454  
    7979    void createTilerIfNeeded();
    8080    void setTilingOption(TilingOption);
    81     TransformationMatrix tilingTransform() const;
    8281
    8382    UpdatableTile* tileAt(int, int) const;
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp

    r96066 r96454  
    119119}
    120120
     121void CCLayerImpl::scrollBy(const IntSize& scroll)
     122{
     123    IntSize newDelta = m_scrollDelta + scroll;
     124    IntSize minDelta = -toSize(m_scrollPosition);
     125    IntSize maxDelta = m_maxScrollPosition - toSize(m_scrollPosition);
     126    // Clamp newDelta so that position + delta stays within scroll bounds.
     127    m_scrollDelta = newDelta.expandedTo(minDelta).shrunkTo(maxDelta);
     128}
     129
    121130void CCLayerImpl::cleanupResources()
    122131{
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h

    r95901 r96454  
    146146    void setScrollPosition(const IntPoint& scrollPosition) { m_scrollPosition = scrollPosition; }
    147147
     148    const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
     149    void setMaxScrollPosition(const IntSize& maxScrollPosition) { m_maxScrollPosition = maxScrollPosition; }
     150
     151    const IntSize& scrollDelta() const { return m_scrollDelta; }
     152    void setScrollDelta(const IntSize& scrollDelta) { m_scrollDelta = scrollDelta; }
     153
     154    void scrollBy(const IntSize& scroll);
     155    bool scrollable() const { return !maxScrollPosition().isZero(); }
     156
    148157    const IntRect& visibleLayerRect() const { return m_visibleLayerRect; }
    149158    void setVisibleLayerRect(const IntRect& visibleLayerRect) { m_visibleLayerRect = visibleLayerRect; }
     
    192201    IntSize m_contentBounds;
    193202    IntPoint m_scrollPosition;
    194     IntRect m_visibleLayerRect;
     203    IntSize m_maxScrollPosition;
    195204
    196205    // Whether the "back" of this layer should draw.
    197206    bool m_doubleSided;
    198207
     208    IntRect m_visibleLayerRect;
    199209    bool m_masksToBounds;
    200210    float m_opacity;
     
    208218    bool m_drawsContent;
    209219
     220    IntSize m_scrollDelta;
     221
    210222    // Properties owned exclusively by this CCLayerImpl.
    211223    // Debugging.
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp

    r96392 r96454  
    416416}
    417417
    418 }
     418void CCLayerTreeHost::applyScrollDeltas(const CCScrollUpdateSet& info)
     419{
     420    for (size_t i = 0; i < info.size(); ++i) {
     421        int layerId = info[i].layerId;
     422        IntSize scrollDelta = info[i].scrollDelta;
     423
     424        // FIXME: pushing scroll offsets to non-root layers not implemented
     425        if (rootLayer()->id() == layerId)
     426            m_client->applyScrollDelta(scrollDelta);
     427        else
     428            ASSERT_NOT_REACHED();
     429    }
     430}
     431
     432}
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h

    r96392 r96454  
    2929#include "IntRect.h"
    3030#include "TransformationMatrix.h"
     31#include "cc/CCLayerTreeHostCommon.h"
    3132#include "cc/CCProxy.h"
    3233
     
    5152public:
    5253    virtual void animateAndLayout(double frameBeginTime) = 0;
     54    virtual void applyScrollDelta(const IntSize&) = 0;
    5355    virtual PassRefPtr<GraphicsContext3D> createLayerTreeHostContext3D() = 0;
    5456    virtual void didRecreateGraphicsContext(bool success) = 0;
     
    151153    void updateLayers();
    152154
     155    void applyScrollDeltas(const CCScrollUpdateSet&);
    153156protected:
    154157    CCLayerTreeHost(CCLayerTreeHostClient*, PassRefPtr<LayerChromium> rootLayer, const CCSettings&);
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp

    r95901 r96454  
    112112    IntSize bounds = layer->bounds();
    113113    FloatPoint anchorPoint = layer->anchorPoint();
    114     FloatPoint position = layer->position();
     114    FloatPoint position = layer->position() - layer->scrollDelta();
    115115
    116116    // Offset between anchor point and the center of the quad.
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommon.h

    r95901 r96454  
    2626#define CCLayerTreeHostCommon_h
    2727
     28#include "IntSize.h"
    2829#include <wtf/RefPtr.h>
    2930#include <wtf/Vector.h>
     
    3435class CCLayerSorter;
    3536class IntRect;
    36 class IntSize;
    3737class LayerChromium;
    3838class TransformationMatrix;
     
    4747    static void calculateDrawTransformsAndVisibility(CCLayerImpl*, CCLayerImpl* rootLayer, const TransformationMatrix& parentMatrix, const TransformationMatrix& fullHierarchyMatrix, Vector<RefPtr<CCLayerImpl> >& renderSurfaceLayerList, Vector<RefPtr<CCLayerImpl> >& layerList, CCLayerSorter*, int maxTextureSize);
    4848
     49    struct ScrollUpdateInfo {
     50        int layerId;
     51        IntSize scrollDelta;
     52    };
    4953};
     54
     55typedef Vector<CCLayerTreeHostCommon::ScrollUpdateInfo> CCScrollUpdateSet;
    5056
    5157} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp

    r96186 r96454  
    160160}
    161161
     162void CCLayerTreeHostImpl::scrollRootLayer(const IntSize& scrollDelta)
     163{
     164    if (!m_rootLayerImpl || !m_rootLayerImpl->scrollable())
     165        return;
     166
     167    m_rootLayerImpl->scrollBy(scrollDelta);
    162168}
     169
     170PassOwnPtr<CCScrollUpdateSet> CCLayerTreeHostImpl::processScrollDeltas()
     171{
     172    OwnPtr<CCScrollUpdateSet> scrollInfo = adoptPtr(new CCScrollUpdateSet());
     173    // FIXME: track scrolls from layers other than the root
     174    if (rootLayer() && !rootLayer()->scrollDelta().isZero()) {
     175        CCLayerTreeHostCommon::ScrollUpdateInfo info;
     176        info.layerId = rootLayer()->id();
     177        info.scrollDelta = rootLayer()->scrollDelta();
     178        scrollInfo->append(info);
     179
     180        rootLayer()->setScrollPosition(rootLayer()->scrollPosition() + rootLayer()->scrollDelta());
     181        rootLayer()->setScrollDelta(IntSize());
     182    }
     183    return scrollInfo.release();
     184}
     185
     186}
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h

    r96186 r96454  
    2727
    2828#include "cc/CCLayerTreeHost.h"
     29#include "cc/CCLayerTreeHostCommon.h"
    2930#include <wtf/RefPtr.h>
    3031
     
    8283
    8384    const CCSettings& settings() const { return m_settings; }
     85
     86    void scrollRootLayer(const IntSize&);
     87
     88    PassOwnPtr<CCScrollUpdateSet> processScrollDeltas();
     89
    8490protected:
    8591    explicit CCLayerTreeHostImpl(const CCSettings&);
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCProxy.h

    r96066 r96454  
    8989protected:
    9090    CCProxy() { }
    91     friend class ScopedSetImplThread;
     91    friend class DebugScopedSetImplThread;
    9292};
    9393
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp

    r96186 r96454  
    3838namespace WebCore {
    3939
    40 class ScopedSetImplThread {
    41 public:
    42     ScopedSetImplThread()
    43     {
    44 #ifndef NDEBUG
    45         ASSERT(CCProxy::isMainThread());
    46         CCProxy::setImplThread(true);
    47 #endif
    48     }
    49     ~ScopedSetImplThread()
    50     {
    51 #ifndef NDEBUG
    52         CCProxy::setImplThread(false);
    53 #endif
    54     }
    55 };
    56 
    5740PassOwnPtr<CCProxy> CCSingleThreadProxy::create(CCLayerTreeHost* layerTreeHost)
    5841{
     
    7255void CCSingleThreadProxy::start()
    7356{
    74     ScopedSetImplThread impl;
     57    DebugScopedSetImplThread impl;
    7558    m_layerTreeHostImpl = m_layerTreeHost->createLayerTreeHostImpl();
    7659}
     
    10689{
    10790    ASSERT(CCProxy::isMainThread());
    108     ScopedSetImplThread impl;
     91    DebugScopedSetImplThread impl;
    10992    return m_layerTreeHostImpl->context();
    11093}
     
    11497    ASSERT(CCProxy::isMainThread());
    11598    {
    116         ScopedSetImplThread impl;
     99        DebugScopedSetImplThread impl;
    117100        m_layerTreeHostImpl->finishAllRendering();
    118101    }
     
    134117
    135118    {
    136         ScopedSetImplThread impl;
     119        DebugScopedSetImplThread impl;
    137120        bool ok = m_layerTreeHostImpl->initializeLayerRenderer(context);
    138121        if (ok)
     
    159142    // Commit immediately
    160143    {
    161         ScopedSetImplThread impl;
     144        DebugScopedSetImplThread impl;
    162145        m_layerTreeHostImpl->beginCommit();
    163146        m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get());
    164147        m_layerTreeHostImpl->commitComplete();
     148
     149#if !ASSERT_DISABLED
     150        // In the single-threaded case, the scroll deltas should never be
     151        // touched on the impl layer tree.
     152        OwnPtr<CCScrollUpdateSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
     153        ASSERT(!scrollInfo->size());
     154#endif
    165155    }
    166156    m_layerTreeHost->commitComplete();
     
    190180    ASSERT(CCProxy::isMainThread());
    191181    {
    192         ScopedSetImplThread impl;
     182        DebugScopedSetImplThread impl;
    193183        m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator());
    194184        m_layerTreeHostImpl.clear();
     
    227217        bool ok;
    228218        {
    229             ScopedSetImplThread impl;
     219            DebugScopedSetImplThread impl;
    230220            m_layerTreeHost->deleteContentsTexturesOnCCThread(m_layerTreeHostImpl->contentsTextureAllocator());
    231221            ok = m_layerTreeHostImpl->initializeLayerRenderer(context);
     
    263253    // Commit
    264254    {
    265         ScopedSetImplThread impl;
     255        DebugScopedSetImplThread impl;
    266256        m_layerTreeHostImpl->beginCommit();
    267257        m_layerTreeHost->commitToOnCCThread(m_layerTreeHostImpl.get());
     
    276266
    277267    {
    278       ScopedSetImplThread impl;
     268      DebugScopedSetImplThread impl;
    279269      m_layerTreeHostImpl->drawLayers();
    280270      if (m_layerTreeHostImpl->isContextLost()) {
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.h

    r96066 r96454  
    7777};
    7878
    79 }
     79// For use in the single-threaded case. In debug builds, it pretends that the
     80// code is running on the thread to satisfy assertion checks.
     81class DebugScopedSetImplThread {
     82public:
     83    DebugScopedSetImplThread()
     84    {
     85#if !ASSERT_DISABLED
     86        ASSERT(CCProxy::isMainThread());
     87        CCProxy::setImplThread(true);
     88#endif
     89    }
     90    ~DebugScopedSetImplThread()
     91    {
     92#if !ASSERT_DISABLED
     93        CCProxy::setImplThread(false);
     94#endif
     95    }
     96};
     97
     98} // namespace WebCore
    8099
    81100#endif
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp

    r96392 r96454  
    280280    int thisTaskSequenceNumber = m_numBeginFrameAndCommitsIssuedOnCCThread;
    281281    m_numBeginFrameAndCommitsIssuedOnCCThread++;
    282     return createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, thisTaskSequenceNumber, frameBeginTime);
    283 }
    284 
    285 void CCThreadProxy::beginFrameAndCommit(int sequenceNumber, double frameBeginTime)
     282    OwnPtr<CCScrollUpdateSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
     283    return createMainThreadTask(this, &CCThreadProxy::beginFrameAndCommit, thisTaskSequenceNumber, frameBeginTime, scrollInfo.release());
     284}
     285
     286void CCThreadProxy::beginFrameAndCommit(int sequenceNumber, double frameBeginTime, PassOwnPtr<CCScrollUpdateSet> scrollInfo)
    286287{
    287288    TRACE_EVENT("CCThreadProxy::beginFrameAndCommit", this, 0);
     
    289290    if (!m_layerTreeHost)
    290291        return;
     292
     293    // Scroll deltas need to be applied even if the commit will be dropped.
     294    m_layerTreeHost->applyScrollDeltas(*scrollInfo.get());
    291295
    292296    // Drop beginFrameAndCommit calls that occur out of sequence. See createBeginFrameAndCommitTaskOnCCThread for
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.h

    r96392 r96454  
    6363
    6464    // Called on CCMainThread
    65     void beginFrameAndCommit(int sequenceNumber, double frameBeginTime);
     65    void beginFrameAndCommit(int sequenceNumber, double frameBeginTime, PassOwnPtr<CCScrollUpdateSet>);
    6666
    6767    // Called on CCThread
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp

    r95901 r96454  
    9393}
    9494
     95TransformationMatrix CCTiledLayerImpl::tilingTransform() const
     96{
     97    TransformationMatrix transform = drawTransform();
     98
     99    if (contentBounds().isEmpty())
     100        return transform;
     101
     102    transform.scaleNonUniform(bounds().width() / static_cast<double>(contentBounds().width()),
     103                              bounds().height() / static_cast<double>(contentBounds().height()));
     104
     105    // Tiler draws with a different origin from other layers.
     106    transform.translate(-contentBounds().width() / 2.0, -contentBounds().height() / 2.0);
     107
     108    transform.translate(-scrollPosition().x(), -scrollPosition().y());
     109
     110    return transform;
     111}
     112
    95113void CCTiledLayerImpl::draw(LayerRendererChromium* layerRenderer)
    96114{
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.h

    r95901 r96454  
    7070    virtual const char* layerTypeAsString() const { return "ContentLayer"; }
    7171
     72    TransformationMatrix tilingTransform() const;
     73
    7274    // Draw all tiles that intersect with the content rect.
    7375    void draw(LayerRendererChromium*, const IntRect& contentRect, const TransformationMatrix&, float opacity);
  • trunk/Source/WebKit/chromium/ChangeLog

    r96450 r96454  
     12011-09-30  Adrienne Walker  <enne@google.com>
     2
     3        [chromium] Track separate scroll deltas on the compositor thread
     4        https://bugs.webkit.org/show_bug.cgi?id=69034
     5
     6        Reviewed by James Robinson.
     7
     8        Add testing support for scroll deltas on layers.
     9
     10        * WebKit.gypi:
     11        * src/WebViewImpl.cpp:
     12        (WebKit::WebViewImpl::applyScrollDelta):
     13        * src/WebViewImpl.h:
     14        * tests/CCLayerTreeHostImplTest.cpp: Added.
     15        (WebCore::CCLayerTreeHostImplTest::CCLayerTreeHostImplTest):
     16        (WebCore::CCLayerTreeHostImplTest::expectClearedScrollDeltasRecursive):
     17        (WebCore::CCLayerTreeHostImplTest::expectContains):
     18        (WebCore::TEST_F):
     19        * tests/CCLayerTreeHostTest.cpp:
     20        (WTF::TestHooks::applyScrollDelta):
     21        (WTF::MockLayerTreeHostClient::applyScrollDelta):
     22        (WTF::CCLayerTreeHostTest::runTest):
     23        (WTF::CCLayerTreeHostTest::doBeginTest):
     24        (WTF::CCLayerTreeHostTestThreadOnly::runTest):
     25        (WTF::CCLayerTreeHostTestScrollSimple::CCLayerTreeHostTestScrollSimple):
     26        (WTF::CCLayerTreeHostTestScrollSimple::beginTest):
     27        (WTF::CCLayerTreeHostTestScrollSimple::beginCommitOnCCThread):
     28        (WTF::CCLayerTreeHostTestScrollSimple::drawLayersOnCCThread):
     29        (WTF::CCLayerTreeHostTestScrollSimple::applyScrollDelta):
     30        (WTF::CCLayerTreeHostTestScrollSimple::afterTest):
     31        (WTF::TEST_F):
     32        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::CCLayerTreeHostTestScrollMultipleRedraw):
     33        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::beginTest):
     34        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::beginCommitOnCCThread):
     35        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::drawLayersOnCCThread):
     36        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::applyScrollDelta):
     37        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::afterTest):
     38        * tests/TreeSynchronizerTest.cpp:
     39        (WebCore::TEST):
     40
    1412011-09-30  Shawn Singh  <shawnsingh@chromium.org>
    242
  • trunk/Source/WebKit/chromium/WebKit.gypi

    r96450 r96454  
    5757            'tests/CCLayerSorterTest.cpp',
    5858            'tests/CCLayerTreeHostTest.cpp',
     59            'tests/CCLayerTreeHostImplTest.cpp',
    5960            'tests/CCThreadTaskTest.cpp',
    6061            'tests/CCThreadTest.cpp',
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r96392 r96454  
    27052705}
    27062706
     2707void WebViewImpl::applyScrollDelta(const IntSize& scrollDelta)
     2708{
     2709    if (!mainFrameImpl() || !mainFrameImpl()->frameView())
     2710        return;
     2711
     2712    mainFrameImpl()->frameView()->scrollBy(scrollDelta);
     2713}
     2714
    27072715void WebViewImpl::didRecreateGraphicsContext(bool success)
    27082716{
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r96392 r96454  
    220220    // CCLayerTreeHostClient
    221221    virtual void animateAndLayout(double frameBeginTime);
     222    virtual void applyScrollDelta(const WebCore::IntSize&);
    222223    virtual PassRefPtr<WebCore::GraphicsContext3D> createLayerTreeHostContext3D();
    223224    virtual void didRecreateGraphicsContext(bool success);
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

    r96392 r96454  
    2929#include "cc/CCLayerTreeHost.h"
    3030
     31#include "cc/CCLayerImpl.h"
    3132#include "cc/CCLayerTreeHostImpl.h"
    3233#include "cc/CCMainThreadTask.h"
    3334#include "cc/CCThreadTask.h"
    34 #include "CCThreadImpl.h"
    3535#include "GraphicsContext3DPrivate.h"
    3636#include <gtest/gtest.h>
     
    5959    virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl*) { }
    6060    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl*) { }
     61    virtual void applyScrollDelta(const IntSize&) { }
    6162};
    6263
     
    150151    virtual void animateAndLayout(double frameBeginTime)
    151152    {
     153    }
     154
     155    virtual void applyScrollDelta(const IntSize& scrollDelta)
     156    {
     157        m_testHooks->applyScrollDelta(scrollDelta);
    152158    }
    153159
     
    251257    }
    252258
    253     void runTest()
     259    virtual void runTest()
    254260    {
    255261        webkit_support::PostDelayedTask(CCLayerTreeHostTest::onBeginTest, static_cast<void*>(this), 0);
     
    297303    m_client = MockLayerTreeHostClient::create(this);
    298304
    299     RefPtr<LayerChromium> rootLayer;
     305    RefPtr<LayerChromium> rootLayer = LayerChromium::create(0);
    300306    m_layerTreeHost = MockLayerTreeHost::create(this, m_client.get(), rootLayer, m_settings);
    301307    ASSERT(m_layerTreeHost);
     
    323329}
    324330
     331class CCLayerTreeHostTestThreadOnly : public CCLayerTreeHostTest {
     332public:
     333    virtual void runTest()
     334    {
     335        if (m_settings.enableCompositorThread)
     336            CCLayerTreeHostTest::runTest();
     337    }
     338};
     339
    325340// Shortlived layerTreeHosts shouldn't die.
    326341class CCLayerTreeHostTestShortlived1 : public CCLayerTreeHostTest {
     
    557572}
    558573
     574class CCLayerTreeHostTestScrollSimple : public CCLayerTreeHostTestThreadOnly {
     575public:
     576    CCLayerTreeHostTestScrollSimple()
     577        : m_initialScroll(IntPoint(10, 20))
     578        , m_secondScroll(IntPoint(40, 5))
     579        , m_scrollAmount(2, -1)
     580        , m_scrolls(0)
     581    {
     582    }
     583
     584    virtual void beginTest()
     585    {
     586        m_layerTreeHost->rootLayer()->setMaxScrollPosition(IntSize(100, 100));
     587        m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll);
     588        postSetNeedsCommitToMainThread();
     589    }
     590
     591    virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl)
     592    {
     593        LayerChromium* root = m_layerTreeHost->rootLayer();
     594        if (!m_layerTreeHost->frameNumber())
     595            EXPECT_EQ(root->scrollPosition(), m_initialScroll);
     596        else {
     597            EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount);
     598
     599            // Pretend like Javascript updated the scroll position itself.
     600            root->setScrollPosition(m_secondScroll);
     601        }
     602    }
     603
     604    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
     605    {
     606        CCLayerImpl* root = impl->rootLayer();
     607        EXPECT_EQ(root->scrollDelta(), IntSize());
     608
     609        root->scrollBy(m_scrollAmount);
     610
     611        if (impl->frameNumber() == 1) {
     612            EXPECT_EQ(root->scrollPosition(), m_initialScroll);
     613            EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
     614            postSetNeedsCommitToMainThread();
     615        } else if (impl->frameNumber() == 2) {
     616            EXPECT_EQ(root->scrollPosition(), m_secondScroll);
     617            EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
     618            endTest();
     619        }
     620    }
     621
     622    virtual void applyScrollDelta(const IntSize& scrollDelta)
     623    {
     624        IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
     625        m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
     626        m_scrolls++;
     627    }
     628
     629    virtual void afterTest()
     630    {
     631        EXPECT_EQ(1, m_scrolls);
     632    }
     633private:
     634    IntPoint m_initialScroll;
     635    IntPoint m_secondScroll;
     636    IntSize m_scrollAmount;
     637    int m_scrolls;
     638};
     639TEST_F(CCLayerTreeHostTestScrollSimple, run)
     640{
     641    runTest();
     642}
     643
     644class CCLayerTreeHostTestScrollMultipleRedraw : public CCLayerTreeHostTestThreadOnly {
     645public:
     646    CCLayerTreeHostTestScrollMultipleRedraw()
     647        : m_initialScroll(IntPoint(40, 10))
     648        , m_scrollAmount(-3, 17)
     649        , m_scrolls(0)
     650    {
     651    }
     652
     653    virtual void beginTest()
     654    {
     655        m_layerTreeHost->rootLayer()->setMaxScrollPosition(IntSize(100, 100));
     656        m_layerTreeHost->rootLayer()->setScrollPosition(m_initialScroll);
     657        postSetNeedsCommitToMainThread();
     658    }
     659
     660    virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl)
     661    {
     662        LayerChromium* root = m_layerTreeHost->rootLayer();
     663        if (!m_layerTreeHost->frameNumber())
     664            EXPECT_EQ(root->scrollPosition(), m_initialScroll);
     665        else if (m_layerTreeHost->frameNumber() == 1)
     666            EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
     667        else if (m_layerTreeHost->frameNumber() == 2)
     668            EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
     669    }
     670
     671    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
     672    {
     673        CCLayerImpl* root = impl->rootLayer();
     674
     675        if (impl->frameNumber() == 1) {
     676            EXPECT_EQ(root->scrollDelta(), IntSize());
     677            root->scrollBy(m_scrollAmount);
     678            EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
     679
     680            EXPECT_EQ(root->scrollPosition(), m_initialScroll);
     681            postSetNeedsRedrawToMainThread();
     682        } else if (impl->frameNumber() == 2) {
     683            EXPECT_EQ(root->scrollDelta(), m_scrollAmount);
     684            root->scrollBy(m_scrollAmount);
     685            EXPECT_EQ(root->scrollDelta(), m_scrollAmount + m_scrollAmount);
     686
     687            EXPECT_EQ(root->scrollPosition(), m_initialScroll);
     688            postSetNeedsCommitToMainThread();
     689        } else if (impl->frameNumber() == 3) {
     690            EXPECT_EQ(root->scrollDelta(), IntSize());
     691            EXPECT_EQ(root->scrollPosition(), m_initialScroll + m_scrollAmount + m_scrollAmount);
     692            endTest();
     693        }
     694    }
     695
     696    virtual void applyScrollDelta(const IntSize& scrollDelta)
     697    {
     698        IntPoint position = m_layerTreeHost->rootLayer()->scrollPosition();
     699        m_layerTreeHost->rootLayer()->setScrollPosition(position + scrollDelta);
     700        m_scrolls++;
     701    }
     702
     703    virtual void afterTest()
     704    {
     705        EXPECT_EQ(1, m_scrolls);
     706    }
     707private:
     708    IntPoint m_initialScroll;
     709    IntSize m_scrollAmount;
     710    int m_scrolls;
     711};
     712TEST_F(CCLayerTreeHostTestScrollMultipleRedraw, run)
     713{
     714    runTest();
     715}
     716
    559717} // namespace
    560718
  • trunk/Source/WebKit/chromium/tests/TreeSynchronizerTest.cpp

    r96066 r96454  
    3030#include "cc/CCLayerImpl.h"
    3131#include "cc/CCProxy.h"
     32#include "cc/CCSingleThreadProxy.h"
    3233#include <gtest/gtest.h>
    3334
     
    3536
    3637namespace {
    37 
    38 class ScopedSetImplThread {
    39 public:
    40     ScopedSetImplThread()
    41     {
    42 #ifndef NDEBUG
    43         CCProxy::setImplThread(true);
    44 #endif
    45     }
    46     ~ScopedSetImplThread()
    47     {
    48 #ifndef NDEBUG
    49         CCProxy::setImplThread(false);
    50 #endif
    51     }
    52 };
    5338
    5439class MockCCLayerImpl : public CCLayerImpl {
     
    134119TEST(TreeSynchronizerTest, syncSimpleTreeFromEmpty)
    135120{
    136     ScopedSetImplThread impl;
     121    DebugScopedSetImplThread impl;
    137122    RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create(0);
    138123    layerTreeRoot->addChild(LayerChromium::create(0));
     
    147132TEST(TreeSynchronizerTest, syncSimpleTreeReusingLayers)
    148133{
    149     ScopedSetImplThread impl;
     134    DebugScopedSetImplThread impl;
    150135    Vector<int> ccLayerDestructionList;
    151136
     
    173158TEST(TreeSynchronizerTest, syncSimpleTreeAndProperties)
    174159{
    175     ScopedSetImplThread impl;
     160    DebugScopedSetImplThread impl;
    176161    RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create(0);
    177162    layerTreeRoot->addChild(LayerChromium::create(0));
     
    205190TEST(TreeSynchronizerTest, reuseCCLayersAfterStructuralChange)
    206191{
    207     ScopedSetImplThread impl;
     192    DebugScopedSetImplThread impl;
    208193    Vector<int> ccLayerDestructionList;
    209194
     
    252237TEST(TreeSynchronizerTest, syncSimpleTreeThenDestroy)
    253238{
    254     ScopedSetImplThread impl;
     239    DebugScopedSetImplThread impl;
    255240    Vector<int> ccLayerDestructionList;
    256241
     
    283268TEST(TreeSynchronizerTest, syncMaskReplicaAndReplicaMaskLayers)
    284269{
    285     ScopedSetImplThread impl;
     270    DebugScopedSetImplThread impl;
    286271    RefPtr<LayerChromium> layerTreeRoot = LayerChromium::create(0);
    287272    layerTreeRoot->addChild(LayerChromium::create(0));
Note: See TracChangeset for help on using the changeset viewer.