Factor repeated CFRunLoopObserver code out
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 22:30:31 +0000 (22:30 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jun 2014 22:30:31 +0000 (22:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133690

Reviewed by Simon Fraser.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* platform/cf/RunLoopObserver.cpp: Added.
(WebCore::RunLoopObserver::create):
(WebCore::RunLoopObserver::~RunLoopObserver):
(WebCore::RunLoopObserver::runLoopObserverFired):
(WebCore::RunLoopObserver::schedule):
(WebCore::RunLoopObserver::invalidate):
* platform/cf/RunLoopObserver.h: Added.
(WebCore::RunLoopObserver::isScheduled):
(WebCore::RunLoopObserver::RunLoopObserver):
Factor CFRunLoopObserver management code out of LayerFlushScheduler and WebKit2.

* platform/graphics/ca/LayerFlushScheduler.h:
* platform/graphics/ca/mac/LayerFlushSchedulerMac.cpp:
(WebCore::LayerFlushScheduler::LayerFlushScheduler):
(WebCore::LayerFlushScheduler::~LayerFlushScheduler):
(WebCore::LayerFlushScheduler::layerFlushCallback):
(WebCore::LayerFlushScheduler::schedule):
(WebCore::LayerFlushScheduler::invalidate):
(WebCore::LayerFlushScheduler::runLoopObserverCallback): Deleted.
Make use of WebCore::RunLoopObserver.

* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
* UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
(WebKit::RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy):
(WebKit::RemoteLayerTreeDrawingAreaProxy::~RemoteLayerTreeDrawingAreaProxy):
(WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
(WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
(WebKit::coreAnimationDidCommitLayersCallback): Deleted.
(WebKit::RemoteLayerTreeDrawingAreaProxy::scheduleCoreAnimationLayerCommitObserver): Deleted.
(WebKit::RemoteLayerTreeDrawingAreaProxy::coreAnimationDidCommitLayers): Deleted.
Make use of WebCore::RunLoopObserver.

* WebView/WebViewData.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@169775 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/cf/RunLoopObserver.cpp [new file with mode: 0644]
Source/WebCore/platform/cf/RunLoopObserver.h [new file with mode: 0644]
Source/WebCore/platform/graphics/ca/LayerFlushScheduler.h
Source/WebCore/platform/graphics/ca/mac/LayerFlushSchedulerMac.cpp
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebViewData.h
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h
Source/WebKit2/UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm

index 0425be5b5b894a81a4edbaacf9c29d4f4380661e..e96ea8f8ad8867e17f15f08381f70f75c12fe682 100644 (file)
@@ -1,3 +1,33 @@
+2014-06-10  Timothy Horton  <timothy_horton@apple.com>
+
+        Factor repeated CFRunLoopObserver code out
+        https://bugs.webkit.org/show_bug.cgi?id=133690
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/cf/RunLoopObserver.cpp: Added.
+        (WebCore::RunLoopObserver::create):
+        (WebCore::RunLoopObserver::~RunLoopObserver):
+        (WebCore::RunLoopObserver::runLoopObserverFired):
+        (WebCore::RunLoopObserver::schedule):
+        (WebCore::RunLoopObserver::invalidate):
+        * platform/cf/RunLoopObserver.h: Added.
+        (WebCore::RunLoopObserver::isScheduled):
+        (WebCore::RunLoopObserver::RunLoopObserver):
+        Factor CFRunLoopObserver management code out of LayerFlushScheduler and WebKit2.
+
+        * platform/graphics/ca/LayerFlushScheduler.h:
+        * platform/graphics/ca/mac/LayerFlushSchedulerMac.cpp:
+        (WebCore::LayerFlushScheduler::LayerFlushScheduler):
+        (WebCore::LayerFlushScheduler::~LayerFlushScheduler):
+        (WebCore::LayerFlushScheduler::layerFlushCallback):
+        (WebCore::LayerFlushScheduler::schedule):
+        (WebCore::LayerFlushScheduler::invalidate):
+        (WebCore::LayerFlushScheduler::runLoopObserverCallback): Deleted.
+        Make use of WebCore::RunLoopObserver.
+
 2014-06-10  Simon Fraser  <simon.fraser@apple.com>
 
         Modernize loop code in scrolling tree code
index b222f92dd1ef72ca3ee8821e2f42fb32ff3205fe..fa802b3f06a499b5fdc21bdfffdb65627c297709 100644 (file)
@@ -606,6 +606,10 @@ __ZN7WebCore15ProtectionSpaceC1ERKN3WTF6StringEiNS_25ProtectionSpaceServerTypeES
 __ZN7WebCore15ProtectionSpaceC1Ev
 __ZN7WebCore15ResourceRequest21httpPipeliningEnabledEv
 __ZN7WebCore15ResourceRequest24setHTTPPipeliningEnabledEb
+__ZN7WebCore15RunLoopObserver10invalidateEv
+__ZN7WebCore15RunLoopObserver6createElNSt3__18functionIFvvEEE
+__ZN7WebCore15RunLoopObserver8scheduleEP11__CFRunLoop
+__ZN7WebCore15RunLoopObserverD1Ev
 __ZN7WebCore15SQLiteStatement12getColumnIntEi
 __ZN7WebCore15SQLiteStatement12isColumnNullEi
 __ZN7WebCore15SQLiteStatement13getColumnTextEi
@@ -794,7 +798,7 @@ __ZN7WebCore19AnimationController21pauseTransitionAtTimeEPNS_13RenderElementERKN
 __ZN7WebCore19AnimationController36setAllowsNewAnimationsWhileSuspendedEb
 __ZN7WebCore19HTMLTextAreaElement8setValueERKN3WTF6StringE
 __ZN7WebCore19LayerFlushScheduler10invalidateEv
-__ZN7WebCore19LayerFlushScheduler23runLoopObserverCallbackEv
+__ZN7WebCore19LayerFlushScheduler18layerFlushCallbackEv
 __ZN7WebCore19LayerFlushScheduler6resumeEv
 __ZN7WebCore19LayerFlushScheduler7suspendEv
 __ZN7WebCore19LayerFlushScheduler8scheduleEv
@@ -2187,6 +2191,7 @@ __ZN7WebCore36initializeLoggingChannelsIfNecessaryEv
 .objc_class_name_WebFontCache
 .objc_class_name_WebWindowFadeAnimation
 .objc_class_name_WebWindowScaleAnimation
+__ZN7WebCore10CredentialC1EP20OpaqueSecIdentityRefPK9__CFArrayNS_21CredentialPersistenceE
 __ZN7WebCore10FloatPointC1ERK8_NSPoint
 __ZN7WebCore10handCursorEv
 __ZN7WebCore11CachedImage5imageEv
@@ -2488,6 +2493,7 @@ _WebThreadUnlockGuardForMail
 _WebUIApplicationDidBecomeActiveNotification
 _WebUIApplicationWillEnterForegroundNotification
 _WebUIApplicationWillResignActiveNotification
+__ZN7WebCore10CredentialC1EP13__SecIdentityPK9__CFArrayNS_21CredentialPersistenceE
 __ZN7WebCore10RenderView35resumePausedImageAnimationsIfNeededEv
 __ZN7WebCore10ScrollView15setScrollOffsetERKNS_8IntPointE
 __ZN7WebCore10ScrollView21setExposedContentRectERKNS_7IntRectE
@@ -3419,9 +3425,3 @@ __ZN7WebCore4Page11setViewModeENS0_8ViewModeE
 #if ENABLE(WEB_TIMING)
 __ZNK7WebCore20ResourceResponseBase18resourceLoadTimingEv
 #endif
-
-#if PLATFORM(IOS)
-__ZN7WebCore10CredentialC1EP13__SecIdentityPK9__CFArrayNS_21CredentialPersistenceE
-#else
-__ZN7WebCore10CredentialC1EP20OpaqueSecIdentityRefPK9__CFArrayNS_21CredentialPersistenceE
-#endif
index 0b95a6f11de0ca660d2ed69879eec7f30c2374cd..3e540027529e5ebb39b496e8d7959411c7f3df09 100644 (file)
                2D6E468417D660F500ECF8BB /* PDFDocumentImageMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */; };
                2D70BA1318074DDF0001908A /* PlatformCALayerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D70BA1218074DDF0001908A /* PlatformCALayerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2D70BA1518074F860001908A /* PlatformCALayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D70BA1418074F850001908A /* PlatformCALayer.cpp */; };
+               2D76BB821945632400CFD29A /* RunLoopObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D76BB801945632400CFD29A /* RunLoopObserver.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               2D76BB8419456F8100CFD29A /* RunLoopObserver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */; };
                2D8287F616E4A0380086BD00 /* HitTestLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */; };
                2D8287F716E4A0380086BD00 /* HitTestLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D8287F516E4A0380086BD00 /* HitTestLocation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2D8FEBDC143E3EF70072502B /* CSSCrossfadeValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D8FEBDA143E3EF70072502B /* CSSCrossfadeValue.cpp */; };
                2D6E468217D660F500ECF8BB /* PDFDocumentImageMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PDFDocumentImageMac.mm; sourceTree = "<group>"; };
                2D70BA1218074DDF0001908A /* PlatformCALayerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCALayerMac.h; path = ca/mac/PlatformCALayerMac.h; sourceTree = "<group>"; };
                2D70BA1418074F850001908A /* PlatformCALayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformCALayer.cpp; path = ca/PlatformCALayer.cpp; sourceTree = "<group>"; };
+               2D76BB801945632400CFD29A /* RunLoopObserver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RunLoopObserver.h; sourceTree = "<group>"; };
+               2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopObserver.cpp; sourceTree = "<group>"; };
                2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestLocation.cpp; sourceTree = "<group>"; };
                2D8287F516E4A0380086BD00 /* HitTestLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HitTestLocation.h; sourceTree = "<group>"; };
                2D8FEBDA143E3EF70072502B /* CSSCrossfadeValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSCrossfadeValue.cpp; sourceTree = "<group>"; };
                                E1A8E56417552B2A007488E7 /* CFURLExtras.cpp */,
                                E1A8E56517552B2A007488E7 /* CFURLExtras.h */,
                                5160306B0CC4362300C8AC25 /* FileSystemCF.cpp */,
