Title: [266587] releases/WebKitGTK/webkit-2.30/Source
Revision
266587
Author
[email protected]
Date
2020-09-04 04:15:58 -0700 (Fri, 04 Sep 2020)

Log Message

Merge r266103 - [GTK] Implement rendering frames timeline panel for GTK+ port
https://bugs.webkit.org/show_bug.cgi?id=150392
<rdar://problem/23200510>

Reviewed by Brian Burg.

Source/WebCore:

Use new RunLoop API to observe the run loop events when the GLib event loop is used.

* inspector/agents/InspectorTimelineAgent.cpp:
(WebCore::InspectorTimelineAgent::internalStart):
(WebCore::InspectorTimelineAgent::internalStop):
* inspector/agents/InspectorTimelineAgent.h:

Source/WTF:

Add API to observe RunLoop events for GLib event loop implementation.

* wtf/RunLoop.h:
* wtf/glib/RunLoopGLib.cpp:
(WTF::RunLoop::RunLoop): Use RunLoopSource struct and initialize the RunLoop.
(WTF::RunLoop::observe): Add the given observer to the set.
(WTF::RunLoop::notify): Notife observers of the given event.
(WTF::RunLoop::TimerBase::TimerBase): Use RunLoopSource struct and initialize the RunLoop.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/ChangeLog	2020-09-04 11:15:58 UTC (rev 266587)
@@ -1,3 +1,20 @@
+2020-08-24  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Implement rendering frames timeline panel for GTK+ port
+        https://bugs.webkit.org/show_bug.cgi?id=150392
+        <rdar://problem/23200510>
+
+        Reviewed by Brian Burg.
+
+        Add API to observe RunLoop events for GLib event loop implementation.
+
+        * wtf/RunLoop.h:
+        * wtf/glib/RunLoopGLib.cpp:
+        (WTF::RunLoop::RunLoop): Use RunLoopSource struct and initialize the RunLoop.
+        (WTF::RunLoop::observe): Add the given observer to the set.
+        (WTF::RunLoop::notify): Notife observers of the given event.
+        (WTF::RunLoop::TimerBase::TimerBase): Use RunLoopSource struct and initialize the RunLoop.
+
 2020-08-11  Wenson Hsieh  <[email protected]>
 
         Text input autocorrect="off" attribute ignored on Mac

Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/RunLoop.h	2020-09-04 11:15:58 UTC (rev 266587)
@@ -32,9 +32,11 @@
 #include <wtf/Forward.h>
 #include <wtf/FunctionDispatcher.h>
 #include <wtf/HashMap.h>
+#include <wtf/Observer.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/Seconds.h>
 #include <wtf/ThreadingPrimitives.h>
+#include <wtf/WeakHashSet.h>
 #include <wtf/text/WTFString.h>
 
 #if USE(CF)
@@ -96,6 +98,9 @@
 
 #if USE(GLIB_EVENT_LOOP)
     WTF_EXPORT_PRIVATE GMainContext* mainContext() const { return m_mainContext.get(); }
+    enum class Event { WillDispatch, DidDispatch };
+    using Observer = WTF::Observer<void(Event)>;
+    WTF_EXPORT_PRIVATE void observe(const Observer&);
 #endif
 
 #if USE(GENERIC_EVENT_LOOP) || USE(WINDOWS_EVENT_LOOP)
@@ -221,9 +226,13 @@
     RetainPtr<CFRunLoopRef> m_runLoop;
     RetainPtr<CFRunLoopSourceRef> m_runLoopSource;
 #elif USE(GLIB_EVENT_LOOP)
+    void notify(Event);
+
+    static GSourceFuncs s_runLoopSourceFunctions;
     GRefPtr<GMainContext> m_mainContext;
     Vector<GRefPtr<GMainLoop>> m_mainLoops;
     GRefPtr<GSource> m_source;
+    WeakHashSet<Observer> m_observers;
 #elif USE(GENERIC_EVENT_LOOP)
     void schedule(Ref<TimerBase::ScheduledTask>&&);
     void schedule(const AbstractLocker&, Ref<TimerBase::ScheduledTask>&&);

