Title: [103180] trunk/Source
Revision
103180
Author
ander...@apple.com
Date
2011-12-18 10:56:22 -0800 (Sun, 18 Dec 2011)

Log Message

Add a scrolling thread to the scrolling coordinator
https://bugs.webkit.org/show_bug.cgi?id=74814

Reviewed by Andreas Kling.

Source/WebCore:

* WebCore.exp.in:
Export ScrollingCoordinator::handleWheelEvent.

* WebCore.xcodeproj/project.pbxproj:
Add ScrollingCoordinatorMac.mm

* page/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::handleWheelEvent):
Add a stub function.

* page/ScrollingCoordinator.h:
* page/mac/ScrollingCoordinatorMac.mm: Added.
Add a ScrollingThread object which creates a thread and attaches a run loop source
to it, allowing for functions to be dispatched and run on said thread.

(WebCore::ScrollingCoordinator::isScrollingThread):
Call ScrollingThread::isCurrentThread.

(WebCore::ScrollingCoordinator::dispatchOnScrollingThread):
Call ScrollingThread::dispatch.

Source/WebKit2:

Check if the scrolling coordinator can handle the wheel event before dispatching it
to the main thread.

* WebProcess/WebPage/EventDispatcher.cpp:
(WebKit::EventDispatcher::wheelEvent):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103179 => 103180)


--- trunk/Source/WebCore/ChangeLog	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebCore/ChangeLog	2011-12-18 18:56:22 UTC (rev 103180)
@@ -1,5 +1,33 @@
 2011-12-18  Anders Carlsson  <ander...@apple.com>
 
+        Add a scrolling thread to the scrolling coordinator
+        https://bugs.webkit.org/show_bug.cgi?id=74814
+
+        Reviewed by Andreas Kling.
+
+        * WebCore.exp.in:
+        Export ScrollingCoordinator::handleWheelEvent.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        Add ScrollingCoordinatorMac.mm
+
+        * page/ScrollingCoordinator.cpp:
+        (WebCore::ScrollingCoordinator::handleWheelEvent):
+        Add a stub function.
+
+        * page/ScrollingCoordinator.h:
+        * page/mac/ScrollingCoordinatorMac.mm: Added.
+        Add a ScrollingThread object which creates a thread and attaches a run loop source
+        to it, allowing for functions to be dispatched and run on said thread.
+
+        (WebCore::ScrollingCoordinator::isScrollingThread):
+        Call ScrollingThread::isCurrentThread.
+
+        (WebCore::ScrollingCoordinator::dispatchOnScrollingThread):
+        Call ScrollingThread::dispatch.
+
+2011-12-18  Anders Carlsson  <ander...@apple.com>
+
         EventDispatcher should keep track of all scrolling coordinators
         https://bugs.webkit.org/show_bug.cgi?id=74810
 

Modified: trunk/Source/WebCore/WebCore.exp.in (103179 => 103180)


--- trunk/Source/WebCore/WebCore.exp.in	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebCore/WebCore.exp.in	2011-12-18 18:56:22 UTC (rev 103180)
@@ -2019,6 +2019,7 @@
 #endif
 
 #if ENABLE(THREADED_SCROLLING)
+__ZN7WebCore20ScrollingCoordinator16handleWheelEventERKNS_18PlatformWheelEventE
 __ZN7WebCore20ScrollingCoordinatorD1Ev
 __ZN7WebCore4Page20scrollingCoordinatorEv
 #endif

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (103179 => 103180)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2011-12-18 18:56:22 UTC (rev 103180)
@@ -357,6 +357,7 @@
 		1A1414B613A0F0500019996C /* WebKitFontFamilyNames.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 1A1414B413A0F0500019996C /* WebKitFontFamilyNames.h */; settings = {ATTRIBUTES = (); }; };
 		1A1D13800A5325520064BF5F /* DOMXPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A1D137E0A5325520064BF5F /* DOMXPath.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A1D13810A5325520064BF5F /* DOMXPath.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1D137F0A5325520064BF5F /* DOMXPath.mm */; };
+		1A1F28A1149E629800FBC35F /* ScrollingCoordinatorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A1F289F149E629800FBC35F /* ScrollingCoordinatorMac.mm */; };
 		1A219B3B0DCA87AB0040E3A0 /* npfunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A219B3A0DCA87AB0040E3A0 /* npfunctions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1A2246490CC98DDB00C05240 /* SQLiteDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2246430CC98DDB00C05240 /* SQLiteDatabase.cpp */; };
 		1A22464A0CC98DDB00C05240 /* SQLiteDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2246440CC98DDB00C05240 /* SQLiteDatabase.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -7487,6 +7488,7 @@
 		1A1414B413A0F0500019996C /* WebKitFontFamilyNames.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebKitFontFamilyNames.h; sourceTree = "<group>"; };
 		1A1D137E0A5325520064BF5F /* DOMXPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMXPath.h; sourceTree = "<group>"; };
 		1A1D137F0A5325520064BF5F /* DOMXPath.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMXPath.mm; sourceTree = "<group>"; };
+		1A1F289F149E629800FBC35F /* ScrollingCoordinatorMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingCoordinatorMac.mm; sourceTree = "<group>"; };
 		1A219B3A0DCA87AB0040E3A0 /* npfunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = npfunctions.h; sourceTree = "<group>"; };
 		1A2246430CC98DDB00C05240 /* SQLiteDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SQLiteDatabase.cpp; path = sql/SQLiteDatabase.cpp; sourceTree = "<group>"; };
 		1A2246440CC98DDB00C05240 /* SQLiteDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SQLiteDatabase.h; path = sql/SQLiteDatabase.h; sourceTree = "<group>"; };
@@ -17189,6 +17191,7 @@
 				93C09A7E0B064EEF005ABD4D /* EventHandlerMac.mm */,
 				65BF023C0974819000C43196 /* FrameMac.mm */,
 				1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */,