+                               2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */,
+                               2D76BB801945632400CFD29A /* RunLoopObserver.h */,
                                512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
                                1A98956A0AA78F80005EF5EF /* URLCF.cpp */,
                        );
                                A77E1FF014AACB6E005B7CB6 /* TreeScopeAdopter.h in Headers */,
                                1419D2C50CEA6F6100FF507A /* TreeShared.h in Headers */,
                                854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */,
+                               2D76BB821945632400CFD29A /* RunLoopObserver.h in Headers */,
                                C375D7FE16639519006184AB /* TypeAhead.h in Headers */,
                                37C28A6810F659CC008C7813 /* TypesettingFeatures.h in Headers */,
                                93309E1A099E64920056E581 /* TypingCommand.h in Headers */,
                                C6F0917F143A2BB900685849 /* JSMutationObserverCustom.cpp in Sources */,
                                C6F08FC91431000D00685849 /* JSMutationRecord.cpp in Sources */,
                                BCD9C2C00C17B69E005C90A2 /* JSNamedNodeMap.cpp in Sources */,
+                               2D76BB8419456F8100CFD29A /* RunLoopObserver.cpp in Sources */,
                                BCD9C2630C17AA67005C90A2 /* JSNamedNodeMapCustom.cpp in Sources */,
                                A9D247F70D757E3400FDF959 /* JSNavigator.cpp in Sources */,
                                073BE34017D17E01002BD431 /* JSNavigatorUserMedia.cpp in Sources */,
