| Differences between
and this patch
- a/Source/WebCore/ChangeLog +47 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2011-12-09  Sami Kyostila  <skyostil@chromium.org>
2
3
        [chromium] Implement layer scrolling in the compositor thread
4
        https://bugs.webkit.org/show_bug.cgi?id=73350
5
6
        This patch enables scrolling child layers in the compositor thread.
7
        Scroll deltas are accumulated for each scrolled CCLayerImpl and
8
        synchronized to the WebViewImpl in the main thread.
9
10
        If a layer has no room to scroll in a given direction, one of its
11
        ancestor layers is scrolled instead if possible.
12
13
        Reviewed by NOBODY (OOPS!).
14
15
        * platform/graphics/chromium/LayerChromium.cpp:
16
        (WebCore::LayerChromium::pushPropertiesTo):
17
        * platform/graphics/chromium/LayerChromium.h:
18
        (WebCore::LayerChromium::maxScrollPosition):
19
        (WebCore::LayerChromium::setMaxScrollPosition):
20
        * platform/graphics/chromium/cc/CCLayerImpl.cpp:
21
        (WebCore::CCLayerImpl::CCLayerImpl):
22
        (WebCore::CCLayerImpl::isInsideScrollableRegion):
23
        (WebCore::CCLayerImpl::scrollBy):
24
        * platform/graphics/chromium/cc/CCLayerImpl.h:
25
        (WebCore::CCLayerImpl::pageScaleDelta):
26
        (WebCore::CCLayerImpl::sentScrollDelta):
27
        (WebCore::CCLayerImpl::setSentScrollDelta):
28
        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
29
        (WebCore::CCLayerTreeHost::setRootLayer):
30
        (WebCore::findScrollLayer):
31
        (WebCore::CCLayerTreeHost::applyScrollAndScale):
32
        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
33
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
34
        (WebCore::CCLayerTreeHostImpl::setRootLayer):
35
        (WebCore::CCLayerTreeHostImpl::adjustScrollsForPageScaleChange):
36
        (WebCore::CCLayerTreeHostImpl::updateMaxScrollPosition):
37
        (WebCore::CCLayerTreeHostImpl::windowToLayerContentPoint):
38
        (WebCore::CCLayerTreeHostImpl::isInsideScrollableRegion):
39
        (WebCore::CCLayerTreeHostImpl::beginScrollingInnermostLayerAtPoint):
40
        (WebCore::CCLayerTreeHostImpl::scrollBegin):
41
        (WebCore::layerCanBeScrolled):
42
        (WebCore::CCLayerTreeHostImpl::scrollBy):
43
        (WebCore::CCLayerTreeHostImpl::pinchGestureBegin):
44
        (WebCore::CCLayerTreeHostImpl::pinchGestureUpdate):
45
        (WebCore::CCLayerTreeHostImpl::pinchGestureEnd):
46
        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
47
1
2011-12-12  Kenneth Russell  <kbr@google.com>
48
2011-12-12  Kenneth Russell  <kbr@google.com>
2
49
3
        Unreviewed, rolling out r102648.
50
        Unreviewed, rolling out r102648.
- a/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp +1 lines
Lines 390-395 void LayerChromium::pushPropertiesTo(CCLayerImpl* layer) a/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp_sec1
390
    layer->setPosition(m_position);
390
    layer->setPosition(m_position);
391
    layer->setPreserves3D(preserves3D());
391
    layer->setPreserves3D(preserves3D());
392
    layer->setScrollPosition(m_scrollPosition);
392
    layer->setScrollPosition(m_scrollPosition);
393
    layer->setMaxScrollPosition(m_maxScrollPosition);
393
    layer->setSublayerTransform(m_sublayerTransform);
394
    layer->setSublayerTransform(m_sublayerTransform);
394
    layer->setTransform(m_transform);
395
    layer->setTransform(m_transform);
395
    layer->setUpdateRect(m_updateRect);
396
    layer->setUpdateRect(m_updateRect);
- a/Source/WebCore/platform/graphics/chromium/LayerChromium.h +9 lines
Lines 36-41 a/Source/WebCore/platform/graphics/chromium/LayerChromium.h_sec1
36
36
37
#include "FloatPoint.h"
37
#include "FloatPoint.h"
38
#include "GraphicsContext.h"
38
#include "GraphicsContext.h"
39
#include "Node.h"
39
#include "PlatformString.h"
40
#include "PlatformString.h"
40
#include "ProgramBinding.h"
41
#include "ProgramBinding.h"
41
#include "RenderSurfaceChromium.h"
42
#include "RenderSurfaceChromium.h"
Lines 132-137 public: a/Source/WebCore/platform/graphics/chromium/LayerChromium.h_sec2
132
    void setScrollPosition(const IntPoint&);
133
    void setScrollPosition(const IntPoint&);
133
    const IntPoint& scrollPosition() const { return m_scrollPosition; }
134
    const IntPoint& scrollPosition() const { return m_scrollPosition; }
134
135
136
    const IntSize& maxScrollPosition() const { return m_maxScrollPosition; }
137
    void setMaxScrollPosition(const IntSize& maxScrollPosition) { m_maxScrollPosition = maxScrollPosition; }
138
139
    Node* scrollNode() const { return m_scrollNode.get(); }
140
    void setScrollNode(PassRefPtr<Node> scrollNode) { m_scrollNode = scrollNode; }
141
135
    void setScrollable(bool);
142
    void setScrollable(bool);
136
    bool scrollable() const { return m_scrollable; }
143
    bool scrollable() const { return m_scrollable; }
137
144
Lines 255-260 private: a/Source/WebCore/platform/graphics/chromium/LayerChromium.h_sec3
255
    IntSize m_bounds;
262
    IntSize m_bounds;
256
    IntRect m_visibleLayerRect;
263
    IntRect m_visibleLayerRect;
257
    IntPoint m_scrollPosition;
264
    IntPoint m_scrollPosition;
265
    IntSize m_maxScrollPosition;
266
    RefPtr<Node> m_scrollNode;
258
    bool m_scrollable;
267
    bool m_scrollable;
259
    FloatPoint m_position;
268
    FloatPoint m_position;
260
    FloatPoint m_anchorPoint;
269
    FloatPoint m_anchorPoint;
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp -3 / +3 lines
Lines 122-130 void CCLayerImpl::bindContentsTexture(LayerRendererChromium*) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp_sec1
122
    ASSERT_NOT_REACHED();
122
    ASSERT_NOT_REACHED();
