Changeset 106565 in webkit


Ignore:
Timestamp:
Feb 2, 2012 9:44:16 AM (12 years ago)
Author:
andersca@apple.com
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):

Location:
trunk/Source/WebCore
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106563 r106565  
     12012-02-02  Anders Carlsson  <andersca@apple.com>
     2
     3        Move ScrollingThread to its own file
     4        https://bugs.webkit.org/show_bug.cgi?id=77652
     5
     6        Reviewed by Sam Weinig.
     7
     8        This just shuffles some classes around and makes ScrollingCoordinator call into ScrollingThread.
     9        Hopefully we'll be able to make ScrollingThread use the new WebCore::RunLoop class eventually.
     10
     11        * WebCore.xcodeproj/project.pbxproj:
     12        * page/scrolling/ScrollingCoordinator.cpp:
     13        (WebCore::ScrollingCoordinator::handleWheelEvent):
     14        * page/scrolling/ScrollingCoordinator.h:
     15        (ScrollingCoordinator):
     16        * page/scrolling/ScrollingThread.cpp: Added.
     17        (WebCore):
     18        (WebCore::ScrollingThread::ScrollingThread):
     19        (WebCore::ScrollingThread::isCurrentThread):
     20        (WebCore::ScrollingThread::dispatch):
     21        (WebCore::ScrollingThread::shared):
     22        (WebCore::ScrollingThread::createThreadIfNeeded):
     23        (WebCore::ScrollingThread::threadCallback):
     24        (WebCore::ScrollingThread::threadBody):
     25        (WebCore::ScrollingThread::dispatchFunctionsFromScrollingThread):
     26        * page/scrolling/ScrollingThread.h: Added.
     27        (WebCore):
     28        (ScrollingThread):
     29        * page/scrolling/mac/ScrollingCoordinatorMac.mm:
     30        (WebCore::ScrollingCoordinator::scrollByOnScrollingThread):
     31        (WebCore::ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread):
     32        * page/scrolling/mac/ScrollingThreadMac.mm: Added.
     33        (WebCore):
     34        (WebCore::ScrollingThread::initializeRunLoop):
     35        (WebCore::ScrollingThread::wakeUpRunLoop):
     36        (WebCore::ScrollingThread::threadRunLoopSourceCallback):
     37
    1382012-02-02  Sheriff Bot  <webkit.review.bot@gmail.com>
    239
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r106523 r106565  
    588588                1AF62EE714DA22A70041556C /* ScrollingCoordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */; };
    589589                1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */; settings = {ATTRIBUTES = (Private, ); }; };
     590                1AF62F2414DAFE910041556C /* ScrollingThreadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */; };
     591                1AF62F2514DAFE9E0041556C /* ScrollingThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF62F2014DAFE790041556C /* ScrollingThread.cpp */; };
     592                1AF62F2614DAFEA10041556C /* ScrollingThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF62F2114DAFE790041556C /* ScrollingThread.h */; };
    590593                1AF8E11A1256592600230FF7 /* ProxyServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AF8E1191256592600230FF7 /* ProxyServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
    591594                1AF8E13312565A4400230FF7 /* ProxyServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AF8E13212565A4400230FF7 /* ProxyServer.cpp */; };
     
    73247327                1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingCoordinator.cpp; sourceTree = "<group>"; };
    73257328                1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingCoordinator.h; sourceTree = "<group>"; };
     7329                1AF62F2014DAFE790041556C /* ScrollingThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingThread.cpp; sourceTree = "<group>"; };
     7330                1AF62F2114DAFE790041556C /* ScrollingThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingThread.h; sourceTree = "<group>"; };
     7331                1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollingThreadMac.mm; sourceTree = "<group>"; };
    73267332                1AF8E1191256592600230FF7 /* ProxyServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyServer.h; sourceTree = "<group>"; };
    73277333                1AF8E13212565A4400230FF7 /* ProxyServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ProxyServer.cpp; sourceTree = "<group>"; };
     
    1391213918                                1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */,
    1391313919                                1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */,
     13920                                1AF62F2014DAFE790041556C /* ScrollingThread.cpp */,
     13921                                1AF62F2114DAFE790041556C /* ScrollingThread.h */,
    1391413922                        );
    1391513923                        path = scrolling;
     
    1392013928                        children = (
    1392113929                                1AF62EE314DA22A70041556C /* ScrollingCoordinatorMac.mm */,
     13930                                1AF62F2314DAFE910041556C /* ScrollingThreadMac.mm */,
    1392213931                        );
    1392313932                        path = mac;
     
    2408924098                                2CF6878A14D32EFF00340F39 /* ElementAttributeData.h in Headers */,
    2409024099                                1AF62EE814DA22A70041556C /* ScrollingCoordinator.h in Headers */,
     24100                                1AF62F2614DAFEA10041556C /* ScrollingThread.h in Headers */,
    2409124101                        );
    2409224102                        runOnlyForDeploymentPostprocessing = 0;
     
    2701527025                                1AF62EE614DA22A70041556C /* ScrollingCoordinatorMac.mm in Sources */,
    2701627026                                1AF62EE714DA22A70041556C /* ScrollingCoordinator.cpp in Sources */,
     27027                                1AF62F2414DAFE910041556C /* ScrollingThreadMac.mm in Sources */,
     27028                                1AF62F2514DAFE9E0041556C /* ScrollingThread.cpp in Sources */,
    2701727029                        );
    2701827030                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp

    r106523 r106565  
    3636#include "PlatformWheelEvent.h"
    3737#include "ScrollAnimator.h"
     38#include "ScrollingThread.h"
    3839#include <wtf/Functional.h>
    3940#include <wtf/MainThread.h>
     
    114115
    115116    IntSize scrollOffset = IntSize(-deltaX, -deltaY);
    116     dispatchOnScrollingThread(bind(&ScrollingCoordinator::scrollByOnScrollingThread, this, scrollOffset));
     117    ScrollingThread::dispatch(bind(&ScrollingCoordinator::scrollByOnScrollingThread, this, scrollOffset));
    117118    return true;
    118119}
  • trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h

    r106523 r106565  
    8686    explicit ScrollingCoordinator(Page*);
    8787
    88     // FIXME: Once we have a proper thread/run loop abstraction we should get rid of these
    89     // functions and just use something like scrollingRunLoop()->dispatch(function);
    90     static bool isScrollingThread();
    91     static void dispatchOnScrollingThread(const Function<void()>&);
    92 
    9388    // The following functions can only be called from the main thread.
    9489    void didUpdateMainFrameScrollPosition();
  • trunk/Source/WebCore/page/scrolling/mac/ScrollingCoordinatorMac.mm

    r106523 r106565  
    3232#import "FrameView.h"
    3333#import "Page.h"
     34#import "ScrollingThread.h"
    3435#import <QuartzCore/QuartzCore.h>
    3536#import <wtf/Functional.h>
     
    4041
    4142namespace WebCore {
    42 
    43 class ScrollingThread {
    44 public:
    45     ScrollingThread()
    46         : m_threadIdentifier(0)
    47     {
    48     }
    49 
    50     bool isCurrentThread() const;
    51     void dispatch(const Function<void()>&);
    52 
    53 private:
    54     void createThreadIfNeeded();
    55 
    56     static void* threadCallback(void* scrollingThread);
    57     void threadBody();
    58 
    59     static void threadRunLoopSourceCallback(void* scrollingThread);
    60     void threadRunLoopSourceCallback();
    61 
    62     ThreadIdentifier m_threadIdentifier;
    63 
    64     ThreadCondition m_initializeRunLoopCondition;
    65     Mutex m_initializeRunLoopConditionMutex;
    66    
    67     RetainPtr<CFRunLoopRef> m_threadRunLoop;
    68     RetainPtr<CFRunLoopSourceRef> m_threadRunLoopSource;
    69 
    70     Mutex m_functionsMutex;
    71     Vector<Function<void()> > m_functions;
    72 };
    73 
    74 bool ScrollingThread::isCurrentThread() const
    75 {
    76     if (!m_threadIdentifier)
    77         return false;
    78 
    79     return currentThread() == m_threadIdentifier;
    80 }
    81 
    82 void ScrollingThread::createThreadIfNeeded()
    83 {
    84     if (m_threadIdentifier)
    85         return;
    86 
    87     m_threadIdentifier = createThread(threadCallback, this, "WebCore: Scrolling");
    88 
    89     // Wait for the thread to initialize the run loop.
    90     {
    91         MutexLocker locker(m_initializeRunLoopConditionMutex);
    92 
    93         while (!m_threadRunLoop)
    94             m_initializeRunLoopCondition.wait(m_initializeRunLoopConditionMutex);
    95     }
    96 }
    97 
    98 void* ScrollingThread::threadCallback(void* scrollingThread)
    99 {
    100     static_cast<ScrollingThread*>(scrollingThread)->threadBody();
    101 
    102     return 0;
    103 }
    104 
    105 void ScrollingThread::threadBody()
    106 {
    107     ASSERT(isCurrentThread());
    108 
    109     // Initialize the run loop.
    110     {
    111         MutexLocker locker(m_initializeRunLoopConditionMutex);
    112 
    113         m_threadRunLoop = CFRunLoopGetCurrent();
    114 
    115         CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, threadRunLoopSourceCallback };
    116         m_threadRunLoopSource = adoptCF(CFRunLoopSourceCreate(0, 0, &context));
    117         CFRunLoopAddSource(CFRunLoopGetCurrent(), m_threadRunLoopSource.get(), kCFRunLoopDefaultMode);
    118 
    119         m_initializeRunLoopCondition.broadcast();
    120     }
    121 
    122     CFRunLoopRun();
    123 }
    124 
    125 void ScrollingThread::threadRunLoopSourceCallback(void* scrollingThread)
    126 {
    127     static_cast<ScrollingThread*>(scrollingThread)->threadRunLoopSourceCallback();
    128 }
    129 
    130 void ScrollingThread::threadRunLoopSourceCallback()
    131 {
    132     ASSERT(isCurrentThread());
    133 
    134     Vector<Function<void ()> > functions;
    135 
    136     {
    137         MutexLocker locker(m_functionsMutex);
    138         m_functions.swap(functions);
    139     }
    140 
    141     for (size_t i = 0; i < functions.size(); ++i)
    142         functions[i]();
    143 }
    144 
    145 void ScrollingThread::dispatch(const Function<void()>& function)
    146 {
    147     createThreadIfNeeded();
    148 
    149     {
    150         MutexLocker locker(m_functionsMutex);
    151         m_functions.append(function);
    152     }
    153 
    154     CFRunLoopSourceSignal(m_threadRunLoopSource.get());
    155     CFRunLoopWakeUp(m_threadRunLoop.get());
    156 }
    157 
    158 static ScrollingThread& scrollingThread()
    159 {
    160     DEFINE_STATIC_LOCAL(ScrollingThread, scrollingThread, ());
    161     return scrollingThread;
    162 }
    16343
    16444void ScrollingCoordinator::frameViewHorizontalScrollbarLayerDidChange(FrameView* frameView, GraphicsLayer*)
     
    19878}
    19979
    200 bool ScrollingCoordinator::isScrollingThread()
    201 {
    202     return scrollingThread().isCurrentThread();
    203 }
    204 
    205 void ScrollingCoordinator::dispatchOnScrollingThread(const Function<void()>& function)
    206 {
    207     return scrollingThread().dispatch(function);
    208 }
    209 
    21080void ScrollingCoordinator::scrollByOnScrollingThread(const IntSize& offset)
    21181{
    212     ASSERT(isScrollingThread());
     82    ASSERT(ScrollingThread::isCurrentThread());
    21383
    21484    MutexLocker locker(m_mainFrameGeometryMutex);
     
    235105void ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread(const FloatPoint& scrollLayerPosition)
    236106{
    237     ASSERT(isScrollingThread());
     107    ASSERT(ScrollingThread::isCurrentThread());
    238108    ASSERT(!m_mainFrameGeometryMutex.tryLock());
    239109
Note: See TracChangeset for help on using the changeset viewer.