diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-03 09:55:33 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-03 09:55:33 +0100 |
commit | cd44dc59cdfc39534aef4d417e9f3c412e3be139 (patch) | |
tree | 8d89889ba95ed6ec9322e733846cc9cce9d7dff1 /Source/WebKit2/Platform | |
parent | d11f84f5b5cdc0d92a08af01b13472fdd5f9acb9 (diff) | |
download | qtwebkit-cd44dc59cdfc39534aef4d417e9f3c412e3be139.tar.gz |
Imported WebKit commit fce473cb4d55aa9fe9d0b0322a2fffecb731b961 (http://svn.webkit.org/repository/webkit/trunk@106560)
Diffstat (limited to 'Source/WebKit2/Platform')
-rw-r--r-- | Source/WebKit2/Platform/CoreIPC/Connection.cpp | 3 | ||||
-rw-r--r-- | Source/WebKit2/Platform/CoreIPC/Connection.h | 10 | ||||
-rw-r--r-- | Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp | 3 | ||||
-rw-r--r-- | Source/WebKit2/Platform/RunLoop.cpp | 70 | ||||
-rw-r--r-- | Source/WebKit2/Platform/RunLoop.h | 161 | ||||
-rw-r--r-- | Source/WebKit2/Platform/SharedMemory.h | 2 | ||||
-rw-r--r-- | Source/WebKit2/Platform/gtk/RunLoopGtk.cpp | 134 | ||||
-rw-r--r-- | Source/WebKit2/Platform/mac/RunLoopMac.mm | 153 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/RunLoopQt.cpp | 163 | ||||
-rw-r--r-- | Source/WebKit2/Platform/win/RunLoopWin.cpp | 179 |
10 files changed, 11 insertions, 867 deletions
diff --git a/Source/WebKit2/Platform/CoreIPC/Connection.cpp b/Source/WebKit2/Platform/CoreIPC/Connection.cpp index 3e17bbd23..3c2f14ced 100644 --- a/Source/WebKit2/Platform/CoreIPC/Connection.cpp +++ b/Source/WebKit2/Platform/CoreIPC/Connection.cpp @@ -28,10 +28,11 @@ #include "BinarySemaphore.h" #include "CoreIPCMessageKinds.h" -#include "RunLoop.h" +#include <WebCore/RunLoop.h> #include <wtf/CurrentTime.h> using namespace std; +using namespace WebCore; namespace CoreIPC { diff --git a/Source/WebKit2/Platform/CoreIPC/Connection.h b/Source/WebKit2/Platform/CoreIPC/Connection.h index bafa99918..81553aeb7 100644 --- a/Source/WebKit2/Platform/CoreIPC/Connection.h +++ b/Source/WebKit2/Platform/CoreIPC/Connection.h @@ -50,7 +50,9 @@ class QSocketNotifier; #include "PlatformProcessIdentifier.h" #endif +namespace WebCore { class RunLoop; +} namespace CoreIPC { @@ -118,8 +120,8 @@ public: typedef int Identifier; #endif - static PassRefPtr<Connection> createServerConnection(Identifier, Client*, RunLoop* clientRunLoop); - static PassRefPtr<Connection> createClientConnection(Identifier, Client*, RunLoop* clientRunLoop); + static PassRefPtr<Connection> createServerConnection(Identifier, Client*, WebCore::RunLoop* clientRunLoop); + static PassRefPtr<Connection> createClientConnection(Identifier, Client*, WebCore::RunLoop* clientRunLoop); ~Connection(); #if OS(DARWIN) @@ -207,7 +209,7 @@ public: typedef Message<ArgumentEncoder> OutgoingMessage; private: - Connection(Identifier, bool isServer, Client*, RunLoop* clientRunLoop); + Connection(Identifier, bool isServer, Client*, WebCore::RunLoop* clientRunLoop); void platformInitialize(Identifier); void platformInvalidate(); @@ -253,7 +255,7 @@ private: bool m_isConnected; WorkQueue m_connectionQueue; - RunLoop* m_clientRunLoop; + WebCore::RunLoop* m_clientRunLoop; Vector<QueueClient*> m_connectionQueueClients; diff --git a/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp b/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp index 97975abea..1119a2847 100644 --- a/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp +++ b/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp @@ -29,11 +29,12 @@ #include "CoreIPCMessageKinds.h" #include "MachPort.h" #include "MachUtilities.h" -#include "RunLoop.h" +#include <WebCore/RunLoop.h> #include <mach/mach_error.h> #include <mach/vm_map.h> using namespace std; +using namespace WebCore; namespace CoreIPC { diff --git a/Source/WebKit2/Platform/RunLoop.cpp b/Source/WebKit2/Platform/RunLoop.cpp deleted file mode 100644 index e495ecc58..000000000 --- a/Source/WebKit2/Platform/RunLoop.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2010 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 "RunLoop.h" - -#include <wtf/StdLibExtras.h> - -static RunLoop* s_mainRunLoop; - -void RunLoop::initializeMainRunLoop() -{ - if (s_mainRunLoop) - return; - s_mainRunLoop = RunLoop::current(); -} - -RunLoop* RunLoop::current() -{ - DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ()); - return &*runLoopData; -} - -RunLoop* RunLoop::main() -{ - ASSERT(s_mainRunLoop); - return s_mainRunLoop; -} - -void RunLoop::performWork() -{ - Vector<Function<void()> > functionQueue; - { - MutexLocker locker(m_functionQueueLock); - m_functionQueue.swap(functionQueue); - } - - for (size_t i = 0; i < functionQueue.size(); ++i) - functionQueue[i](); -} - -void RunLoop::dispatch(const Function<void()>& function) -{ - MutexLocker locker(m_functionQueueLock); - m_functionQueue.append(function); - - wakeUp(); -} diff --git a/Source/WebKit2/Platform/RunLoop.h b/Source/WebKit2/Platform/RunLoop.h deleted file mode 100644 index 57a79a8f3..000000000 --- a/Source/WebKit2/Platform/RunLoop.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * Portions Copyright (c) 2010 Motorola Mobility, 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 RunLoop_h -#define RunLoop_h - -#include <wtf/Forward.h> -#include <wtf/Functional.h> -#include <wtf/HashMap.h> -#include <wtf/PassOwnPtr.h> -#include <wtf/ThreadSpecific.h> -#include <wtf/Threading.h> -#include <wtf/Vector.h> -#if PLATFORM(GTK) -#include <wtf/gobject/GRefPtr.h> -typedef struct _GSource GSource; -typedef struct _GMainLoop GMainLoop; -typedef struct _GMainContext GMainContext; -typedef int gboolean; -#endif - -class RunLoop { -public: - // Must be called from the main thread. - static void initializeMainRunLoop(); - - static RunLoop* current(); - static RunLoop* main(); - - void dispatch(const Function<void()>&); - - static void run(); - void stop(); - -#if PLATFORM(MAC) - void runForDuration(double duration); -#endif - - class TimerBase { - friend class RunLoop; - public: - TimerBase(RunLoop*); - virtual ~TimerBase(); - - void startRepeating(double repeatInterval) { start(repeatInterval, true); } - void startOneShot(double interval) { start(interval, false); } - - void stop(); - bool isActive() const; - - virtual void fired() = 0; - - private: - void start(double nextFireInterval, bool repeat); - - RunLoop* m_runLoop; - -#if PLATFORM(WIN) - static void timerFired(RunLoop*, uint64_t ID); - uint64_t m_ID; - bool m_isRepeating; -#elif PLATFORM(MAC) - static void timerFired(CFRunLoopTimerRef, void*); - CFRunLoopTimerRef m_timer; -#elif PLATFORM(QT) - static void timerFired(RunLoop*, int ID); - int m_ID; - bool m_isRepeating; -#elif PLATFORM(GTK) - static gboolean timerFiredCallback(RunLoop::TimerBase*); - gboolean isRepeating() const { return m_isRepeating; } - void clearTimerSource(); - GRefPtr<GSource> m_timerSource; - gboolean m_isRepeating; -#endif - }; - - template <typename TimerFiredClass> - class Timer : public TimerBase { - public: - typedef void (TimerFiredClass::*TimerFiredFunction)(); - - Timer(RunLoop* runLoop, TimerFiredClass* o, TimerFiredFunction f) - : TimerBase(runLoop) - , m_object(o) - , m_function(f) - { - } - - private: - virtual void fired() { (m_object->*m_function)(); } - - TimerFiredClass* m_object; - TimerFiredFunction m_function; - }; - -private: - friend class WTF::ThreadSpecific<RunLoop>; - - RunLoop(); - ~RunLoop(); - - void performWork(); - void wakeUp(); - - Mutex m_functionQueueLock; - Vector<Function<void()> > m_functionQueue; - -#if PLATFORM(WIN) - static bool registerRunLoopMessageWindowClass(); - static LRESULT CALLBACK RunLoopWndProc(HWND, UINT, WPARAM, LPARAM); - LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - HWND m_runLoopMessageWindow; - - typedef HashMap<uint64_t, TimerBase*> TimerMap; - TimerMap m_activeTimers; -#elif PLATFORM(MAC) - static void performWork(void*); - CFRunLoopRef m_runLoop; - CFRunLoopSourceRef m_runLoopSource; - int m_nestingLevel; -#elif PLATFORM(QT) - typedef HashMap<int, TimerBase*> TimerMap; - TimerMap m_activeTimers; - class TimerObject; - TimerObject* m_timerObject; -#elif PLATFORM(GTK) -public: - static gboolean queueWork(RunLoop*); - GMainLoop* mainLoop(); -private: - GMainContext* m_runLoopContext; - GMainLoop* m_runLoopMain; -#endif -}; - -#endif // RunLoop_h diff --git a/Source/WebKit2/Platform/SharedMemory.h b/Source/WebKit2/Platform/SharedMemory.h index 23ec58ce7..a6f832851 100644 --- a/Source/WebKit2/Platform/SharedMemory.h +++ b/Source/WebKit2/Platform/SharedMemory.h @@ -30,7 +30,7 @@ #include <wtf/PassRefPtr.h> #include <wtf/RefCounted.h> -#if PLATFORM(QT) || PLATFORM(GTK) +#if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL) #include "Attachment.h" #include <wtf/text/WTFString.h> #endif diff --git a/Source/WebKit2/Platform/gtk/RunLoopGtk.cpp b/Source/WebKit2/Platform/gtk/RunLoopGtk.cpp deleted file mode 100644 index 81cbeaaf1..000000000 --- a/Source/WebKit2/Platform/gtk/RunLoopGtk.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * Portions Copyright (c) 2010 Motorola Mobility, 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 "RunLoop.h" - -#include "WKBase.h" -#include <glib.h> - -RunLoop::RunLoop() -{ - m_runLoopContext = g_main_context_default(); - ASSERT(m_runLoopContext); - m_runLoopMain = g_main_loop_new(m_runLoopContext, FALSE); - ASSERT(m_runLoopMain); -} - -RunLoop::~RunLoop() -{ - if (m_runLoopMain) { - if (g_main_loop_is_running(m_runLoopMain)) - g_main_loop_quit(m_runLoopMain); - g_main_loop_unref(m_runLoopMain); - } - - if (m_runLoopContext) - g_main_context_unref(m_runLoopContext); -} - -void RunLoop::run() -{ - g_main_loop_run(RunLoop::main()->mainLoop()); -} - -GMainLoop* RunLoop::mainLoop() -{ - return m_runLoopMain; -} - -void RunLoop::stop() -{ - g_main_loop_quit(m_runLoopMain); -} - -gboolean RunLoop::queueWork(RunLoop* runLoop) -{ - runLoop->performWork(); - return FALSE; -} - -void RunLoop::wakeUp() -{ - GRefPtr<GSource> source = adoptGRef(g_idle_source_new()); - g_source_set_priority(source.get(), G_PRIORITY_DEFAULT); - g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0); - g_source_attach(source.get(), m_runLoopContext); - - g_main_context_wakeup(m_runLoopContext); -} - -RunLoop::TimerBase::TimerBase(RunLoop* runLoop) - : m_runLoop(runLoop) - , m_timerSource(0) -{ -} - -RunLoop::TimerBase::~TimerBase() -{ - stop(); -} - -void RunLoop::TimerBase::clearTimerSource() -{ - m_timerSource = 0; -} - -gboolean RunLoop::TimerBase::timerFiredCallback(RunLoop::TimerBase* timer) -{ - GSource* currentTimerSource = timer->m_timerSource.get(); - bool isRepeating = timer->isRepeating(); - // This can change the timerSource by starting a new timer within the callback. - timer->fired(); - if (!isRepeating && currentTimerSource == timer->m_timerSource.get()) - timer->clearTimerSource(); - return isRepeating; -} - -void RunLoop::TimerBase::start(double fireInterval, bool repeat) -{ - if (m_timerSource) - stop(); - - m_timerSource = adoptGRef(g_timeout_source_new(static_cast<guint>(fireInterval * 1000))); - m_isRepeating = repeat; - g_source_set_callback(m_timerSource.get(), reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::timerFiredCallback), this, 0); - g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext); -} - -void RunLoop::TimerBase::stop() -{ - if (!m_timerSource) - return; - - g_source_destroy(m_timerSource.get()); - clearTimerSource(); -} - -bool RunLoop::TimerBase::isActive() const -{ - return m_timerSource; -} diff --git a/Source/WebKit2/Platform/mac/RunLoopMac.mm b/Source/WebKit2/Platform/mac/RunLoopMac.mm deleted file mode 100644 index 03bb86e8d..000000000 --- a/Source/WebKit2/Platform/mac/RunLoopMac.mm +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2010 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. - */ - -#import "config.h" -#import "RunLoop.h" - -void RunLoop::performWork(void* context) -{ - // Wrap main thread in an Autorelease pool. Sending messages can call - // into objc code and accumulate memory. - if (current() == main()) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - static_cast<RunLoop*>(context)->performWork(); - [pool drain]; - } else - static_cast<RunLoop*>(context)->performWork(); -} - -RunLoop::RunLoop() - : m_runLoop(CFRunLoopGetCurrent()) - , m_nestingLevel(0) -{ - CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, performWork }; - m_runLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context); - CFRunLoopAddSource(m_runLoop, m_runLoopSource, kCFRunLoopCommonModes); -} - -RunLoop::~RunLoop() -{ - // FIXME: Tear down the work item queue here. - CFRunLoopSourceInvalidate(m_runLoopSource); - CFRelease(m_runLoopSource); -} - -void RunLoop::run() -{ - current()->m_nestingLevel++; - if (current() == main() && current()->m_nestingLevel == 1) { - // Use -[NSApplication run] for the main run loop. - [NSApp run]; - } else { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - CFRunLoopRun(); - [pool drain]; - } - current()->m_nestingLevel--; -} - -void RunLoop::runForDuration(double duration) -{ - CFRunLoopRunInMode(kCFRunLoopDefaultMode, duration, true); -} - -void RunLoop::stop() -{ - ASSERT(m_runLoop == CFRunLoopGetCurrent()); - - if (m_runLoop == main()->m_runLoop && m_nestingLevel == 1) { - [NSApp stop:nil]; - NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined - location:NSMakePoint(0, 0) - modifierFlags:0 - timestamp:0.0 - windowNumber:0 - context:nil - subtype: 0 - data1:0 - data2:0]; - [NSApp postEvent:event atStart:true]; - } else - CFRunLoopStop(m_runLoop); -} - -void RunLoop::wakeUp() -{ - CFRunLoopSourceSignal(m_runLoopSource); - CFRunLoopWakeUp(m_runLoop); -} - -// RunLoop::Timer - -void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef, void* context) -{ - TimerBase* timer = static_cast<TimerBase*>(context); - - // Wrap main thread in an Autorelease pool. The timer can call - // into objc code and accumulate memory outside of the main event loop. - if (current() == main()) { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - timer->fired(); - [pool drain]; - } else - timer->fired(); -} - -RunLoop::TimerBase::TimerBase(RunLoop* runLoop) - : m_runLoop(runLoop) - , m_timer(0) -{ -} - -RunLoop::TimerBase::~TimerBase() -{ - stop(); -} - -void RunLoop::TimerBase::start(double nextFireInterval, bool repeat) -{ - if (m_timer) - stop(); - - CFRunLoopTimerContext context = { 0, this, 0, 0, 0 }; - CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0; - m_timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context); - CFRunLoopAddTimer(m_runLoop->m_runLoop, m_timer, kCFRunLoopCommonModes); -} - -void RunLoop::TimerBase::stop() -{ - if (!m_timer) - return; - - CFRunLoopTimerInvalidate(m_timer); - CFRelease(m_timer); - m_timer = 0; -} - -bool RunLoop::TimerBase::isActive() const -{ - return m_timer && CFRunLoopTimerIsValid(m_timer); -} diff --git a/Source/WebKit2/Platform/qt/RunLoopQt.cpp b/Source/WebKit2/Platform/qt/RunLoopQt.cpp deleted file mode 100644 index 007a0a5b1..000000000 --- a/Source/WebKit2/Platform/qt/RunLoopQt.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * - * 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 "RunLoop.h" - -#include <QCoreApplication> -#include <QAbstractEventDispatcher> -#include <QObject> -#include <QMetaMethod> -#include <QMetaObject> -#include <QTimerEvent> - -class RunLoop::TimerObject : public QObject -{ - Q_OBJECT -public: - TimerObject(RunLoop* runLoop) : m_runLoop(runLoop) - { - int methodIndex = metaObject()->indexOfMethod("performWork()"); - m_method = metaObject()->method(methodIndex); - } - - Q_SLOT void performWork() { m_runLoop->performWork(); } - inline void wakeUp() { m_method.invoke(this, Qt::QueuedConnection); } - -protected: - virtual void timerEvent(QTimerEvent* event) - { - RunLoop::TimerBase::timerFired(m_runLoop, event->timerId()); - } - -private: - RunLoop* m_runLoop; - QMetaMethod m_method; -}; - -static QEventLoop* currentEventLoop; - -void RunLoop::run() -{ - static bool mainEventLoopIsRunning = false; - if (!mainEventLoopIsRunning) { - mainEventLoopIsRunning = true; - QCoreApplication::exec(); - mainEventLoopIsRunning = false; - } else { - QEventLoop eventLoop; - - QEventLoop* previousEventLoop = currentEventLoop; - currentEventLoop = &eventLoop; - - eventLoop.exec(); - - currentEventLoop = previousEventLoop; - } -} - -void RunLoop::stop() -{ - if (currentEventLoop) - currentEventLoop->exit(); - else - QCoreApplication::exit(); -} - -RunLoop::RunLoop() - : m_timerObject(new TimerObject(this)) -{ -} - -RunLoop::~RunLoop() -{ - delete m_timerObject; -} - -void RunLoop::wakeUp() -{ - m_timerObject->wakeUp(); -} - -// RunLoop::Timer - -void RunLoop::TimerBase::timerFired(RunLoop* runLoop, int ID) -{ - TimerMap::iterator it = runLoop->m_activeTimers.find(ID); - ASSERT(it != runLoop->m_activeTimers.end()); - TimerBase* timer = it->second; - - if (!timer->m_isRepeating) { - // Stop the timer (calling stop would need another hash table lookup). - runLoop->m_activeTimers.remove(it); - runLoop->m_timerObject->killTimer(timer->m_ID); - timer->m_ID = 0; - } - - timer->fired(); -} - -RunLoop::TimerBase::TimerBase(RunLoop* runLoop) - : m_runLoop(runLoop) - , m_ID(0) - , m_isRepeating(false) -{ -} - -RunLoop::TimerBase::~TimerBase() -{ - stop(); -} - -void RunLoop::TimerBase::start(double nextFireInterval, bool repeat) -{ - stop(); - int millis = static_cast<int>(nextFireInterval * 1000); - m_isRepeating = repeat; - m_ID = m_runLoop->m_timerObject->startTimer(millis); - ASSERT(m_ID); - m_runLoop->m_activeTimers.set(m_ID, this); -} - -void RunLoop::TimerBase::stop() -{ - if (!m_ID) - return; - TimerMap::iterator it = m_runLoop->m_activeTimers.find(m_ID); - if (it == m_runLoop->m_activeTimers.end()) - return; - - m_runLoop->m_activeTimers.remove(it); - m_runLoop->m_timerObject->killTimer(m_ID); - m_ID = 0; -} - -bool RunLoop::TimerBase::isActive() const -{ - return m_ID; -} - -#include "RunLoopQt.moc" diff --git a/Source/WebKit2/Platform/win/RunLoopWin.cpp b/Source/WebKit2/Platform/win/RunLoopWin.cpp deleted file mode 100644 index dfbcaee56..000000000 --- a/Source/WebKit2/Platform/win/RunLoopWin.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (C) 2010 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 "RunLoop.h" - -#include "BinarySemaphore.h" -#include <wtf/CurrentTime.h> - -using namespace CoreIPC; -using namespace std; - -static const UINT PerformWorkMessage = WM_USER + 1; -static const LPWSTR kRunLoopMessageWindowClassName = L"RunLoopMessageWindow"; - -LRESULT CALLBACK RunLoop::RunLoopWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - LONG_PTR longPtr = ::GetWindowLongPtr(hWnd, 0); - - if (RunLoop* runLoop = reinterpret_cast<RunLoop*>(longPtr)) - return runLoop->wndProc(hWnd, message, wParam, lParam); - - if (message == WM_CREATE) { - LPCREATESTRUCT createStruct = reinterpret_cast<LPCREATESTRUCT>(lParam); - - // Associate the RunLoop with the window. - ::SetWindowLongPtr(hWnd, 0, (LONG_PTR)createStruct->lpCreateParams); - return 0; - } - - return ::DefWindowProc(hWnd, message, wParam, lParam); -} - -LRESULT RunLoop::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case PerformWorkMessage: - performWork(); - return 0; - case WM_TIMER: - RunLoop::TimerBase::timerFired(this, wParam); - return 0; - } - - return ::DefWindowProc(hWnd, message, wParam, lParam); -} - -void RunLoop::run() -{ - MSG message; - while (BOOL result = ::GetMessage(&message, 0, 0, 0)) { - if (result == -1) - break; - ::TranslateMessage(&message); - ::DispatchMessage(&message); - } -} - -void RunLoop::stop() -{ - ::PostQuitMessage(0); -} - -bool RunLoop::registerRunLoopMessageWindowClass() -{ - // FIXME: This really only needs to be called once. - - WNDCLASSEX windowClass = { 0 }; - windowClass.cbSize = sizeof(windowClass); - windowClass.lpfnWndProc = RunLoop::RunLoopWndProc; - windowClass.cbWndExtra = sizeof(RunLoop*); - windowClass.lpszClassName = kRunLoopMessageWindowClassName; - - return !!::RegisterClassEx(&windowClass); -} - -RunLoop::RunLoop() -{ - registerRunLoopMessageWindowClass(); - - m_runLoopMessageWindow = ::CreateWindow(kRunLoopMessageWindowClassName, 0, 0, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, - HWND_MESSAGE, 0, 0, this); - ASSERT(::IsWindow(m_runLoopMessageWindow)); -} - -RunLoop::~RunLoop() -{ - // FIXME: Tear down the work item queue here. -} - -void RunLoop::wakeUp() -{ - // FIXME: No need to wake up the run loop if we've already called dispatch - // before the run loop has had the time to respond. - ::PostMessage(m_runLoopMessageWindow, PerformWorkMessage, reinterpret_cast<WPARAM>(this), 0); -} - -// RunLoop::Timer - -void RunLoop::TimerBase::timerFired(RunLoop* runLoop, uint64_t ID) -{ - TimerMap::iterator it = runLoop->m_activeTimers.find(ID); - if (it == runLoop->m_activeTimers.end()) { - // The timer must have been stopped after the WM_TIMER message was posted to the message queue. - return; - } - - TimerBase* timer = it->second; - - if (!timer->m_isRepeating) { - runLoop->m_activeTimers.remove(it); - ::KillTimer(runLoop->m_runLoopMessageWindow, ID); - } - - timer->fired(); -} - -static uint64_t generateTimerID() -{ - static uint64_t uniqueTimerID = 1; - return uniqueTimerID++; -} - -RunLoop::TimerBase::TimerBase(RunLoop* runLoop) - : m_runLoop(runLoop) - , m_ID(generateTimerID()) - , m_isRepeating(false) -{ -} - -RunLoop::TimerBase::~TimerBase() -{ - stop(); -} - -void RunLoop::TimerBase::start(double nextFireInterval, bool repeat) -{ - m_isRepeating = repeat; - m_runLoop->m_activeTimers.set(m_ID, this); - ::SetTimer(m_runLoop->m_runLoopMessageWindow, m_ID, nextFireInterval * 1000, 0); -} - -void RunLoop::TimerBase::stop() -{ - TimerMap::iterator it = m_runLoop->m_activeTimers.find(m_ID); - if (it == m_runLoop->m_activeTimers.end()) - return; - - m_runLoop->m_activeTimers.remove(it); - ::KillTimer(m_runLoop->m_runLoopMessageWindow, m_ID); -} - -bool RunLoop::TimerBase::isActive() const -{ - return m_runLoop->m_activeTimers.contains(m_ID); -} |