diff --git a/Source/WebCore/platform/cf/RunLoopObserver.cpp b/Source/WebCore/platform/cf/RunLoopObserver.cpp
new file mode 100644 (file)
index 0000000..e1ea4eb
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011, 2014 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. ``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
+ * 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 "RunLoopObserver.h"
+
+namespace WebCore {
+
+std::unique_ptr<RunLoopObserver> RunLoopObserver::create(CFIndex order, RunLoopObserver::RunLoopObserverCallback callback)
+{
+    return std::unique_ptr<RunLoopObserver>(new RunLoopObserver(order, callback));
+}
+
+RunLoopObserver::~RunLoopObserver()
+{
+    invalidate();
+}
+
+void RunLoopObserver::runLoopObserverFired(CFRunLoopObserverRef, CFRunLoopActivity, void* context)
+{
+    static_cast<RunLoopObserver*>(context)->runLoopObserverFired();
+}
+
+void RunLoopObserver::runLoopObserverFired()
+{
+    ASSERT(m_runLoopObserver);
+    m_callback();
+}
+
+void RunLoopObserver::schedule(CFRunLoopRef runLoop)
+{
+    if (!runLoop)
+        runLoop = CFRunLoopGetCurrent();
+
+    // Make sure we wake up the loop or the observer could be delayed until some other source fires.
+    CFRunLoopWakeUp(runLoop);
+
+    if (m_runLoopObserver)
+        return;
+
+    CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
+    m_runLoopObserver = adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, m_order, runLoopObserverFired, &context));
+
+    CFRunLoopAddObserver(runLoop, m_runLoopObserver.get(), kCFRunLoopCommonModes);
+}
+
+void RunLoopObserver::invalidate()
+{
+    if (m_runLoopObserver) {
+        CFRunLoopObserverInvalidate(m_runLoopObserver.get());
+        m_runLoopObserver = nullptr;   
+    }
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/cf/RunLoopObserver.h b/Source/WebCore/platform/cf/RunLoopObserver.h
new file mode 100644 (file)
index 0000000..fc883dd
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2011, 2014 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. ``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
+ * 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 RunLoopObserver_h
+#define RunLoopObserver_h
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <functional>
+#include <wtf/Noncopyable.h>
+#include <wtf/RetainPtr.h>
+
+namespace WebCore {
+
+class RunLoopObserver {
+    WTF_MAKE_NONCOPYABLE(RunLoopObserver);
+public:
+    typedef std::function<void ()> RunLoopObserverCallback;
+
+    static std::unique_ptr<RunLoopObserver> create(CFIndex order, RunLoopObserverCallback callback);
+
+    ~RunLoopObserver();
+
+    void schedule(CFRunLoopRef = nullptr);
+    void invalidate();
+
+    bool isScheduled() const { return m_runLoopObserver; }
+
+    enum class WellKnownRunLoopOrders : CFIndex {
+        CoreAnimationCommit = 2000000
+    };
+
+protected:
+    RunLoopObserver(CFIndex order, RunLoopObserverCallback callback)
+        : m_order(order)
+        , m_callback(callback)
+    { }
+
+    void runLoopObserverFired();
+
+private:
+    static void runLoopObserverFired(CFRunLoopObserverRef, CFRunLoopActivity, void* context);
+
+    CFIndex m_order;
+    RunLoopObserverCallback m_callback;
+    RetainPtr<CFRunLoopObserverRef> m_runLoopObserver;
+};
+
+} // namespace WebCore
+
+#endif // RunLoopObserver_h
index c3a4fa2e5b6121a1e95041feeccc88cf5de93cb2..72b6725e4705190add849cd81e576f9ac865679a 100644 (file)
@@ -27,8 +27,8 @@
 #define LayerFlushScheduler_h
 
 #include "LayerFlushSchedulerClient.h"
+#include "RunLoopObserver.h"
 #include <wtf/Noncopyable.h>
-#include <wtf/RetainPtr.h>
 
 namespace WebCore {
     
@@ -46,16 +46,16 @@ public:
 
     bool isSuspended() const { return m_isSuspended; }
 
+#if PLATFORM(COCOA)
+    virtual void layerFlushCallback();
+#endif
+
 private:
     bool m_isSuspended;
     LayerFlushSchedulerClient* m_client;
     
 #if PLATFORM(COCOA)
-    RetainPtr<CFRunLoopObserverRef> m_runLoopObserver;
-    static void runLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context);
-
-protected:
-    virtual void runLoopObserverCallback();
+    std::unique_ptr<RunLoopObserver> m_runLoopObserver;
 #endif
 };
 