123
}
123
}
124
124
125
void CCLayerImpl::scrollBy(const IntSize& scroll)
125
void CCLayerImpl::scrollBy(const FloatSize& scroll)
126
{
126
{
127
    IntSize newDelta = m_scrollDelta + scroll;
127
    FloatSize newDelta = m_scrollDelta + scroll;
128
    IntSize minDelta = -toSize(m_scrollPosition);
128
    IntSize minDelta = -toSize(m_scrollPosition);
129
    IntSize maxDelta = m_maxScrollPosition - toSize(m_scrollPosition);
129
    IntSize maxDelta = m_maxScrollPosition - toSize(m_scrollPosition);
130
    // Clamp newDelta so that position + delta stays within scroll bounds.
130
    // Clamp newDelta so that position + delta stays within scroll bounds.
Lines 434-440 void CCLayerImpl::setScrollPosition(const IntPoint& scrollPosition) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.cpp_sec2
434
    noteLayerPropertyChangedForSubtree();
434
    noteLayerPropertyChangedForSubtree();
435
}
435
}
436
436
437
void CCLayerImpl::setScrollDelta(const IntSize& scrollDelta)
437
void CCLayerImpl::setScrollDelta(const FloatSize& scrollDelta)
438
{
438
{
439
    if (m_scrollDelta == scrollDelta)
439
    if (m_scrollDelta == scrollDelta)
440
        return;
440
        return;
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h -7 / +7 lines
Lines 157-172 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h_sec1
157
    const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
157
    const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
158
    void setMaxScrollPosition(const IntSize& maxScrollPosition) { m_maxScrollPosition = maxScrollPosition; }
158
    void setMaxScrollPosition(const IntSize& maxScrollPosition) { m_maxScrollPosition = maxScrollPosition; }
159
159
160
    const IntSize& scrollDelta() const { return m_scrollDelta; }
160
    const FloatSize& scrollDelta() const { return m_scrollDelta; }
161
    void setScrollDelta(const IntSize&);
161
    void setScrollDelta(const FloatSize&);
162
162
163
    float pageScaleDelta() const { return m_pageScaleDelta; }
163
    float pageScaleDelta() const { return m_pageScaleDelta; }
164
    void setPageScaleDelta(float);
164
    void setPageScaleDelta(float);
165
165
166
    const IntSize& sentScrollDelta() const { return m_sentScrollDelta; }
166
    const FloatSize& sentScrollDelta() const { return m_sentScrollDelta; }
167
    void setSentScrollDelta(const IntSize& sentScrollDelta) { m_sentScrollDelta = sentScrollDelta; }
167
    void setSentScrollDelta(const FloatSize& sentScrollDelta) { m_sentScrollDelta = sentScrollDelta; }
168
168
169
    void scrollBy(const IntSize& scroll);
169
    void scrollBy(const FloatSize& scroll);
170
170
171
    bool scrollable() const { return m_scrollable; }
171
    bool scrollable() const { return m_scrollable; }
172
    void setScrollable(bool scrollable) { m_scrollable = scrollable; }
172
    void setScrollable(bool scrollable) { m_scrollable = scrollable; }
Lines 250-257 private: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerImpl.h_sec2
250
250
251
    bool m_drawsContent;
251
    bool m_drawsContent;
252
252
253
    IntSize m_scrollDelta;
253
    FloatSize m_scrollDelta;
254
    IntSize m_sentScrollDelta;
254
    FloatSize m_sentScrollDelta;
255
    IntSize m_maxScrollPosition;
255
    IntSize m_maxScrollPosition;
256
    float m_pageScaleDelta;
256
    float m_pageScaleDelta;
257
257
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp -7 / +35 lines
Lines 29-34 a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp_sec1
29
#include "LayerChromium.h"
29
#include "LayerChromium.h"
30
#include "LayerPainterChromium.h"
30
#include "LayerPainterChromium.h"
31
#include "LayerRendererChromium.h"
31
#include "LayerRendererChromium.h"
32
#include "RenderBox.h"
32
#include "TraceEvent.h"
33
#include "TraceEvent.h"
33
#include "TreeSynchronizer.h"
34
#include "TreeSynchronizer.h"
34
#include "cc/CCLayerTreeHostCommon.h"
35
#include "cc/CCLayerTreeHostCommon.h"
Lines 449-463 void CCLayerTreeHost::clearPendingUpdate() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp_sec2
449
    m_updateList.clear();
450
    m_updateList.clear();
450
}
451
}
451
452
452
void CCLayerTreeHost::applyScrollAndScale(const CCScrollAndScaleSet& info)
453
static LayerChromium* findLayerById(LayerChromium* layer, int id)
453
{
454
{
454
    // FIXME: pushing scroll offsets to non-root layers not implemented
455
    if (!layer)
455
    if (!info.scrolls.size())
456
        return 0;
456
        return;
457
458
    if (layer->id() == id)
459
        return layer;
460
461
    for (size_t i = 0; i < layer->children().size(); ++i) {
462
        LayerChromium* found = findLayerById(layer->children()[i].get(), id);
463
        if (found)
464
            return found;
465
    }
457
466
458
    ASSERT(info.scrolls.size() == 1);
467
    return 0;
459
    IntSize scrollDelta = info.scrolls[0].scrollDelta;
468
}
460
    m_client->applyScrollAndScale(scrollDelta, info.pageScaleDelta);
469
470
void CCLayerTreeHost::applyScrollAndScale(const CCScrollAndScaleSet& info)
471
{
472
    if (!info.rootScrollDelta.isZero() || info.pageScaleDelta != 1)
473
        m_client->applyScrollAndScale(info.rootScrollDelta, info.pageScaleDelta);
474
475
    for (size_t i = 0; i < info.scrolls.size(); ++i) {
476
        LayerChromium* layer = findLayerById(m_rootLayer.get(), info.scrolls[i].layerId);
477
        if (!layer)
478
            continue;
479
        layer->setScrollPosition(layer->scrollPosition() + info.scrolls[i].scrollDelta);
480
        if (!layer->scrollNode())
481
            continue;
482
        Node* node = layer->scrollNode();
483
        if (!node->renderer() || !node->renderer()->isBox() || !layer->scrollNode()->inDocument())
484
            continue;
485
        RenderBox* renderBox = toRenderBox(node->renderer());
486
        renderBox->setScrollLeft(renderBox->scrollLeft() + info.scrolls[i].scrollDelta.width());
487
        renderBox->setScrollTop(renderBox->scrollTop() + info.scrolls[i].scrollDelta.height());
488
    }
461
}
489
}
462
490
463
void CCLayerTreeHost::startRateLimiter(GraphicsContext3D* context)
491
void CCLayerTreeHost::startRateLimiter(GraphicsContext3D* context)
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommon.h +1 lines
Lines 55-60 public: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommon.h_sec1
55
55
56
struct CCScrollAndScaleSet {
56
struct CCScrollAndScaleSet {
57
    Vector<CCLayerTreeHostCommon::ScrollUpdateInfo> scrolls;
57
    Vector<CCLayerTreeHostCommon::ScrollUpdateInfo> scrolls;
58
    IntSize rootScrollDelta;
58
    float pageScaleDelta;
59
    float pageScaleDelta;
59
};
60
};
60
61
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp -31 / +118 lines
Lines 88-94 void CCLayerTreeHostImpl::animate(double frameBeginTimeMs) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec1
88
    if (!m_pageScaleAnimation)
