Skip to content
Permalink
Browse files
[chromium] Wire up shouldUpdateScrollPositionOnMainThread and nonFast…
…ScrollableRegion to compositor

https://bugs.webkit.org/show_bug.cgi?id=79155

Reviewed by Adam Barth.

Source/WebCore:

This hooks up ScrollingCoordinator::setNonFastScrollableRegion() and
ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread() to the chromium compositor
implementation and implements them on the impl thread.

New compositor behavior is covered by unit tests in LayerChromiumTests and CCLayerTreeHostImplTests. The rest is
just glue code.

* page/scrolling/chromium/ScrollingCoordinatorChromium.cpp:
(WebCore::ScrollingCoordinator::setNonFastScrollableRegion):
(WebCore::ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread):
* platform/graphics/chromium/LayerChromium.cpp:
(WebCore::LayerChromium::LayerChromium):
(WebCore::LayerChromium::setShouldScrollOnMainThread):
(WebCore):
(WebCore::LayerChromium::setNonFastScrollableRegion):
(WebCore::LayerChromium::pushPropertiesTo):
* platform/graphics/chromium/LayerChromium.h:
(WebCore):
(LayerChromium):
* platform/graphics/chromium/cc/CCLayerImpl.cpp:
(WebCore::CCLayerImpl::CCLayerImpl):
* platform/graphics/chromium/cc/CCLayerImpl.h:
(WebCore::CCLayerImpl::shouldScrollOnMainThread):
(WebCore::CCLayerImpl::setShouldScrollOnMainThread):
(CCLayerImpl):
(WebCore::CCLayerImpl::nonFastScrollableRegion):
(WebCore::CCLayerImpl::setNonFastScrollableRegion):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::scrollBegin):

Source/WebKit/chromium:

Add new tests for shouldScrollOnMainThread and nonFastScrollableRegion properties.

* tests/CCLayerTreeHostImplTest.cpp:
(WebKit::TEST_F):
(WebKit):
* tests/LayerChromiumTest.cpp:

Canonical link: https://commits.webkit.org/96707@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@108937 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
jamesr committed Feb 27, 2012
1 parent ebe9983 commit f34c04674ffd4f27dbc0c83e599ea7306bde445c
Showing 10 changed files with 169 additions and 6 deletions.
@@ -1,3 +1,40 @@
2012-02-26 James Robinson <jamesr@chromium.org>

[chromium] Wire up shouldUpdateScrollPositionOnMainThread and nonFastScrollableRegion to compositor
https://bugs.webkit.org/show_bug.cgi?id=79155

Reviewed by Adam Barth.

This hooks up ScrollingCoordinator::setNonFastScrollableRegion() and
ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread() to the chromium compositor
implementation and implements them on the impl thread.

New compositor behavior is covered by unit tests in LayerChromiumTests and CCLayerTreeHostImplTests. The rest is
just glue code.

* page/scrolling/chromium/ScrollingCoordinatorChromium.cpp:
(WebCore::ScrollingCoordinator::setNonFastScrollableRegion):
(WebCore::ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread):
* platform/graphics/chromium/LayerChromium.cpp:
(WebCore::LayerChromium::LayerChromium):
(WebCore::LayerChromium::setShouldScrollOnMainThread):
(WebCore):
(WebCore::LayerChromium::setNonFastScrollableRegion):
(WebCore::LayerChromium::pushPropertiesTo):
* platform/graphics/chromium/LayerChromium.h:
(WebCore):
(LayerChromium):
* platform/graphics/chromium/cc/CCLayerImpl.cpp:
(WebCore::CCLayerImpl::CCLayerImpl):
* platform/graphics/chromium/cc/CCLayerImpl.h:
(WebCore::CCLayerImpl::shouldScrollOnMainThread):
(WebCore::CCLayerImpl::setShouldScrollOnMainThread):
(CCLayerImpl):
(WebCore::CCLayerImpl::nonFastScrollableRegion):
(WebCore::CCLayerImpl::setNonFastScrollableRegion):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::scrollBegin):

2012-02-26 Kentaro Hara <haraken@chromium.org>

Unreviewed. Rebaselined run-bindings-tests results.
@@ -73,9 +73,10 @@ void ScrollingCoordinator::setScrollLayer(GraphicsLayer* scrollLayer)
m_private->setScrollLayer(scrollLayer ? scrollLayer->platformLayer() : 0);
}