+				1A1F289F149E629800FBC35F /* ScrollingCoordinatorMac.mm */,
 				F587854C02DE375901EA4122 /* WebCoreFrameView.h */,
 			);
 			path = mac;
@@ -27838,6 +27841,7 @@
 				1A2F9D7914968C740065AC63 /* ScrollingCoordinator.cpp in Sources */,
 				1AA7160A149BC4DB0016EC19 /* TileCache.mm in Sources */,
 				1AA7161E149BF2FA0016EC19 /* WebTileLayer.mm in Sources */,
+				1A1F28A1149E629800FBC35F /* ScrollingCoordinatorMac.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebCore/page/ScrollingCoordinator.cpp (103179 => 103180)


--- trunk/Source/WebCore/page/ScrollingCoordinator.cpp	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebCore/page/ScrollingCoordinator.cpp	2011-12-18 18:56:22 UTC (rev 103180)
@@ -24,12 +24,14 @@
  */
 
 #include "config.h"
+
+#if ENABLE(THREADED_SCROLLING)
+
 #include "ScrollingCoordinator.h"
 
+#include <wtf/Functional.h>
 #include <wtf/PassRefPtr.h>
 
-#if ENABLE(THREADED_SCROLLING)
-
 namespace WebCore {
 
 PassRefPtr<ScrollingCoordinator> ScrollingCoordinator::create(Page* page)
@@ -53,6 +55,12 @@
     m_page = 0;
 }
 
+bool ScrollingCoordinator::handleWheelEvent(const PlatformWheelEvent&)
+{
+    // FIXME: Implement.
+    return false;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(THREADED_SCROLLING)

Modified: trunk/Source/WebCore/page/ScrollingCoordinator.h (103179 => 103180)


--- trunk/Source/WebCore/page/ScrollingCoordinator.h	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebCore/page/ScrollingCoordinator.h	2011-12-18 18:56:22 UTC (rev 103180)
@@ -44,9 +44,18 @@
 
     void pageDestroyed();
 
+    // Can be called from any thread. Will try to handle the wheel event on the scrolling thread,
+    // and return false if the event must be sent again to the WebCore event handler.
+    bool handleWheelEvent(const PlatformWheelEvent&);
+
 private:
     explicit ScrollingCoordinator(Page*);
 
+    // FIXME: Once we have a proper thread/run loop abstraction we should get rid of these
+    // functions and just use something like scrollingRunLoop()->dispatch(function);
+    static bool isScrollingThread();
+    static void dispatchOnScrollingThread(const Function<void()>&);
+
 private:
     Page* m_page;
 };

Added: trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm (0 => 103180)


--- trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm	2011-12-18 18:56:22 UTC (rev 103180)
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if ENABLE(THREADED_SCROLLING)
+
+#import "ScrollingCoordinator.h"
+
+#import <wtf/Functional.h>
+#import <wtf/MainThread.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/StdlibExtras.h>
+#import <wtf/Vector.h>
+
+namespace WebCore {
+
+class ScrollingThread {
+public:
+    ScrollingThread()
+        : m_threadIdentifier(0)
+    {
+    }
+
+    bool isCurrentThread() const;
+    void dispatch(const Function<void()>&);
+
+private:
+    void createThreadIfNeeded();
+
+    static void* threadCallback(void* scrollingThread);
+    void threadBody();
+
+    static void threadRunLoopSourceCallback(void* scrollingThread);
+    void threadRunLoopSourceCallback();
+
+    ThreadIdentifier m_threadIdentifier;
+
+    ThreadCondition m_initializeRunLoopCondition;
+    Mutex m_initializeRunLoopConditionMutex;
+    
+    RetainPtr<CFRunLoopRef> m_threadRunLoop;
+    RetainPtr<CFRunLoopSourceRef> m_threadRunLoopSource;
+
+    Mutex m_functionsMutex;
+    Vector<Function<void()> > m_functions;
+};
+
+bool ScrollingThread::isCurrentThread() const
+{
+    if (!m_threadIdentifier)
+        return false;
+
+    return currentThread() == m_threadIdentifier;
+}
+
+void ScrollingThread::createThreadIfNeeded()
+{
+    if (m_threadIdentifier)
+        return;
+
+    m_threadIdentifier = createThread(threadCallback, this, "WebCore: Scrolling");
+
+    // Wait for the thread to initialize the run loop.
+    {
+        MutexLocker locker(m_initializeRunLoopConditionMutex);
+
+        while (!m_threadRunLoop)
+            m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex);
+    }
+}
+
+void* ScrollingThread::threadCallback(void *scrollingThread)
+{
+    static_cast<ScrollingThread*>(scrollingThread)->threadBody();
+
+    return 0;
+}
+
+void ScrollingThread::threadBody()
+{
+    ASSERT(isCurrentThread());
+
+    // Initialize the run loop.
+    {
+        MutexLocker locker(m_initializeRunLoopConditionMutex);
+
+        m_threadRunLoop = CFRunLoopGetCurrent();
+
+        CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, threadRunLoopSourceCallback };
+        m_threadRunLoopSource = adoptCF(CFRunLoopSourceCreate(0, 0, &context));
+        CFRunLoopAddSource(CFRunLoopGetCurrent(), m_threadRunLoopSource.get(), kCFRunLoopDefaultMode);
+
+        m_initializeRunLoopCondition.broadcast();
+    }
+
+    CFRunLoopRun();
+}
+
+void ScrollingThread::threadRunLoopSourceCallback(void* scrollingThread)
+{
+    static_cast<ScrollingThread*>(scrollingThread)->threadRunLoopSourceCallback();
+}
+
+void ScrollingThread::threadRunLoopSourceCallback()
+{
+    ASSERT(isCurrentThread());
+
+    Vector<Function<void ()> > functions;
+
+    {
+        MutexLocker locker(m_functionsMutex);
+        m_functions.swap(functions);
+    }
+
+    for (size_t i = 0; i < functions.size(); ++i)
+        functions[i]();
+}
+
+void ScrollingThread::dispatch(const Function<void()>& function)
+{
+    createThreadIfNeeded();
+
+    {
+        MutexLocker locker(m_functionsMutex);
+        m_functions.append(function);
+    }
+
+    CFRunLoopSourceSignal(m_threadRunLoopSource.get());
+    CFRunLoopWakeUp(m_threadRunLoop.get());
+}
+
+static ScrollingThread& scrollingThread()
+{
+    DEFINE_STATIC_LOCAL(ScrollingThread, scrollingThread, ());
+    return scrollingThread;
+}
+
+bool ScrollingCoordinator::isScrollingThread()
+{
+    return scrollingThread().isCurrentThread();
+}
+
+void ScrollingCoordinator::dispatchOnScrollingThread(const Function<void()>& function)
+{
+    return scrollingThread().dispatch(function);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_SCROLLING)

Modified: trunk/Source/WebKit2/ChangeLog (103179 => 103180)


--- trunk/Source/WebKit2/ChangeLog	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebKit2/ChangeLog	2011-12-18 18:56:22 UTC (rev 103180)
@@ -1,5 +1,18 @@
 2011-12-18  Anders Carlsson  <ander...@apple.com>
 
+        Add a scrolling thread to the scrolling coordinator
+        https://bugs.webkit.org/show_bug.cgi?id=74814
+
+        Reviewed by Andreas Kling.
+
+        Check if the scrolling coordinator can handle the wheel event before dispatching it
+        to the main thread.
+
+        * WebProcess/WebPage/EventDispatcher.cpp:
+        (WebKit::EventDispatcher::wheelEvent):
+
+2011-12-18  Anders Carlsson  <ander...@apple.com>
+
         EventDispatcher should keep track of all scrolling coordinators
         https://bugs.webkit.org/show_bug.cgi?id=74810
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/EventDispatcher.cpp (103179 => 103180)


--- trunk/Source/WebKit2/WebProcess/WebPage/EventDispatcher.cpp	2011-12-18 18:01:53 UTC (rev 103179)
+++ trunk/Source/WebKit2/WebProcess/WebPage/EventDispatcher.cpp	2011-12-18 18:56:22 UTC (rev 103180)
@@ -80,6 +80,18 @@
 
 void EventDispatcher::wheelEvent(uint64_t pageID, const WebWheelEvent& wheelEvent)
 {
+#if ENABLE(THREADED_SCROLLING)
+    MutexLocker locker(m_scrollingCoordinatorsMutex);
+    if (ScrollingCoordinator* scrollingCoordinator = m_scrollingCoordinators.get(pageID).get()) {
+        PlatformWheelEvent platformWheelEvent = platform(wheelEvent);
+
+        if (scrollingCoordinator->handleWheelEvent(platformWheelEvent)) {
+            sendDidHandleEvent(pageID, wheelEvent);
+            return;
+        }
+    }
+#endif
+
     RunLoop::main()->dispatch(bind(&EventDispatcher::dispatchWheelEvent, this, pageID, wheelEvent));
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to