Modified: releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/glib/RunLoopGLib.cpp (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/glib/RunLoopGLib.cpp	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WTF/wtf/glib/RunLoopGLib.cpp	2020-09-04 11:15:58 UTC (rev 266587)
@@ -33,7 +33,12 @@
 
 namespace WTF {
 
-static GSourceFuncs runLoopSourceFunctions = {
+typedef struct {
+    GSource source;
+    RunLoop* runLoop;
+} RunLoopSource;
+
+GSourceFuncs RunLoop::s_runLoopSourceFunctions = {
     nullptr, // prepare
     nullptr, // check
     // dispatch
@@ -42,7 +47,11 @@
         if (g_source_get_ready_time(source) == -1)
             return G_SOURCE_CONTINUE;
         g_source_set_ready_time(source, -1);
-        return callback(userData);
+        auto& runLoopSource = *reinterpret_cast<RunLoopSource*>(source);
+        runLoopSource.runLoop->notify(RunLoop::Event::WillDispatch);
+        auto returnValue = callback(userData);
+        runLoopSource.runLoop->notify(RunLoop::Event::DidDispatch);
+        return returnValue;
     },
     nullptr, // finalize
     nullptr, // closure_callback
@@ -60,7 +69,9 @@
     ASSERT(innermostLoop);
     m_mainLoops.append(innermostLoop);
 
-    m_source = adoptGRef(g_source_new(&runLoopSourceFunctions, sizeof(GSource)));
+    m_source = adoptGRef(g_source_new(&RunLoop::s_runLoopSourceFunctions, sizeof(RunLoopSource)));
+    auto& runLoopSource = *reinterpret_cast<RunLoopSource*>(m_source.get());
+    runLoopSource.runLoop = this;
     g_source_set_priority(m_source.get(), RunLoopSourcePriority::RunLoopDispatcher);
     g_source_set_name(m_source.get(), "[WebKit] RunLoop work");
     g_source_set_can_recurse(m_source.get(), TRUE);
@@ -129,10 +140,29 @@
     return CycleResult::Continue;
 }
 
+void RunLoop::observe(const RunLoop::Observer& observer)
+{
+    ASSERT(!m_observers.contains(observer));
+    m_observers.add(observer);
+}
+
+void RunLoop::notify(RunLoop::Event event)
+{
+    if (m_observers.computesEmpty())
+        return;
+
+    m_observers.forEach([event](auto& observer) {
+        observer(event);
+    });
+}
+
 RunLoop::TimerBase::TimerBase(RunLoop& runLoop)
     : m_runLoop(runLoop)
-    , m_source(adoptGRef(g_source_new(&runLoopSourceFunctions, sizeof(GSource))))
+    , m_source(adoptGRef(g_source_new(&RunLoop::s_runLoopSourceFunctions, sizeof(GSource))))
 {
+    auto& runLoopSource = *reinterpret_cast<RunLoopSource*>(m_source.get());
+    runLoopSource.runLoop = m_runLoop.ptr();
+
     g_source_set_priority(m_source.get(), RunLoopSourcePriority::RunLoopTimer);
     g_source_set_name(m_source.get(), "[WebKit] RunLoop::Timer work");
     g_source_set_callback(m_source.get(), [](gpointer userData) -> gboolean {

Modified: releases/WebKitGTK/webkit-2.30/Source/WebCore/ChangeLog (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WebCore/ChangeLog	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WebCore/ChangeLog	2020-09-04 11:15:58 UTC (rev 266587)
@@ -1,3 +1,18 @@
+2020-08-24  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] Implement rendering frames timeline panel for GTK+ port
+        https://bugs.webkit.org/show_bug.cgi?id=150392
+        <rdar://problem/23200510>
+
+        Reviewed by Brian Burg.
+
+        Use new RunLoop API to observe the run loop events when the GLib event loop is used.
+
+        * inspector/agents/InspectorTimelineAgent.cpp:
+        (WebCore::InspectorTimelineAgent::internalStart):
+        (WebCore::InspectorTimelineAgent::internalStop):
+        * inspector/agents/InspectorTimelineAgent.h:
+
 2020-08-14  Zalan Bujtas  <[email protected]>
 
         RenderTextControlSingleLine::scroll* functions should not call Element::scroll* on the inner text content

Modified: releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.cpp	2020-09-04 11:15:58 UTC (rev 266587)
@@ -226,6 +226,21 @@
     pushCurrentRecord(JSON::Object::create(), TimelineRecordType::RenderingFrame, false, nullptr);
 
     m_runLoopNestingLevel = 1;
+#elif USE(GLIB_EVENT_LOOP)
+    m_runLoopObserver = makeUnique<RunLoop::Observer>([this](RunLoop::Event event) {
+        if (!m_tracking || m_environment.scriptDebugServer().isPaused())
+            return;
+
+        switch (event) {
+        case RunLoop::Event::WillDispatch:
+            pushCurrentRecord(JSON::Object::create(), TimelineRecordType::RenderingFrame, false, nullptr);
+            break;
+        case RunLoop::Event::DidDispatch:
+            didCompleteCurrentRecord(TimelineRecordType::RenderingFrame);
+            break;
+        }
+    });
+    RunLoop::current().observe(*m_runLoopObserver);
 #endif
 
     m_frontendDispatcher->recordingStarted(timestamp());
@@ -247,11 +262,13 @@
     m_frameStartObserver = nullptr;
     m_frameStopObserver = nullptr;
     m_runLoopNestingLevel = 0;
+#elif USE(GLIB_EVENT_LOOP)
+    m_runLoopObserver = nullptr;
+#endif
 
     // Complete all pending records to prevent discarding events that are currently in progress.
     while (!m_recordStack.isEmpty())
         didCompleteCurrentRecord(m_recordStack.last().type);
-#endif
 
     m_recordStack.clear();
 

Modified: releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.h (266586 => 266587)


--- releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.h	2020-09-04 11:15:52 UTC (rev 266586)
+++ releases/WebKitGTK/webkit-2.30/Source/WebCore/inspector/agents/InspectorTimelineAgent.h	2020-09-04 11:15:58 UTC (rev 266587)
@@ -38,6 +38,7 @@
 #include <_javascript_Core/InspectorFrontendDispatchers.h>
 #include <_javascript_Core/ScriptDebugListener.h>
 #include <wtf/JSONValues.h>
+#include <wtf/RunLoop.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -223,8 +224,10 @@
 #if PLATFORM(COCOA)
     std::unique_ptr<WebCore::RunLoopObserver> m_frameStartObserver;
     std::unique_ptr<WebCore::RunLoopObserver> m_frameStopObserver;
+    int m_runLoopNestingLevel { 0 };
+#elif USE(GLIB_EVENT_LOOP)
+    std::unique_ptr<RunLoop::Observer> m_runLoopObserver;
 #endif
-    int m_runLoopNestingLevel { 0 };
     bool m_startedComposite { false };
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to