Title: [106565] trunk/Source/WebCore
Revision
106565
Author
[email protected]
Date
2012-02-02 09:44:16 -0800 (Thu, 02 Feb 2012)

Log Message

Move ScrollingThread to its own file
https://bugs.webkit.org/show_bug.cgi?id=77652

Reviewed by Sam Weinig.

This just shuffles some classes around and makes ScrollingCoordinator call into ScrollingThread.
Hopefully we'll be able to make ScrollingThread use the new WebCore::RunLoop class eventually.

* WebCore.xcodeproj/project.pbxproj:
* page/scrolling/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::handleWheelEvent):
* page/scrolling/ScrollingCoordinator.h:
(ScrollingCoordinator):
* page/scrolling/ScrollingThread.cpp: Added.
(WebCore):
(WebCore::ScrollingThread::ScrollingThread):
(WebCore::ScrollingThread::isCurrentThread):
(WebCore::ScrollingThread::dispatch):
(WebCore::ScrollingThread::shared):
(WebCore::ScrollingThread::createThreadIfNeeded):
(WebCore::ScrollingThread::threadCallback):
(WebCore::ScrollingThread::threadBody):
(WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
* page/scrolling/ScrollingThread.h: Added.
(WebCore):
(ScrollingThread):
* page/scrolling/mac/ScrollingCoordinatorMac.mm:
(WebCore::ScrollingCoordinator::scrollByOnScrollingThread):
(WebCore::ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread):
* page/scrolling/mac/ScrollingThreadMac.mm: Added.
(WebCore):
(WebCore::ScrollingThread::initializeRunLoop):
(WebCore::ScrollingThread::wakeUpRunLoop):
(WebCore::ScrollingThread::threadRunLoopSourceCallback):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (106564 => 106565)


--- trunk/Source/WebCore/ChangeLog	2012-02-02 17:39:43 UTC (rev 106564)
+++ trunk/Source/WebCore/ChangeLog	2012-02-02 17:44:16 UTC (rev 106565)
@@ -1,3 +1,40 @@
+2012-02-02  Anders Carlsson  <[email protected]>
+
+        Move ScrollingThread to its own file
+        https://bugs.webkit.org/show_bug.cgi?id=77652
+
+        Reviewed by Sam Weinig.
+
+        This just shuffles some classes around and makes ScrollingCoordinator call into ScrollingThread.
+        Hopefully we'll be able to make ScrollingThread use the new WebCore::RunLoop class eventually.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * page/scrolling/ScrollingCoordinator.cpp:
+        (WebCore::ScrollingCoordinator::handleWheelEvent):
+        * page/scrolling/ScrollingCoordinator.h:
+        (ScrollingCoordinator):
+        * page/scrolling/ScrollingThread.cpp: Added.
+        (WebCore):
+        (WebCore::ScrollingThread::ScrollingThread):
+        (WebCore::ScrollingThread::isCurrentThread):
+        (WebCore::ScrollingThread::dispatch):
+        (WebCore::ScrollingThread::shared):
+        (WebCore::ScrollingThread::createThreadIfNeeded):
+        (WebCore::ScrollingThread::threadCallback):
+        (WebCore::ScrollingThread::threadBody):
+        (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
+        * page/scrolling/ScrollingThread.h: Added.
+        (WebCore):
+        (ScrollingThread):
+        * page/scrolling/mac/ScrollingCoordinatorMac.mm:
+        (WebCore::ScrollingCoordinator::scrollByOnScrollingThread):
+        (WebCore::ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread):
+        * page/scrolling/mac/ScrollingThreadMac.mm: Added.
+        (WebCore):
+        (WebCore::ScrollingThread::initializeRunLoop):
+        (WebCore::ScrollingThread::wakeUpRunLoop):
+        (WebCore::ScrollingThread::threadRunLoopSourceCallback):
+
 2012-02-02  Sheriff Bot  <[email protected]>
 
         Unreviewed, rolling out r106551.

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (106564 => 106565)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-02-02 17:39:43 UTC (rev 106564)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-02-02 17:44:16 UTC (rev 106565)
@@ -587,6 +587,9 @@
 		1AF62EE614DA22A70041556C /* ScrollingCoordinatorMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62EE314DA22A70041556C /* ScrollingCoordinatorMac.mm */; };
 		1AF62EE714DA22A70041556C /* ScrollingCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */; };
 		1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		1AF62F2414DAFE910041556C /* ScrollingThreadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */; };
+		1AF62F2514DAFE9E0041556C /* ScrollingThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62F2014DAFE790041556C /* ScrollingThread.cpp */; };
+		1AF62F2614DAFEA10041556C /* ScrollingThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF62F2114DAFE790041556C /* ScrollingThread.h */; };
 		1AF8E11A1256592600230FF7 /* ProxyServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF8E1191256592600230FF7 /* ProxyServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1AF8E13312565A4400230FF7 /* ProxyServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF8E13212565A4400230FF7 /* ProxyServer.cpp */; };
 		1AF8E1C3125673E000230FF7 /* ProxyServerCFNet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF8E1C1125673E000230FF7 /* ProxyServerCFNet.cpp */; };