88
    if (!m_pageScaleAnimation)
89
        return;
89
        return;
90
90
91
    IntSize scrollTotal = toSize(m_scrollLayerImpl->scrollPosition() + m_scrollLayerImpl->scrollDelta());
91
    IntSize scrollTotal = toSize(m_scrollLayerImpl->scrollPosition() + flooredIntPoint(m_scrollLayerImpl->scrollDelta()));
92
92
93
    setPageScaleDelta(m_pageScaleAnimation->pageScaleAtTime(frameBeginTimeMs) / m_pageScale);
93
    setPageScaleDelta(m_pageScaleAnimation->pageScaleAtTime(frameBeginTimeMs) / m_pageScale);
94
    IntSize nextScroll = m_pageScaleAnimation->scrollOffsetAtTime(frameBeginTimeMs);
94
    IntSize nextScroll = m_pageScaleAnimation->scrollOffsetAtTime(frameBeginTimeMs);
Lines 107-113 void CCLayerTreeHostImpl::startPageScaleAnimation(const IntSize& targetPosition, a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec2
107
    if (!m_scrollLayerImpl)
107
    if (!m_scrollLayerImpl)
108
        return;
108
        return;
109
109
110
    IntSize scrollTotal = toSize(m_scrollLayerImpl->scrollPosition() + m_scrollLayerImpl->scrollDelta());
110
    IntSize scrollTotal = toSize(m_scrollLayerImpl->scrollPosition() + flooredIntPoint(m_scrollLayerImpl->scrollDelta()));
111
    scrollTotal.scale(m_pageScaleDelta);
111
    scrollTotal.scale(m_pageScaleDelta);
112
    float scaleTotal = m_pageScale * m_pageScaleDelta;
112
    float scaleTotal = m_pageScale * m_pageScaleDelta;
113
    IntSize scaledContentSize = m_scrollLayerImpl->children()[0]->contentBounds();
113
    IntSize scaledContentSize = m_scrollLayerImpl->children()[0]->contentBounds();
Lines 194-201 static CCLayerImpl* findScrollLayer(CCLayerImpl* layer) a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec3
194
void CCLayerTreeHostImpl::setRootLayer(PassRefPtr<CCLayerImpl> layer)
194
void CCLayerTreeHostImpl::setRootLayer(PassRefPtr<CCLayerImpl> layer)
195
{
195
{
196
    m_rootLayerImpl = layer;
196
    m_rootLayerImpl = layer;
197
198
    // FIXME: Currently, this only finds the first scrollable layer.
199
    m_scrollLayerImpl = findScrollLayer(m_rootLayerImpl.get());
197
    m_scrollLayerImpl = findScrollLayer(m_rootLayerImpl.get());
200
}
198
}
201
199
Lines 263-277 void CCLayerTreeHostImpl::setPageScaleFactorAndLimits(float pageScale, float min a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec4
263
261
264
void CCLayerTreeHostImpl::adjustScrollsForPageScaleChange(float pageScaleChange)
262
void CCLayerTreeHostImpl::adjustScrollsForPageScaleChange(float pageScaleChange)
265
{
263
{
266
    if (pageScaleChange == 1)
264
    if (!m_scrollLayerImpl || pageScaleChange == 1)
267
        return;
265
        return;
268
266
269
    // We also need to convert impl-side scroll deltas to pageScale space.
267
    // We also need to convert impl-side scroll delta for the root layer to pageScale space.
270
    if (m_scrollLayerImpl) {
268
    FloatSize scrollDelta = m_scrollLayerImpl->scrollDelta();
271
        IntSize scrollDelta = m_scrollLayerImpl->scrollDelta();
269
    scrollDelta.scale(pageScaleChange);
272
        scrollDelta.scale(pageScaleChange);
270
    m_scrollLayerImpl->setScrollDelta(scrollDelta);
273
        m_scrollLayerImpl->setScrollDelta(scrollDelta);
274
    }
275
}
271
}
276
272
277
void CCLayerTreeHostImpl::setPageScaleDelta(float delta)
273
void CCLayerTreeHostImpl::setPageScaleDelta(float delta)
Lines 313-321 void CCLayerTreeHostImpl::updateMaxScrollPosition() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec5
313
    // having a vertical scrollbar but no horizontal overflow.
309
    // having a vertical scrollbar but no horizontal overflow.
314
    maxScroll.clampNegativeToZero();
310
    maxScroll.clampNegativeToZero();
315
311
312
    // We only need to update the root layer scroll range, since the child
313
    // layers use unscaled scroll coordinates.
316
    m_scrollLayerImpl->setMaxScrollPosition(maxScroll);
314
    m_scrollLayerImpl->setMaxScrollPosition(maxScroll);
317
318
    // TODO(aelias): Also update sublayers.
319
}
315
}
320
316
321
void CCLayerTreeHostImpl::setZoomAnimatorTransform(const TransformationMatrix& zoom)
317
void CCLayerTreeHostImpl::setZoomAnimatorTransform(const TransformationMatrix& zoom)
Lines 336-363 void CCLayerTreeHostImpl::setNeedsRedraw() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec6
336
    m_client->setNeedsRedrawOnImplThread();
332
    m_client->setNeedsRedrawOnImplThread();