void ScrollingCoordinator::setNonFastScrollableRegion(const Region&)
void ScrollingCoordinator::setNonFastScrollableRegion(const Region& region)
{
// FIXME: Implement!
if (LayerChromium* layer = m_private->scrollLayer())
layer->setNonFastScrollableRegion(region);
}

void ScrollingCoordinator::setScrollParameters(ScrollElasticity horizontalScrollElasticity, ScrollElasticity verticalScrollElasticity,
@@ -93,7 +94,8 @@ void ScrollingCoordinator::setWheelEventHandlerCount(unsigned wheelEventHandlerC

void ScrollingCoordinator::setShouldUpdateScrollLayerPositionOnMainThread(bool should)
{
// FIXME: Implement!
if (LayerChromium* layer = m_private->scrollLayer())
layer->setShouldScrollOnMainThread(should);
}

}
@@ -42,7 +42,6 @@
#include "NativeImageSkia.h"
#include "PlatformContextSkia.h"
#endif
#include "Region.h"
#include "RenderLayerBacking.h"
#include "TextStream.h"
#include "skia/ext/platform_canvas.h"
@@ -64,7 +63,9 @@ LayerChromium::LayerChromium()
, m_parent(0)
, m_layerAnimationController(CCLayerAnimationController::create())
, m_scrollable(false)
, m_shouldScrollOnMainThread(false)
, m_haveWheelEventHandlers(false)
, m_nonFastScrollableRegionChanged(false)
, m_anchorPoint(0.5, 0.5)
, m_backgroundColor(0, 0, 0, 0)
, m_backgroundCoversViewport(false)
@@ -440,6 +441,14 @@ void LayerChromium::setScrollable(bool scrollable)
setNeedsCommit();
}

void LayerChromium::setShouldScrollOnMainThread(bool shouldScrollOnMainThread)
{
if (m_shouldScrollOnMainThread == shouldScrollOnMainThread)
return;
m_shouldScrollOnMainThread = shouldScrollOnMainThread;
setNeedsCommit();
}

void LayerChromium::setHaveWheelEventHandlers(bool haveWheelEventHandlers)
{
if (m_haveWheelEventHandlers == haveWheelEventHandlers)
@@ -448,6 +457,15 @@ void LayerChromium::setHaveWheelEventHandlers(bool haveWheelEventHandlers)
setNeedsCommit();
}

void LayerChromium::setNonFastScrollableRegion(const Region& region)
{
if (m_nonFastScrollableRegion == region)
return;
m_nonFastScrollableRegion = region;
m_nonFastScrollableRegionChanged = true;
setNeedsCommit();
}