@@ -7323,6 +7326,9 @@
 		1AF62EE314DA22A70041556C /* ScrollingCoordinatorMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingCoordinatorMac.mm; sourceTree = "<group>"; };
 		1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingCoordinator.cpp; sourceTree = "<group>"; };
 		1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingCoordinator.h; sourceTree = "<group>"; };
+		1AF62F2014DAFE790041556C /* ScrollingThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingThread.cpp; sourceTree = "<group>"; };
+		1AF62F2114DAFE790041556C /* ScrollingThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingThread.h; sourceTree = "<group>"; };
+		1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingThreadMac.mm; sourceTree = "<group>"; };
 		1AF8E1191256592600230FF7 /* ProxyServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyServer.h; sourceTree = "<group>"; };
 		1AF8E13212565A4400230FF7 /* ProxyServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyServer.cpp; sourceTree = "<group>"; };
 		1AF8E1C1125673E000230FF7 /* ProxyServerCFNet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyServerCFNet.cpp; sourceTree = "<group>"; };
@@ -13911,6 +13917,8 @@
 				1AF62EE214DA22A70041556C /* mac */,
 				1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */,
 				1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */,
+				1AF62F2014DAFE790041556C /* ScrollingThread.cpp */,
+				1AF62F2114DAFE790041556C /* ScrollingThread.h */,
 			);
 			path = scrolling;
 			sourceTree = "<group>";