337
}
333
}
338
334
339
CCInputHandlerClient::ScrollStatus CCLayerTreeHostImpl::scrollBegin(const IntPoint&)
335
CCInputHandlerClient::ScrollStatus CCLayerTreeHostImpl::beginScrollingInnermostLayerAtPoint(CCLayerImpl* layerImpl, const IntPoint& viewportPoint)
336
{
337
    if (!layerImpl)
338
        return CCInputHandlerClient::ScrollIgnored;
339
340
    for (size_t i = 0; i < layerImpl->children().size(); i++) {
341
        CCInputHandlerClient::ScrollStatus status = beginScrollingInnermostLayerAtPoint(layerImpl->children()[i].get(), viewportPoint);
342
        if (status == CCInputHandlerClient::ScrollStarted || status == CCInputHandlerClient::ScrollFailed)
343
            return status;
344
    }
345
346
    IntPoint contentPoint(layerImpl->screenSpaceTransform().inverse().mapPoint(viewportPoint));
347
348
    // The content point for non-root layers must be scaled with the page scale. Note that the
349
    // page scale delta is already embedded in each layer's screen space transform.
350
    if (layerImpl != m_scrollLayerImpl)
351
        contentPoint.scale(m_pageScale, m_pageScale);
352
353
    if (layerImpl->drawsContent() && !layerImpl->visibleLayerRect().contains(contentPoint))
354
        return CCInputHandlerClient::ScrollIgnored;
355
356
    if (layerImpl->scrollable()) {
357
        m_currentlyScrollingLayerImpl = layerImpl;
358
        return CCInputHandlerClient::ScrollStarted;
359
    }
360
361
    return CCInputHandlerClient::ScrollIgnored;
362
}
363
364
CCInputHandlerClient::ScrollStatus CCLayerTreeHostImpl::scrollBegin(const IntPoint& viewportPoint)
340
{
365
{
341
    // TODO: Check for scrollable sublayers.
366
    return beginScrollingInnermostLayerAtPoint(m_scrollLayerImpl.get(), viewportPoint);
342
    if (!m_scrollLayerImpl || !m_scrollLayerImpl->scrollable())
367
}
343
        return ScrollIgnored;
344
368
345
    return ScrollStarted;
369
static bool layerCanBeScrolled(const CCLayerImpl* layerImpl, const IntSize& direction)
370
{
371
    IntPoint scrollPosition(layerImpl->scrollPosition() + flooredIntPoint(layerImpl->scrollDelta()));
372
    if (!layerImpl->scrollable())
373
        return false;
374
    if (direction.width() < 0 && scrollPosition.x() > 0)
375
        return true;
376
    if (direction.height() < 0 && scrollPosition.y() > 0)
377
        return true;
378
    if (direction.width() > 0 && scrollPosition.x() < layerImpl->maxScrollPosition().width())
379
        return true;
380
    if (direction.height() > 0 && scrollPosition.y() < layerImpl->maxScrollPosition().height())
381
        return true;
382
    return false;
346
}
383
}
347
384
348
void CCLayerTreeHostImpl::scrollBy(const IntSize& scrollDelta)
385
void CCLayerTreeHostImpl::scrollBy(const IntSize& scrollDelta)
349
{
386
{
350
    TRACE_EVENT("CCLayerTreeHostImpl::scrollBy", this, 0);
387
    TRACE_EVENT("CCLayerTreeHostImpl::scrollBy", this, 0);
351
    if (!m_scrollLayerImpl)
388
    if (!m_currentlyScrollingLayerImpl)
352
        return;
389
        return;
353
390
354
    m_scrollLayerImpl->scrollBy(scrollDelta);
391
    IntSize pendingDelta(scrollDelta);
355
    m_client->setNeedsCommitOnImplThread();
392
    CCLayerImpl* layerImpl = m_currentlyScrollingLayerImpl.get();
356
    m_client->setNeedsRedrawOnImplThread();
393
    while (layerImpl) {
394
        if (layerCanBeScrolled(layerImpl, pendingDelta)) {
395
            FloatSize previousDelta(layerImpl->scrollDelta());
396
            FloatSize scaledPendingDelta(pendingDelta);
397
            // Since scrollDelta is in window coordinates, it already has the page scale applied.
398
            // This matches what the root scroll layer expects, but child layers are scrolled using
399
            // unscaled content coordinates instead, so we have to undo the scaling for them. The
400
            // page scale delta needs to be unapplied with both layer types since the scroll
401
            // coordinates do not respect it.
402
            if (layerImpl == m_scrollLayerImpl) {
403
                scaledPendingDelta.scale(1 / m_pageScaleDelta);
404
                layerImpl->scrollBy(scaledPendingDelta);
405
            } else {
406
                scaledPendingDelta.scale(1 / (m_pageScale * m_pageScaleDelta));
407
                layerImpl->scrollBy(scaledPendingDelta);
408
            }
409
            // Reset the pending scroll delta to zero if the layer was able to move along the requested
410
            // axis. This is to ensure it is possible to scroll exactly to the beginning or end of a
411
            // scroll area regardless of the scroll step.
412
            if (previousDelta.width() != layerImpl->scrollDelta().width())
413
                pendingDelta.setWidth(0);
414
            if (previousDelta.height() != layerImpl->scrollDelta().height())
415
                pendingDelta.setHeight(0);
416
            // Also reset the delta if the layer did not move because the scroll delta got rounded down
417
            // to zero and the layer still has room to scroll in the requested direction. This avoids
418
            // scrolling the parent layer for slow scrolls that do not move the layer at every iteration.
419
            if (pendingDelta.width() && layerCanBeScrolled(layerImpl, IntSize(pendingDelta.width(), 0)))
420
                pendingDelta.setWidth(0);
421
            if (pendingDelta.height() && layerCanBeScrolled(layerImpl, IntSize(0, pendingDelta.height())))
422
                pendingDelta.setHeight(0);
423
        }
424
        layerImpl = layerImpl->parent();
425
    }
426
427
    if (pendingDelta != scrollDelta) {
428
        m_client->setNeedsCommitOnImplThread();
429
        m_client->setNeedsRedrawOnImplThread();
430
    }
357
}
431
}
358
432
359
void CCLayerTreeHostImpl::scrollEnd()
433
void CCLayerTreeHostImpl::scrollEnd()
360
{
434
{
435
    m_currentlyScrollingLayerImpl.clear();
361
}
436
}
362
437
363
bool CCLayerTreeHostImpl::haveWheelEventHandlers()
438
bool CCLayerTreeHostImpl::haveWheelEventHandlers()
Lines 400-409 void CCLayerTreeHostImpl::pinchGestureEnd() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec7
400
    m_client->setNeedsCommitOnImplThread();
475
    m_client->setNeedsCommitOnImplThread();