void LayerChromium::setDoubleSided(bool doubleSided)
{
if (m_doubleSided == doubleSided)
@@ -502,7 +520,14 @@ void LayerChromium::pushPropertiesTo(CCLayerImpl* layer)
layer->setIsNonCompositedContent(m_isNonCompositedContent);
layer->setMasksToBounds(m_masksToBounds);
layer->setScrollable(m_scrollable);
layer->setShouldScrollOnMainThread(m_shouldScrollOnMainThread);
layer->setHaveWheelEventHandlers(m_haveWheelEventHandlers);
// Copying a Region is more expensive than most layer properties, since it involves copying two Vectors that may be
// arbitrarily large depending on page content, so we only push the property if it's changed.
if (m_nonFastScrollableRegionChanged) {
layer->setNonFastScrollableRegion(m_nonFastScrollableRegion);
m_nonFastScrollableRegionChanged = false;
}
layer->setName(m_name);
layer->setOpaque(m_opaque);
layer->setOpacity(m_opacity);
@@ -39,6 +39,7 @@
#include "GraphicsContext.h"
#include "PlatformString.h"
#include "ProgramBinding.h"
#include "Region.h"
#include "RenderSurfaceChromium.h"
#include "ShaderChromium.h"
#include "TransformationMatrix.h"
@@ -60,7 +61,6 @@ class CCLayerImpl;
class CCLayerTreeHost;
class CCTextureUpdater;
class GraphicsContext3D;
class Region;

// Base class for composited layers. Special layer types are derived from
// this class.
@@ -134,7 +134,9 @@ class LayerChromium : public RefCounted<LayerChromium> {
const IntPoint& scrollPosition() const { return m_scrollPosition; }

void setScrollable(bool);
void setShouldScrollOnMainThread(bool);
void setHaveWheelEventHandlers(bool);
void setNonFastScrollableRegion(const Region&);

IntSize scrollDelta() const { return IntSize(); }

@@ -284,7 +286,10 @@ class LayerChromium : public RefCounted<LayerChromium> {
IntRect m_visibleLayerRect;
IntPoint m_scrollPosition;
bool m_scrollable;
bool m_shouldScrollOnMainThread;
bool m_haveWheelEventHandlers;
Region m_nonFastScrollableRegion;
bool m_nonFastScrollableRegionChanged;
FloatPoint m_position;
FloatPoint m_anchorPoint;
Color m_backgroundColor;
@@ -48,6 +48,7 @@ CCLayerImpl::CCLayerImpl(int id)
, m_anchorPoint(0.5, 0.5)
, m_anchorPointZ(0)
, m_scrollable(false)
, m_shouldScrollOnMainThread(false)
, m_haveWheelEventHandlers(false)
, m_backgroundCoversViewport(false)
, m_doubleSided(true)
@@ -30,6 +30,7 @@
#include "FilterOperations.h"
#include "FloatRect.h"
#include "IntRect.h"
#include "Region.h"
#include "TextStream.h"
#include "TransformationMatrix.h"
#include "cc/CCLayerAnimationControllerImpl.h"
@@ -181,9 +182,15 @@ class CCLayerImpl : public CCLayerAnimationControllerImplClient {
bool scrollable() const { return m_scrollable; }
void setScrollable(bool scrollable) { m_scrollable = scrollable; }

bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; }
void setShouldScrollOnMainThread(bool shouldScrollOnMainThread) { m_shouldScrollOnMainThread = shouldScrollOnMainThread; }

bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; }
void setHaveWheelEventHandlers(bool haveWheelEventHandlers) { m_haveWheelEventHandlers = haveWheelEventHandlers; }

const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRegion; }
void setNonFastScrollableRegion(const Region& region) { m_nonFastScrollableRegion = region; }

const IntRect& visibleLayerRect() const { return m_visibleLayerRect; }
void setVisibleLayerRect(const IntRect& visibleLayerRect) { m_visibleLayerRect = visibleLayerRect; }

@@ -251,7 +258,9 @@ class CCLayerImpl : public CCLayerAnimationControllerImplClient {
IntSize m_contentBounds;
IntPoint m_scrollPosition;
bool m_scrollable;
bool m_shouldScrollOnMainThread;
bool m_haveWheelEventHandlers;
Region m_nonFastScrollableRegion;
Color m_backgroundColor;
bool m_backgroundCoversViewport;

@@ -488,14 +488,25 @@ void CCLayerTreeHostImpl::setNeedsRedraw()
m_client->setNeedsRedrawOnImplThread();
}

CCInputHandlerClient::ScrollStatus CCLayerTreeHostImpl::scrollBegin(const IntPoint& point, CCInputHandlerClient::ScrollInputType type)
CCInputHandlerClient::ScrollStatus CCLayerTreeHostImpl::scrollBegin(const IntPoint& viewportPoint, CCInputHandlerClient::ScrollInputType type)
{
// TODO: Check for scrollable sublayers.
if (!m_scrollLayerImpl || !m_scrollLayerImpl->scrollable()) {
TRACE_EVENT("scrollBegin Ignored no scrollable", this, 0);
return ScrollIgnored;
}

if (m_scrollLayerImpl->shouldScrollOnMainThread()) {
TRACE_EVENT("scrollBegin Failed shouldScrollOnMainThread", this, 0);
return ScrollFailed;
}

IntPoint scrollLayerContentPoint(m_scrollLayerImpl->screenSpaceTransform().inverse().mapPoint(viewportPoint));
if (m_scrollLayerImpl->nonFastScrollableRegion().contains(scrollLayerContentPoint)) {
TRACE_EVENT("scrollBegin Failed nonFastScrollableRegion", this, 0);
return ScrollFailed;
}

if (type == CCInputHandlerClient::Wheel && m_scrollLayerImpl->haveWheelEventHandlers()) {
TRACE_EVENT("scrollBegin Failed wheelEventHandlers", this, 0);
return ScrollFailed;
@@ -1,3 +1,17 @@
2012-02-26 James Robinson <jamesr@chromium.org>

[chromium] Wire up shouldUpdateScrollPositionOnMainThread and nonFastScrollableRegion to compositor
https://bugs.webkit.org/show_bug.cgi?id=79155

Reviewed by Adam Barth.

Add new tests for shouldScrollOnMainThread and nonFastScrollableRegion properties.

* tests/CCLayerTreeHostImplTest.cpp:
(WebKit::TEST_F):
(WebKit):
* tests/LayerChromiumTest.cpp:

2012-02-25 Adrienne Walker <enne@google.com>

[chromium] Unreviewed gardening, fix Linux Clang OwnPtr breakage
@@ -205,6 +205,63 @@ TEST_F(CCLayerTreeHostImplTest, wheelEventHandlers)
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gesture), CCInputHandlerClient::ScrollStarted);
}