index fb5fa6e4234ec24da2d52bce17929cfd09d62c16..04153652fed4a9da8465fbeb258de63af05a1b40 100644 (file)
@@ -37,8 +37,7 @@
 
 namespace WebCore {
 
-static const CFIndex CoreAnimationRunLoopOrder = 2000000;
-static const CFIndex LayerFlushRunLoopOrder = CoreAnimationRunLoopOrder - 1;
+static const CFIndex layerFlushRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit - 1;
 
 static CFRunLoopRef currentRunLoop()
 {
@@ -59,21 +58,20 @@ LayerFlushScheduler::LayerFlushScheduler(LayerFlushSchedulerClient* client)
     , m_client(client)
 {
     ASSERT_ARG(client, client);
-}
 
-LayerFlushScheduler::~LayerFlushScheduler()
-{
-    ASSERT(!m_runLoopObserver);
+    m_runLoopObserver = RunLoopObserver::create(layerFlushRunLoopOrder, [this]() {
+        if (this->isSuspended())
+            return;
+        this->layerFlushCallback();
+    });
 }
 
-void LayerFlushScheduler::runLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context)
+LayerFlushScheduler::~LayerFlushScheduler()
 {
-    static_cast<LayerFlushScheduler*>(context)->runLoopObserverCallback();
 }
 
-void LayerFlushScheduler::runLoopObserverCallback()
+void LayerFlushScheduler::layerFlushCallback()
 {
-    ASSERT(m_runLoopObserver);
     ASSERT(!m_isSuspended);
 
     AutodrainedPool pool;
@@ -86,26 +84,12 @@ void LayerFlushScheduler::schedule()
     if (m_isSuspended)
         return;
 
-    CFRunLoopRef runLoop = currentRunLoop();
-
-    // Make sure we wake up the loop or the observer could be delayed until some other source fires.
-    CFRunLoopWakeUp(runLoop);
-
-    if (m_runLoopObserver)
-        return;
-
-    CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
-    m_runLoopObserver = adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, LayerFlushRunLoopOrder, runLoopObserverCallback, &context));
-
-    CFRunLoopAddObserver(runLoop, m_runLoopObserver.get(), kCFRunLoopCommonModes);
+    m_runLoopObserver->schedule(currentRunLoop());
 }
 
 void LayerFlushScheduler::invalidate()
 {
-    if (m_runLoopObserver) {
-        CFRunLoopObserverInvalidate(m_runLoopObserver.get());
-        m_runLoopObserver = nullptr;   
-    }
+    m_runLoopObserver->invalidate();
 }
     
 } // namespace WebCore