401
}
476
}
402
477
478
bool CCLayerTreeHostImpl::collectScrollDeltas(CCScrollAndScaleSet* scrollInfo, CCLayerImpl* layerImpl) const
479
{
480
    if (!layerImpl->scrollDelta().isZero()) {
481
        IntSize scrollDelta = toSize(flooredIntPoint(layerImpl->scrollDelta()));
482
        if (layerImpl != m_scrollLayerImpl) {
483
            CCLayerTreeHostCommon::ScrollUpdateInfo scroll;
484
            scroll.layerId = layerImpl->id();
485
            scroll.scrollDelta = scrollDelta;
486
            scrollInfo->scrolls.append(scroll);
487
        } else
488
            scrollInfo->rootScrollDelta = scrollDelta;
489
        layerImpl->setSentScrollDelta(layerImpl->scrollDelta());
490
    }
491
492
    for (size_t i = 0; i < layerImpl->children().size(); ++i)
493
        collectScrollDeltas(scrollInfo, layerImpl->children()[i].get());
494
495
    return !scrollInfo->rootScrollDelta.isZero() || scrollInfo->scrolls.size() > 0;
496
}
497
403
PassOwnPtr<CCScrollAndScaleSet> CCLayerTreeHostImpl::processScrollDeltas()
498
PassOwnPtr<CCScrollAndScaleSet> CCLayerTreeHostImpl::processScrollDeltas()
404
{
499
{
405
    OwnPtr<CCScrollAndScaleSet> scrollInfo = adoptPtr(new CCScrollAndScaleSet());
500
    OwnPtr<CCScrollAndScaleSet> scrollInfo = adoptPtr(new CCScrollAndScaleSet());
406
    bool didMove = m_scrollLayerImpl && (!m_scrollLayerImpl->scrollDelta().isZero() || m_pageScaleDelta != 1.0f);
501
    bool didMove = m_scrollLayerImpl && (collectScrollDeltas(scrollInfo.get(), m_scrollLayerImpl.get()) || m_pageScaleDelta != 1.0f);
407
    if (!didMove || m_pinchGestureActive || m_pageScaleAnimation) {
502
    if (!didMove || m_pinchGestureActive || m_pageScaleAnimation) {
408
        m_sentPageScaleDelta = scrollInfo->pageScaleDelta = 1;
503
        m_sentPageScaleDelta = scrollInfo->pageScaleDelta = 1;
409
        return scrollInfo.release();
504
        return scrollInfo.release();
Lines 411-424 PassOwnPtr<CCScrollAndScaleSet> CCLayerTreeHostImpl::processScrollDeltas() a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp_sec8
411
506
412
    m_sentPageScaleDelta = scrollInfo->pageScaleDelta = m_pageScaleDelta;
507
    m_sentPageScaleDelta = scrollInfo->pageScaleDelta = m_pageScaleDelta;
413
508
414
    // FIXME: track scrolls from layers other than the root
415
    CCLayerTreeHostCommon::ScrollUpdateInfo scroll;
416
    scroll.layerId = m_scrollLayerImpl->id();
417
    scroll.scrollDelta = m_scrollLayerImpl->scrollDelta();
418
    scrollInfo->scrolls.append(scroll);
419
420
    m_scrollLayerImpl->setSentScrollDelta(scroll.scrollDelta);
421
422
    return scrollInfo.release();
509
    return scrollInfo.release();
423
}
510
}
424
511
- a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h +3 lines
Lines 128-137 private: a/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h_sec1
128
    void applyPageScaleDeltaToScrollLayer();
128
    void applyPageScaleDeltaToScrollLayer();
129
    void adjustScrollsForPageScaleChange(float);
129
    void adjustScrollsForPageScaleChange(float);
130
    void updateMaxScrollPosition();
130
    void updateMaxScrollPosition();
131
    ScrollStatus beginScrollingInnermostLayerAtPoint(CCLayerImpl*, const IntPoint&);
132
    bool collectScrollDeltas(CCScrollAndScaleSet*, CCLayerImpl*) const;
131
133
132
    OwnPtr<LayerRendererChromium> m_layerRenderer;
134
    OwnPtr<LayerRendererChromium> m_layerRenderer;
133
    RefPtr<CCLayerImpl> m_rootLayerImpl;
135
    RefPtr<CCLayerImpl> m_rootLayerImpl;
134
    RefPtr<CCLayerImpl> m_scrollLayerImpl;
136
    RefPtr<CCLayerImpl> m_scrollLayerImpl;
137
    RefPtr<CCLayerImpl> m_currentlyScrollingLayerImpl;
135
    CCSettings m_settings;
138
    CCSettings m_settings;
136
    IntSize m_viewportSize;
139
    IntSize m_viewportSize;
137
    bool m_visible;
140
    bool m_visible;
- a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp +1 lines
Lines 165-170 void CCSingleThreadProxy::doCommit() a/Source/WebCore/platform/graphics/chromium/cc/CCSingleThreadProxy.cpp_sec1
165
        // In the single-threaded case, the scroll deltas should never be
165
        // In the single-threaded case, the scroll deltas should never be
166
        // touched on the impl layer tree.
166
        // touched on the impl layer tree.
167
        OwnPtr<CCScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
167
        OwnPtr<CCScrollAndScaleSet> scrollInfo = m_layerTreeHostImpl->processScrollDeltas();
168
        ASSERT(scrollInfo->rootScrollDelta.isZero());
168
        ASSERT(!scrollInfo->scrolls.size());
169
        ASSERT(!scrollInfo->scrolls.size());
169
#endif
170
#endif
170
    }
171
    }
- a/Source/WebKit/chromium/ChangeLog +54 lines
Lines 1-3 a/Source/WebKit/chromium/ChangeLog_sec1
1
2011-12-09  Sami Kyostila  <skyostil@chromium.org>
2
3
        [chromium] Implement layer scrolling in the compositor thread
4
        https://bugs.webkit.org/show_bug.cgi?id=73350
5
6
        This patch enables scrolling child layers in the compositor thread.
7
        Scroll deltas are accumulated for each scrolled CCLayerImpl and
8
        synchronized to the WebViewImpl in the main thread.
9
10
        If a layer has no room to scroll in a given direction, one of its
11
        ancestor layers is scrolled instead if possible.
12
13
        Reviewed by NOBODY (OOPS!).
14
15
        * public/platform/WebLayerTreeViewClient.h:
16
        * src/ChromeClientImpl.cpp:
17
        (WebKit::ChromeClientImpl::addOrUpdateScrollingLayer):
18
        (WebKit::ChromeClientImpl::removeScrollingLayer):
19
        * src/ChromeClientImpl.h:
20
        * src/WebLayerTreeViewImpl.cpp:
21
        (WebKit::WebLayerTreeViewImpl::applyRootLayerScrollAndScale):
22
        (WebKit::WebLayerTreeViewImpl::applyLayerScroll):
23
        * src/WebLayerTreeViewImpl.h:
24
        * src/WebViewImpl.cpp:
25
        (WebKit::WebViewImpl::addOrUpdateScrollingLayer):
26
        (WebKit::WebViewImpl::removeScrollingLayer):
27
        (WebKit::WebViewImpl::applyLayerScroll):
28
        (WebKit::WebViewImpl::applyRootLayerScrollAndScale):
29
        * src/WebViewImpl.h:
30
        * tests/CCLayerImplTest.cpp:
31
        (WebCore::TEST):
32
        * tests/CCLayerTreeHostImplTest.cpp:
33
        (WebKit::TEST_F):
34
        * tests/CCLayerTreeHostTest.cpp:
35
        (WTF::TestHooks::applyRootLayerScrollAndScale):
36
        (WTF::TestHooks::applyLayerScroll):
37
        (WTF::MockLayerTreeHostClient::applyRootLayerScrollAndScale):
38
        (WTF::MockLayerTreeHostClient::applyLayerScroll):
39
        (WTF::CCLayerTreeHostTestScrollSimple::applyRootLayerScrollAndScale):
40
        (WTF::CCLayerTreeHostTestScrollMultipleRedraw::applyRootLayerScrollAndScale):
41
        (WTF::CCLayerTreeHostTestScrollBase::beginTest):
42
        (WTF::CCLayerTreeHostTestScrollBase::applyRootLayerScrollAndScale):
43
        (WTF::CCLayerTreeHostTestScrollBase::applyLayerScroll):
44
        (WTF::CCLayerTreeHostTestScrollBase::afterTest):
45
        (WTF::CCLayerTreeHostTestScrollBase::applyScrollToChildLayer):
46
        (WTF::CCLayerTreeHostTestScrollChildLayer::CCLayerTreeHostTestScrollChildLayer):
47
        (WTF::CCLayerTreeHostTestScrollChildLayer::beginCommitOnCCThread):
48
        (WTF::CCLayerTreeHostTestScrollChildLayer::drawLayersOnCCThread):
49
        (WTF::TEST_F):
50
        (WTF::CCLayerTreeHostTestScrollChildLayerBeyondLimit::CCLayerTreeHostTestScrollChildLayerBeyondLimit):
51
        (WTF::CCLayerTreeHostTestScrollChildLayerBeyondLimit::beginTest):
52
        (WTF::CCLayerTreeHostTestScrollChildLayerBeyondLimit::beginCommitOnCCThread):
53
        (WTF::CCLayerTreeHostTestScrollChildLayerBeyondLimit::drawLayersOnCCThread):
54
1
2011-12-12  Ryosuke Niwa  <rniwa@webkit.org>
55
2011-12-12  Ryosuke Niwa  <rniwa@webkit.org>
2
56
3
        WebKit code shouldn't be calling applyCommand directly
57
        WebKit code shouldn't be calling applyCommand directly
- a/Source/WebKit/chromium/src/ChromeClientImpl.cpp +18 lines
Lines 59-64 a/Source/WebKit/chromium/src/ChromeClientImpl.cpp_sec1
59
#include "PlatformSupport.h"
59
#include "PlatformSupport.h"
60
#include "PopupContainer.h"
60
#include "PopupContainer.h"
61
#include "PopupMenuChromium.h"
61
#include "PopupMenuChromium.h"
62
#include "RenderLayer.h"
62
#include "RenderWidget.h"
63
#include "RenderWidget.h"
63
#include "ScriptController.h"
64
#include "ScriptController.h"
64
#include "SearchPopupMenuChromium.h"
65
#include "SearchPopupMenuChromium.h"
Lines 844-849 bool ChromeClientImpl::paintCustomOverhangArea(GraphicsContext* context, const I a/Source/WebKit/chromium/src/ChromeClientImpl.cpp_sec2
844
    return false;
845
    return false;
845
}
846
}
846
847
848
void ChromeClientImpl::addOrUpdateScrollingLayer(Node* node, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer, const IntSize& scrollSize)
849
{
850
    if (!node->renderer()->isBox())
851
        return;
852
    RenderBox* renderBox = toRenderBox(node->renderer());
853
    contentsLayer->setScrollable(true);
854
    contentsLayer->setScrollPosition(IntPoint(node->renderer()->enclosingLayer()->scrolledContentOffset()));
855
    contentsLayer->setMaxScrollPosition(IntSize(scrollSize.width() - renderBox->clientWidth(), scrollSize.height() - renderBox->clientHeight()));
856
    contentsLayer->setScrollNode(node);
857
}
858
859
void ChromeClientImpl::removeScrollingLayer(Node* node, PlatformLayer* scrollingLayer, PlatformLayer* contentsLayer)
860
{
861
    contentsLayer->setScrollable(false);
862
    contentsLayer->setScrollNode(0);
863
}
864
847
// FIXME: Remove ChromeClientImpl::requestGeolocationPermissionForFrame and ChromeClientImpl::cancelGeolocationPermissionRequestForFrame
865
// FIXME: Remove ChromeClientImpl::requestGeolocationPermissionForFrame and ChromeClientImpl::cancelGeolocationPermissionRequestForFrame
848
// once all ports have moved to client-based geolocation (see https://bugs.webkit.org/show_bug.cgi?id=40373 ).
866
// once all ports have moved to client-based geolocation (see https://bugs.webkit.org/show_bug.cgi?id=40373 ).
849
// For client-based geolocation, these methods are now implemented as WebGeolocationClient::requestPermission and WebGeolocationClient::cancelPermissionRequest.
867
// For client-based geolocation, these methods are now implemented as WebGeolocationClient::requestPermission and WebGeolocationClient::cancelPermissionRequest.
- a/Source/WebKit/chromium/src/ChromeClientImpl.h +4 lines
Lines 33-38 a/Source/WebKit/chromium/src/ChromeClientImpl.h_sec1
33
#define ChromeClientImpl_h
33
#define ChromeClientImpl_h
34
34
35
#include "ChromeClientChromium.h"
35
#include "ChromeClientChromium.h"
36
#include "GraphicsLayer.h"
36
#include "PopupMenu.h"
37
#include "PopupMenu.h"
37
#include "SearchPopupMenu.h"
38
#include "SearchPopupMenu.h"
38
39
Lines 40-45 namespace WebCore { a/Source/WebKit/chromium/src/ChromeClientImpl.h_sec2
40
class AccessibilityObject;
41
class AccessibilityObject;
41
class Element;
42
class Element;
42
class FileChooser;
43
class FileChooser;
44
class Node;
43
class PopupContainer;
45
class PopupContainer;
44
class PopupMenuClient;
46
class PopupMenuClient;
45
class RenderBox;
47
class RenderBox;
Lines 132-137 public: a/Source/WebKit/chromium/src/ChromeClientImpl.h_sec3
132
    virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
134
    virtual void reachedMaxAppCacheSize(int64_t spaceNeeded);
133
    virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*, int64_t totalSpaceNeeded);
135
    virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*, int64_t totalSpaceNeeded);
134
    virtual bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
136
    virtual bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&);