@@ -13919,6 +13927,7 @@
 			isa = PBXGroup;
 			children = (
 				1AF62EE314DA22A70041556C /* ScrollingCoordinatorMac.mm */,
+				1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -24088,6 +24097,7 @@
 				0720B0A114D3323500642955 /* GenericEventQueue.h in Headers */,
 				2CF6878A14D32EFF00340F39 /* ElementAttributeData.h in Headers */,
 				1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */,
+				1AF62F2614DAFEA10041556C /* ScrollingThread.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -27014,6 +27024,8 @@
 				2CF6878814D32EB500340F39 /* ElementAttributeData.cpp in Sources */,
 				1AF62EE614DA22A70041556C /* ScrollingCoordinatorMac.mm in Sources */,
 				1AF62EE714DA22A70041556C /* ScrollingCoordinator.cpp in Sources */,
+				1AF62F2414DAFE910041556C /* ScrollingThreadMac.mm in Sources */,
+				1AF62F2514DAFE9E0041556C /* ScrollingThread.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp (106564 => 106565)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp	2012-02-02 17:39:43 UTC (rev 106564)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp	2012-02-02 17:44:16 UTC (rev 106565)
@@ -35,6 +35,7 @@
 #include "Page.h"
 #include "PlatformWheelEvent.h"
 #include "ScrollAnimator.h"
+#include "ScrollingThread.h"
 #include <wtf/Functional.h>
 #include <wtf/MainThread.h>
 #include <wtf/PassRefPtr.h>
@@ -113,7 +114,7 @@
         deltaY = 0;
 
     IntSize scrollOffset = IntSize(-deltaX, -deltaY);
-    dispatchOnScrollingThread(bind(&ScrollingCoordinator::scrollByOnScrollingThread, this, scrollOffset));
+    ScrollingThread::dispatch(bind(&ScrollingCoordinator::scrollByOnScrollingThread, this, scrollOffset));
     return true;
 }
 

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h (106564 => 106565)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2012-02-02 17:39:43 UTC (rev 106564)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2012-02-02 17:44:16 UTC (rev 106565)
@@ -85,11 +85,6 @@
 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()>&);
-
     // The following functions can only be called from the main thread.
     void didUpdateMainFrameScrollPosition();
 

Added: trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp (0 => 106565)


--- trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/ScrollingThread.cpp	2012-02-02 17:44:16 UTC (rev 106565)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2012 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"
+#include "ScrollingThread.h"
+
+#if ENABLE(THREADED_SCROLLING)
+
+namespace WebCore {
+
+ScrollingThread::ScrollingThread()
+    : m_threadIdentifier(0)
+{
+}
+
+bool ScrollingThread::isCurrentThread()
+{
+    if (!shared().m_threadIdentifier)
+        return false;
+
+    return currentThread() == shared().m_threadIdentifier;
+}
+
+void ScrollingThread::dispatch(const Function<void()>& function)
+{
+    shared().createThreadIfNeeded();
+
+    {
+        MutexLocker locker(shared().m_functionsMutex);
+        shared().m_functions.append(function);
+    }
+
+    shared().wakeUpRunLoop();
+}
+
+ScrollingThread& ScrollingThread::shared()
+{
+    DEFINE_STATIC_LOCAL(ScrollingThread, scrollingThread, ());
+    return scrollingThread;
+}
+
+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());
+
+    initializeRunLoop();
+}
+
+void ScrollingThread::dispatchFunctionsFromScrollingThread()
+{
+    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]();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_SCROLLING)

Added: trunk/Source/WebCore/page/scrolling/ScrollingThread.h (0 => 106565)


--- trunk/Source/WebCore/page/scrolling/ScrollingThread.h	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/ScrollingThread.h	2012-02-02 17:44:16 UTC (rev 106565)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+#ifndef ScrollingThread_h
+#define ScrollingThread_h
+
+#if ENABLE(THREADED_SCROLLING)
+
+#include <wtf/Functional.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Threading.h>
+#include <wtf/Vector.h>
+
+#if PLATFORM(MAC)
+#include <wtf/RetainPtr.h>
+#endif
+
+namespace WebCore {
+
+class ScrollingThread {
+    WTF_MAKE_NONCOPYABLE(ScrollingThread);
+
+public:
+    static bool isCurrentThread();
+    static void dispatch(const Function<void()>&);
+
+private:
+    ScrollingThread();
+
+    static ScrollingThread& shared();
+
+    void createThreadIfNeeded();
+    static void* threadCallback(void* scrollingThread);
+    void threadBody();
+    void dispatchFunctionsFromScrollingThread();
+
+    void initializeRunLoop();
+    void wakeUpRunLoop();
+
+#if PLATFORM(MAC)
+    static void threadRunLoopSourceCallback(void* scrollingThread);
+    void threadRunLoopSourceCallback();
+#endif
+
+    ThreadIdentifier m_threadIdentifier;
+
+    ThreadCondition m_initializeRunLoopCondition;
+    Mutex m_initializeRunLoopConditionMutex;
+
+    Mutex m_functionsMutex;
+    Vector<Function<void()> > m_functions;
+
+#if PLATFORM(MAC)
+    // FIXME: We should use WebCore::RunLoop here.
+    RetainPtr<CFRunLoopRef> m_threadRunLoop;
+    RetainPtr<CFRunLoopSourceRef> m_threadRunLoopSource;
+#endif
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_SCROLLING)
+
+#endif // ScrollingThread_h

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm (106564 => 106565)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2012-02-02 17:39:43 UTC (rev 106564)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm	2012-02-02 17:44:16 UTC (rev 106565)
@@ -31,6 +31,7 @@
 
 #import "FrameView.h"
 #import "Page.h"
+#import "ScrollingThread.h"
 #import <QuartzCore/QuartzCore.h>
 #import <wtf/Functional.h>
 #import <wtf/MainThread.h>
@@ -40,127 +41,6 @@
 
 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;
-}
-
 void ScrollingCoordinator::frameViewHorizontalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer*)
 {
     ASSERT(isMainThread());
@@ -197,19 +77,9 @@
     // FIXME: Inform the scrolling thread?
 }
 
-bool ScrollingCoordinator::isScrollingThread()
-{
-    return scrollingThread().isCurrentThread();
-}
-
-void ScrollingCoordinator::dispatchOnScrollingThread(const Function<void()>& function)
-{
-    return scrollingThread().dispatch(function);
-}
-
 void ScrollingCoordinator::scrollByOnScrollingThread(const IntSize& offset)
 {
-    ASSERT(isScrollingThread());
+    ASSERT(ScrollingThread::isCurrentThread());
 
     MutexLocker locker(m_mainFrameGeometryMutex);
 
@@ -234,7 +104,7 @@
 
 void ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread(const FloatPoint& scrollLayerPosition)
 {
-    ASSERT(isScrollingThread());
+    ASSERT(ScrollingThread::isCurrentThread());
     ASSERT(!m_mainFrameGeometryMutex.tryLock());
 
     [CATransaction begin];

Added: trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm (0 => 106565)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingThreadMac.mm	2012-02-02 17:44:16 UTC (rev 106565)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 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"
+#include "ScrollingThread.h"
+
+#if ENABLE(THREADED_SCROLLING)
+
+namespace WebCore {
+
+void ScrollingThread::initializeRunLoop()
+{
+    // 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::wakeUpRunLoop()
+{
+    CFRunLoopSourceSignal(m_threadRunLoopSource.get());
+    CFRunLoopWakeUp(m_threadRunLoop.get());
+}
+
+void ScrollingThread::threadRunLoopSourceCallback(void* scrollingThread)
+{
+    static_cast<ScrollingThread*>(scrollingThread)->threadRunLoopSourceCallback();
+}
+
+void ScrollingThread::threadRunLoopSourceCallback()
+{
+    dispatchFunctionsFromScrollingThread();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(THREADED_SCROLLING)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to