TEST_F(CCLayerTreeHostImplTest, shouldScrollOnMainThread)
{
RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
root->setScrollable(true);
root->setScrollPosition(IntPoint(0, 0));
root->setMaxScrollPosition(IntSize(100, 100));
m_hostImpl->setRootLayer(root);
root->setShouldScrollOnMainThread(true);
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollFailed);
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(0, 0), CCInputHandlerClient::Gesture), CCInputHandlerClient::ScrollFailed);
}

TEST_F(CCLayerTreeHostImplTest, nonFastScrollableRegionBasic)
{
RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
root->setScrollable(true);
root->setScrollPosition(IntPoint(0, 0));
root->setMaxScrollPosition(IntSize(100, 100));
m_hostImpl->setRootLayer(root);
root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50));
// All scroll types inside the non-fast scrollable region should fail.
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollFailed);
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(25, 25), CCInputHandlerClient::Gesture), CCInputHandlerClient::ScrollFailed);

// All scroll types outside this region should succeed.
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollStarted);
m_hostImpl->scrollBy(IntSize(0, 10));
m_hostImpl->scrollEnd();
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(75, 75), CCInputHandlerClient::Gesture), CCInputHandlerClient::ScrollStarted);
m_hostImpl->scrollBy(IntSize(0, 10));
m_hostImpl->scrollEnd();
}

TEST_F(CCLayerTreeHostImplTest, nonFastScrollableRegionWithOffset)
{
GraphicsContext3D::Attributes attrs;
RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new FakeWebGraphicsContext3D()), attrs, 0, GraphicsContext3D::RenderDirectlyToHostWindow, GraphicsContext3DPrivate::ForUseOnThisThread);
m_hostImpl->initializeLayerRenderer(context);

RefPtr<CCLayerImpl> root = CCLayerImpl::create(0);
root->setScrollable(true);
root->setScrollPosition(IntPoint(0, 0));
root->setMaxScrollPosition(IntSize(100, 100));
m_hostImpl->setRootLayer(root);
root->setNonFastScrollableRegion(IntRect(0, 0, 50, 50));
root->setPosition(FloatPoint(-25, 0));
m_hostImpl->drawLayers(); // Update draw transforms so we can correctly map points into layer space.

// This point would fall into the non-fast scrollable region except that we've moved the layer down by 25 pixels.
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(40, 10), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollStarted);
m_hostImpl->scrollBy(IntSize(0, 1));
m_hostImpl->scrollEnd();

// This point is still inside the non-fast region.
EXPECT_EQ(m_hostImpl->scrollBegin(IntPoint(10, 10), CCInputHandlerClient::Wheel), CCInputHandlerClient::ScrollFailed);
}

TEST_F(CCLayerTreeHostImplTest, pinchGesture)
{
setupScrollAndContentsLayers(IntSize(100, 100));
@@ -515,6 +515,8 @@ TEST_F(LayerChromiumTest, checkPropertyChangeCausesCorrectBehavior)
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setReplicaLayer(dummyLayer.get()));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setSublayerTransform(TransformationMatrix(0, 0, 0, 0, 0, 0)));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollable(true));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setShouldScrollOnMainThread(true));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setNonFastScrollableRegion(Region(IntRect(1, 1, 2, 2))));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setHaveWheelEventHandlers(true));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setScrollPosition(IntPoint(10, 10)));
EXECUTE_AND_VERIFY_SET_NEEDS_COMMIT_BEHAVIOR(1, testLayer->setTransform(TransformationMatrix(0, 0, 0, 0, 0, 0)));

0 comments on commit f34c046

Please sign in to comment.