137
    virtual void addOrUpdateScrollingLayer(WebCore::Node*, WebCore::PlatformLayer* scrollingLayer, WebCore::PlatformLayer* contentsLayer, const WebCore::IntSize& scrollSize);
138
    virtual void removeScrollingLayer(WebCore::Node*, WebCore::PlatformLayer* scrollingLayer, WebCore::PlatformLayer* contentsLayer);
135
    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*);
139
    virtual void requestGeolocationPermissionForFrame(WebCore::Frame*, WebCore::Geolocation*);
136
    virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*);
140
    virtual void cancelGeolocationPermissionRequestForFrame(WebCore::Frame*, WebCore::Geolocation*);
137
    virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
141
    virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>);
- a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp -4 / +92 lines
Lines 125-140 TEST_F(CCLayerTreeHostImplTest, scrollDeltaRepeatedScrolls) a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp_sec1
125
    OwnPtr<CCScrollAndScaleSet> scrollInfo;
125
    OwnPtr<CCScrollAndScaleSet> scrollInfo;
126
126
127
    scrollInfo = m_hostImpl->processScrollDeltas();
127
    scrollInfo = m_hostImpl->processScrollDeltas();
128
    ASSERT_EQ(scrollInfo->scrolls.size(), 1u);
128
    ASSERT_EQ(scrollInfo->scrolls.size(), 0u);
129
    EXPECT_EQ(root->sentScrollDelta(), scrollDelta);
129
    EXPECT_EQ(root->sentScrollDelta(), scrollDelta);
130
    expectContains(*scrollInfo.get(), root->id(), scrollDelta);
130
    ASSERT_EQ(scrollInfo->rootScrollDelta, scrollDelta);
131
131
132
    IntSize scrollDelta2(-5, 27);
132
    IntSize scrollDelta2(-5, 27);
133
    root->scrollBy(scrollDelta2);
133
    root->scrollBy(scrollDelta2);
134
    scrollInfo = m_hostImpl->processScrollDeltas();
134
    scrollInfo = m_hostImpl->processScrollDeltas();
135
    ASSERT_EQ(scrollInfo->scrolls.size(), 1u);
135
    ASSERT_EQ(scrollInfo->scrolls.size(), 0u);
136
    EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2);
136
    EXPECT_EQ(root->sentScrollDelta(), scrollDelta + scrollDelta2);
137
    expectContains(*scrollInfo.get(), root->id(), scrollDelta + scrollDelta2);
137
    ASSERT_EQ(scrollInfo->rootScrollDelta, scrollDelta + scrollDelta2);
138
138
139
    root->scrollBy(IntSize());
139
    root->scrollBy(IntSize());
140
    scrollInfo = m_hostImpl->processScrollDeltas();
140
    scrollInfo = m_hostImpl->processScrollDeltas();
Lines 155-160 TEST_F(CCLayerTreeHostImplTest, scrollRootCallsCommitAndRedraw) a/Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp_sec2
155
    EXPECT_TRUE(m_didRequestCommit);
155
    EXPECT_TRUE(m_didRequestCommit);
156
}
156
}
157
157
158
TEST_F(CCLayerTreeHostImplTest, scrollRootIgnored)
159
{
160
    RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
161
    root->setScrollable(false);
162
    m_hostImpl->setRootLayer(root);
163
    EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0)), CCInputHandlerClient::ScrollIgnored);
164
    EXPECT_FALSE(m_didRequestRedraw);
165
    EXPECT_FALSE(m_didRequestCommit);
166
}
167
168
TEST_F(CCLayerTreeHostImplTest, scrollChildCallsCommitAndRedraw)
169
{
170
    RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
171
    root->setScrollable(false);
172
    RefPtr<CCLayerImpl> child = CCLayerImpl::create(0);
173
    child->setScrollable(true);
174
    child->setMaxScrollPosition(IntSize(100, 100));
175
    child->setDrawsContent(true);
176
    child->setVisibleLayerRect(IntRect(IntPoint(), IntSize(10, 10)));
177
    root->addChild(child);
178
    m_hostImpl->setRootLayer(root);
179
180
    EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5)), CCInputHandlerClient::ScrollStarted);
181
    m_hostImpl->scrollBy(IntSize(0, 10));
182
    m_hostImpl->scrollEnd();
183
    EXPECT_TRUE(m_didRequestRedraw);
184
    EXPECT_TRUE(m_didRequestCommit);
185
}
186
187
TEST_F(CCLayerTreeHostImplTest, scrollMissesChild)
188
{
189
    RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
190
    root->setScrollable(false);
191
    RefPtr<CCLayerImpl> child = CCLayerImpl::create(0);
192
    child->setScrollable(true);
193
    child->setMaxScrollPosition(IntSize(100, 100));
194
    child->setDrawsContent(true);
195
    child->setVisibleLayerRect(IntRect(IntPoint(), IntSize(10, 10)));
196
    root->addChild(child);
197
    m_hostImpl->setRootLayer(root);
198
    EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(15, 5)), CCInputHandlerClient::ScrollIgnored);
199
    EXPECT_FALSE(m_didRequestRedraw);
200
    EXPECT_FALSE(m_didRequestCommit);
201
}
202
203
TEST_F(CCLayerTreeHostImplTest, scrollRootAndChangePageScale)
204
{
205
    RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
206
    root->setScrollable(true);
207
    root->setMaxScrollPosition(IntSize(100, 100));
208
    root->setDrawsContent(true);
209
    root->setVisibleLayerRect(IntRect(IntPoint(), IntSize(10, 10)));
210
    m_hostImpl->setRootLayer(root);
211
212
    IntSize scrollDelta(0, 10);
213
    EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5)), CCInputHandlerClient::ScrollStarted);
214
    m_hostImpl->scrollBy(scrollDelta);
215
    m_hostImpl->setPageScaleFactorAndLimits(2, 1, 2);
216
217
    // The scale should apply to the root scroll delta.
218
    OwnPtr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas();
219
    EXPECT_EQ(scrollInfo->rootScrollDelta, IntSize(scrollDelta.width() * 2, scrollDelta.height() * 2));
220
}
221
222
TEST_F(CCLayerTreeHostImplTest, scrollChildAndChangePageScale)
223
{
224
    RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
225
    RefPtr<CCLayerImpl> scrollRoot = CCLayerImpl::create(0);
226
    scrollRoot->setScrollable(true);
227
    RefPtr<CCLayerImpl> child = CCLayerImpl::create(0);
228
    child->setScrollable(true);
229
    child->setMaxScrollPosition(IntSize(100, 100));
230
    child->setDrawsContent(true);
231
    child->setVisibleLayerRect(IntRect(IntPoint(), IntSize(10, 10)));
232
    root->addChild(scrollRoot);
233
    scrollRoot->addChild(child);
234
    m_hostImpl->setRootLayer(scrollRoot);
235
236
    IntSize scrollDelta(0, 10);
237
    EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(5, 5)), CCInputHandlerClient::ScrollStarted);