index 200446635b683d861b392af722de0cb62caf0126..bcc056800968542becbe4bccc1ae921a61afa7a6 100644 (file)
@@ -1,3 +1,12 @@
+2014-06-10  Timothy Horton  <timothy_horton@apple.com>
+
+        Factor repeated CFRunLoopObserver code out
+        https://bugs.webkit.org/show_bug.cgi?id=133690
+
+        Reviewed by Simon Fraser.
+
+        * WebView/WebViewData.h:
+
 2014-06-05  Pratik Solanki  <psolanki@apple.com>
 
         Remove unsused method _setAcceleratedImageDecoding
index d58dd839e6ec7469a20495e55978839ecac793b9..a0be681fa2c1cc8c9bc9d1aa77482aa61ef97512 100644 (file)
@@ -89,10 +89,10 @@ public:
     virtual ~WebViewLayerFlushScheduler() { }
 
 private:
-    virtual void runLoopObserverCallback() override
+    virtual void layerFlushCallback() override
     {
         RefPtr<LayerFlushController> protector = m_flushController;
-        WebCore::LayerFlushScheduler::runLoopObserverCallback();
+        WebCore::LayerFlushScheduler::layerFlushCallback();
     }
     
     LayerFlushController* m_flushController;
index f7658e29ca7db129f2f28cd39ea0bdc9e70d03cb..424db02252e393405636c6062d8d531cea8ed6f6 100644 (file)
@@ -1,3 +1,21 @@
+2014-06-10  Timothy Horton  <timothy_horton@apple.com>
+
+        Factor repeated CFRunLoopObserver code out
+        https://bugs.webkit.org/show_bug.cgi?id=133690
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.h:
+        * UIProcess/mac/RemoteLayerTreeDrawingAreaProxy.mm:
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::~RemoteLayerTreeDrawingAreaProxy):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::commitLayerTree):
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::showDebugIndicator):
+        (WebKit::coreAnimationDidCommitLayersCallback): Deleted.
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::scheduleCoreAnimationLayerCommitObserver): Deleted.
+        (WebKit::RemoteLayerTreeDrawingAreaProxy::coreAnimationDidCommitLayers): Deleted.
+        Make use of WebCore::RunLoopObserver.
+
 2014-06-10  Anders Carlsson  <andersca@apple.com>
 
         Fix availability declaration.
index e87b9e99a994a2be8d5bc3d0448a7c0339e64cd4..a81bf301db21c15e6d53510c602f2dfb0a6e435d 100644 (file)
@@ -31,6 +31,7 @@
 #include <WebCore/FloatPoint.h>
 #include <WebCore/IntPoint.h>
 #include <WebCore/IntSize.h>
+#include <WebCore/RunLoopObserver.h>
 
 namespace WebKit {
 
@@ -75,8 +76,6 @@ private:
     
     void sendUpdateGeometry();
 
-    void scheduleCoreAnimationLayerCommitObserver();
-
     RemoteLayerTreeHost m_remoteLayerTreeHost;
     bool m_isWaitingForDidUpdateGeometry;
 
@@ -87,7 +86,7 @@ private:
     RetainPtr<CALayer> m_tileMapHostLayer;
     RetainPtr<CALayer> m_exposedRectIndicatorLayer;
 
-    RetainPtr<CFRunLoopObserverRef> m_layerCommitObserver;
+    std::unique_ptr<WebCore::RunLoopObserver> m_layerCommitObserver;
 };
 
 DRAWING_AREA_PROXY_TYPE_CASTS(RemoteLayerTreeDrawingAreaProxy, type() == DrawingAreaTypeRemoteLayerTree);
index 89b200dd9c04900014fbb7b40ff6114c960aa0b7..2cc7fe92c8fe7111c9a42651950a4442bdb72608 100644 (file)
 #import <WebCore/IOSurfacePool.h>
 #import <WebCore/WebActionDisablingCALayerDelegate.h>
 
-static const CFIndex CoreAnimationCommitRunLoopOrder = 2000000;
-static const CFIndex DidCommitLayersRunLoopOrder = CoreAnimationCommitRunLoopOrder + 1;
-
 using namespace WebCore;
 
+static const CFIndex didCommitLayersRunLoopOrder = (CFIndex)RunLoopObserver::WellKnownRunLoopOrders::CoreAnimationCommit + 1;
+
 namespace WebKit {
 
 RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy(WebPageProxy* webPageProxy)
@@ -56,16 +55,15 @@ RemoteLayerTreeDrawingAreaProxy::RemoteLayerTreeDrawingAreaProxy(WebPageProxy* w
 #endif
 
     m_webPageProxy->process().addMessageReceiver(Messages::RemoteLayerTreeDrawingAreaProxy::messageReceiverName(), m_webPageProxy->pageID(), *this);
+
+    m_layerCommitObserver = RunLoopObserver::create(didCommitLayersRunLoopOrder, [this]() {
+        this->coreAnimationDidCommitLayers();
+    });
 }
 
 RemoteLayerTreeDrawingAreaProxy::~RemoteLayerTreeDrawingAreaProxy()
 {
     m_webPageProxy->process().removeMessageReceiver(Messages::RemoteLayerTreeDrawingAreaProxy::messageReceiverName(), m_webPageProxy->pageID());
-
-    if (m_layerCommitObserver) {
-        CFRunLoopObserverInvalidate(m_layerCommitObserver.get());
-        m_layerCommitObserver = nullptr;
-    }
 }
 
 void RemoteLayerTreeDrawingAreaProxy::sizeDidChange()
@@ -150,7 +148,7 @@ void RemoteLayerTreeDrawingAreaProxy::commitLayerTree(const RemoteLayerTreeTrans
         asLayer(m_debugIndicatorLayerTreeHost->rootLayer()).name = @"Indicator host root";
     }
 
-    scheduleCoreAnimationLayerCommitObserver();
+    m_layerCommitObserver->schedule();
 }
 
 void RemoteLayerTreeDrawingAreaProxy::acceleratedAnimationDidStart(uint64_t layerID, const String& key, double startTime)
@@ -296,33 +294,9 @@ void RemoteLayerTreeDrawingAreaProxy::showDebugIndicator(bool show)
     }
 }
 
-static void coreAnimationDidCommitLayersCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context)
-{
-    static_cast<RemoteLayerTreeDrawingAreaProxy*>(context)->coreAnimationDidCommitLayers();
-}
-
-void RemoteLayerTreeDrawingAreaProxy::scheduleCoreAnimationLayerCommitObserver()
-{
-    if (m_layerCommitObserver)
-        return;
-
-    CFRunLoopRef runLoop = CFRunLoopGetCurrent();
-
-    // Make sure we wake up the loop or the observer could be delayed until some other source fires.
-    CFRunLoopWakeUp(runLoop);
-
-    CFRunLoopObserverContext context = { 0, this, 0, 0, 0 };
-    m_layerCommitObserver = adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, DidCommitLayersRunLoopOrder, coreAnimationDidCommitLayersCallback, &context));
-
-    CFRunLoopAddObserver(runLoop, m_layerCommitObserver.get(), kCFRunLoopCommonModes);
-}
-
 void RemoteLayerTreeDrawingAreaProxy::coreAnimationDidCommitLayers()
 {
-    if (m_layerCommitObserver) {
-        CFRunLoopObserverInvalidate(m_layerCommitObserver.get());
-        m_layerCommitObserver = nullptr;
-    }
+    m_layerCommitObserver->invalidate();
 
     if (!m_webPageProxy->isValid())
         return;