238
    m_hostImpl->scrollBy(scrollDelta);
239
    m_hostImpl->setPageScaleFactorAndLimits(2, 1, 2);
240
241
    // The scale should not apply to the child scroll delta.
242
    OwnPtr<CCScrollAndScaleSet> scrollInfo = m_hostImpl->processScrollDeltas();
243
    expectContains(*scrollInfo.get(), child->id(), scrollDelta);
244
}
245
158
class BlendStateTrackerContext: public MockWebGraphicsContext3D {
246
class BlendStateTrackerContext: public MockWebGraphicsContext3D {
159
public:
247
public:
160
    BlendStateTrackerContext() : m_blend(false) { }
248
    BlendStateTrackerContext() : m_blend(false) { }
- a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp -1 / +115 lines
Lines 922-927 TEST_F(CCLayerTreeHostTestSetVisible, runMultiThread) a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp_sec1
922
    runTest(true);
922
    runTest(true);
923
}
923
}
924
924
925
class CCLayerTreeHostTestScrollBase : public CCLayerTreeHostTestThreadOnly {
926
public:
927
    virtual void beginTest()
928
    {
929
        m_rootScrollLayer = LayerChromium::create(0);
930
        m_rootScrollLayer->setBounds(IntSize(10, 10));
931
        m_rootScrollLayer->setScrollable(true);
932
        m_rootScrollLayer->setMaxScrollPosition(IntSize(100, 100));
933
        m_layerTreeHost->rootLayer()->addChild(m_rootScrollLayer);
934
        m_childLayer = LayerChromium::create(0);
935
        m_childLayer->setBounds(IntSize(10, 10));
936
        m_childLayer->setScrollable(true);
937
        m_childLayer->setMaxScrollPosition(IntSize(100, 100));
938
        m_rootScrollLayer->addChild(m_childLayer);
939
        postSetNeedsCommitToMainThread();
940
    }
941
942
    virtual void applyScrollAndScale(const IntSize& scrollDelta, float)
943
    {
944
        IntPoint position = m_rootScrollLayer->scrollPosition();
945
        m_rootScrollLayer->setScrollPosition(position + scrollDelta);
946
    }
947
948
    virtual void afterTest()
949
    {
950
    }
951
protected:
952
    RefPtr<LayerChromium> m_childLayer;
953
    RefPtr<LayerChromium> m_rootScrollLayer;
954
};
955
956
class CCLayerTreeHostTestScrollChildLayer : public CCLayerTreeHostTestScrollBase {
957
public:
958
    CCLayerTreeHostTestScrollChildLayer()
959
        : m_scrollAmount(2, 1)
960
    {
961
    }
962
963
    virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl)
964
    {
965
        EXPECT_EQ(m_rootScrollLayer->scrollPosition(), IntPoint());
966
        if (!m_layerTreeHost->frameNumber())
967
            EXPECT_EQ(m_childLayer->scrollPosition(), IntPoint());
968
        else
969
            EXPECT_EQ(m_childLayer->scrollPosition(), IntPoint() + m_scrollAmount);
970
    }
971
972
    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
973
    {
974
        if (impl->frameNumber() == 1) {
975
            EXPECT_TRUE(impl->scrollBegin(IntPoint(5, 5)));
976
            impl->scrollBy(m_scrollAmount);
977
            impl->scrollEnd();
978
        } else if (impl->frameNumber() == 2)
979
            endTest();
980
    }
981
private:
982
    const IntSize m_scrollAmount;
983
};
984
985
TEST_F(CCLayerTreeHostTestScrollChildLayer, runMultiThread)
986
{
987
    runTestThreaded();
988
}
989
990
class CCLayerTreeHostTestScrollChildLayerBeyondLimit : public CCLayerTreeHostTestScrollBase {
991
public:
992
    CCLayerTreeHostTestScrollChildLayerBeyondLimit()
993
        : m_initialRootScrollPosition(10, 10)
994
        , m_initialChildScrollPosition(20, 0)
995
        , m_scrollAmount(-25, -5)
996
    {
997
    }
998
999
    virtual void beginTest()
1000
    {
1001
        CCLayerTreeHostTestScrollBase::beginTest();
1002
        m_rootScrollLayer->setScrollPosition(m_initialRootScrollPosition);
1003
        m_childLayer->setScrollPosition(m_initialChildScrollPosition);
1004
    }
1005
1006
    virtual void beginCommitOnCCThread(CCLayerTreeHostImpl* impl)
1007
    {
1008
        if (m_layerTreeHost->frameNumber() == 1) {
1009
            CCLayerImpl* root = impl->rootLayer();
1010
            CCLayerImpl* scrollRoot = root->children()[0].get();
1011
            CCLayerImpl* child = scrollRoot->children()[0].get();
1012
            EXPECT_EQ(scrollRoot->scrollPosition(), m_initialRootScrollPosition);
1013
            EXPECT_EQ(scrollRoot->scrollDelta(), IntSize(0, -5));
1014
            EXPECT_EQ(child->scrollPosition(), m_initialChildScrollPosition);
1015
            EXPECT_EQ(child->scrollDelta(), IntSize(-20, 0));
1016
        }
1017
    }
1018
1019
    virtual void drawLayersOnCCThread(CCLayerTreeHostImpl* impl)
1020
    {
1021
        if (impl->frameNumber() == 1) {
1022
            EXPECT_TRUE(impl->scrollBegin(IntPoint(5, 5)));
1023
            impl->scrollBy(m_scrollAmount);
1024
            impl->scrollEnd();
1025
        } else if (impl->frameNumber() == 2) {
1026
            endTest();
1027
        }
1028
    }
1029
private:
1030
    const IntPoint m_initialRootScrollPosition;
1031
    const IntPoint m_initialChildScrollPosition;
1032
    const IntSize m_scrollAmount;
1033
};
1034
1035
TEST_F(CCLayerTreeHostTestScrollChildLayerBeyondLimit, runMultiThread)
1036
{
1037
    runTestThreaded();
1038
}
1039
925
class TestOpacityChangeLayerDelegate : public CCLayerDelegate {
1040
class TestOpacityChangeLayerDelegate : public CCLayerDelegate {
926
public:
1041
public:
927
    TestOpacityChangeLayerDelegate(CCLayerTreeHostTest* test)
1042
    TestOpacityChangeLayerDelegate(CCLayerTreeHostTest* test)
928
- 

Return to Bug 73350