Title: [174818] trunk/Source
Revision
174818
Author
[email protected]
Date
2014-10-17 03:10:47 -0700 (Fri, 17 Oct 2014)

Log Message

[GLIB] Add API to GMainLoopSource to schedule sources after a delay in microseconds
https://bugs.webkit.org/show_bug.cgi?id=137782

Reviewed by Sergio Villar Senin.

Source/WebCore:

* platform/gtk/SharedTimerGtk.cpp:
(WebCore::setSharedTimerFireInterval): Use microseconds instead of
milliseconds.

Source/WebKit2:

* WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
(WebKit::LayerTreeHostGtk::layerFlushTimerFired): Use microseconds
instead of milliseconds.

Source/WTF:

In some cases when we have a double with the time in seconds, the
conversion to milliseconds ends up truncating the value to 0, and
the source scheduled immediately.

* wtf/gobject/GMainLoopSource.cpp:
(WTF::createMicrosecondsTimeoutSource): Use a custom timeout
source that handles the interval in microseconds instead of milliseconds.
(WTF::GMainLoopSource::scheduleAfterDelay): Use MicrosecondsTimeoutSource.
(WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Ditto.
* wtf/gobject/GMainLoopSource.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (174817 => 174818)


--- trunk/Source/WTF/ChangeLog	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WTF/ChangeLog	2014-10-17 10:10:47 UTC (rev 174818)
@@ -1,3 +1,21 @@
+2014-10-17  Carlos Garcia Campos  <[email protected]>
+
+        [GLIB] Add API to GMainLoopSource to schedule sources after a delay in microseconds
+        https://bugs.webkit.org/show_bug.cgi?id=137782
+
+        Reviewed by Sergio Villar Senin.
+
+        In some cases when we have a double with the time in seconds, the
+        conversion to milliseconds ends up truncating the value to 0, and
+        the source scheduled immediately.
+
+        * wtf/gobject/GMainLoopSource.cpp:
+        (WTF::createMicrosecondsTimeoutSource): Use a custom timeout
+        source that handles the interval in microseconds instead of milliseconds.
+        (WTF::GMainLoopSource::scheduleAfterDelay): Use MicrosecondsTimeoutSource.
+        (WTF::GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy): Ditto.
+        * wtf/gobject/GMainLoopSource.h:
+
 2014-10-17  Dan Bernstein  <[email protected]>
 
         Reverted incorrect build fix attempt.

Modified: trunk/Source/WTF/wtf/gobject/GMainLoopSource.cpp (174817 => 174818)


--- trunk/Source/WTF/wtf/gobject/GMainLoopSource.cpp	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WTF/wtf/gobject/GMainLoopSource.cpp	2014-10-17 10:10:47 UTC (rev 174818)
@@ -233,6 +233,69 @@
     scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
 }
 
+struct MicrosecondsTimeoutSource {
+    GSource source;
+    uint64_t delay;
+};
+
+static GSourceFuncs microsecondsTimeoutSourceFunctions = {
+    nullptr, // prepare
+    nullptr, // check
+    // dispatch
+    [](GSource* source, GSourceFunc callback, gpointer userData) -> gboolean
+    {
+        bool repeat = callback(userData);
+        if (repeat)
+            g_source_set_ready_time(source, g_source_get_time(source) + reinterpret_cast<MicrosecondsTimeoutSource*>(source)->delay);
+        return repeat;
+    },
+    nullptr, // finalize
+    nullptr, // closure_callback
+    nullptr // closure_marshall
+};
+
+static GSource* createMicrosecondsTimeoutSource(uint64_t delay)
+{
+    GSource* source = g_source_new(&microsecondsTimeoutSourceFunctions, sizeof(MicrosecondsTimeoutSource));
+    reinterpret_cast<MicrosecondsTimeoutSource*>(source)->delay = delay;
+    g_source_set_ready_time(source, g_get_monotonic_time() + delay);
+    return source;
+}
+
+void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<void ()> function, std::chrono::microseconds delay, int priority, std::function<void ()> destroyFunction, GMainContext* context)
+{
+    cancel();
+
+    ASSERT(!m_context.source);
+    m_context = {
+        adoptGRef(createMicrosecondsTimeoutSource(delay.count())),
+        nullptr, // cancellable
+        nullptr, // socketCancellable
+        WTF::move(function),
+        nullptr, // boolCallback
+        nullptr, // socketCallback
+        WTF::move(destroyFunction)
+    };
+    scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(voidSourceCallback), priority, context);
+}
+
+void GMainLoopSource::scheduleAfterDelay(const char* name, std::function<bool ()> function, std::chrono::microseconds delay, int priority, std::function<void ()> destroyFunction, GMainContext* context)
+{
+    cancel();
+
+    ASSERT(!m_context.source);
+    m_context = {
+        adoptGRef(createMicrosecondsTimeoutSource(delay.count())),
+        nullptr, // cancellable
+        nullptr, // socketCancellable
+        nullptr, // voidCallback
+        WTF::move(function),
+        nullptr, // socketCallback
+        WTF::move(destroyFunction)
+    };
+    scheduleTimeoutSource(name, reinterpret_cast<GSourceFunc>(boolSourceCallback), priority, context);
+}
+
 void GMainLoopSource::scheduleAndDeleteOnDestroy(const char* name, std::function<void()> function, int priority, std::function<void()> destroyFunction, GMainContext* context)
 {
     create().schedule(name, function, priority, destroyFunction, context);
@@ -263,6 +326,16 @@
     create().scheduleAfterDelay(name, function, delay, priority, destroyFunction, context);
 }
 
+void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()> function, std::chrono::microseconds delay, int priority, std::function<void()> destroyFunction, GMainContext* context)
+{
+    create().scheduleAfterDelay(name, function, delay, priority, destroyFunction, context);
+}
+
+void GMainLoopSource::scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()> function, std::chrono::microseconds delay, int priority, std::function<void()> destroyFunction, GMainContext* context)
+{
+    create().scheduleAfterDelay(name, function, delay, priority, destroyFunction, context);
+}
+
 bool GMainLoopSource::prepareVoidCallback(Context& context)
 {
     if (!m_context.source)

Modified: trunk/Source/WTF/wtf/gobject/GMainLoopSource.h (174817 => 174818)


--- trunk/Source/WTF/wtf/gobject/GMainLoopSource.h	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WTF/wtf/gobject/GMainLoopSource.h	2014-10-17 10:10:47 UTC (rev 174818)
@@ -56,6 +56,8 @@
     WTF_EXPORT_PRIVATE virtual void scheduleAfterDelay(const char* name, std::function<bool()>, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
     WTF_EXPORT_PRIVATE virtual void scheduleAfterDelay(const char* name, std::function<void()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
     WTF_EXPORT_PRIVATE virtual void scheduleAfterDelay(const char* name, std::function<bool()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
+    WTF_EXPORT_PRIVATE virtual void scheduleAfterDelay(const char* name, std::function<void()>, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
+    WTF_EXPORT_PRIVATE virtual void scheduleAfterDelay(const char* name, std::function<bool()>, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
     WTF_EXPORT_PRIVATE virtual void cancel();
 
     WTF_EXPORT_PRIVATE void schedule(const char* name, std::function<bool(GIOCondition)>, GSocket*, GIOCondition, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
@@ -66,6 +68,8 @@
     static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>, std::chrono::milliseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
     static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
     static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>, std::chrono::seconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
+    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<void()>, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
+    static void scheduleAfterDelayAndDeleteOnDestroy(const char* name, std::function<bool()>, std::chrono::microseconds, int priority = G_PRIORITY_DEFAULT, std::function<void()> destroyFunction = nullptr, GMainContext* = nullptr);
 
 protected:
     enum Status { Ready, Scheduled, Dispatching };

Modified: trunk/Source/WebCore/ChangeLog (174817 => 174818)


--- trunk/Source/WebCore/ChangeLog	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WebCore/ChangeLog	2014-10-17 10:10:47 UTC (rev 174818)
@@ -1,5 +1,16 @@
 2014-10-17  Carlos Garcia Campos  <[email protected]>
 
+        [GLIB] Add API to GMainLoopSource to schedule sources after a delay in microseconds
+        https://bugs.webkit.org/show_bug.cgi?id=137782
+
+        Reviewed by Sergio Villar Senin.
+
+        * platform/gtk/SharedTimerGtk.cpp:
+        (WebCore::setSharedTimerFireInterval): Use microseconds instead of
+        milliseconds.
+
+2014-10-17  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Move touch events handling from Platform to WebKit2
         https://bugs.webkit.org/show_bug.cgi?id=137735
 

Modified: trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp (174817 => 174818)


--- trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp	2014-10-17 10:10:47 UTC (rev 174818)
@@ -48,7 +48,7 @@
     ASSERT(sharedTimerFiredFunction);
 
     gSharedTimer.scheduleAfterDelay("[WebKit] sharedTimerTimeoutCallback", std::function<void()>(sharedTimerFiredFunction),
-        std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(interval)), GDK_PRIORITY_REDRAW);
+        std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(interval)), GDK_PRIORITY_REDRAW);
 }
 
 void stopSharedTimer()

Modified: trunk/Source/WebKit2/ChangeLog (174817 => 174818)


--- trunk/Source/WebKit2/ChangeLog	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WebKit2/ChangeLog	2014-10-17 10:10:47 UTC (rev 174818)
@@ -1,5 +1,16 @@
 2014-10-17  Carlos Garcia Campos  <[email protected]>
 
+        [GLIB] Add API to GMainLoopSource to schedule sources after a delay in microseconds
+        https://bugs.webkit.org/show_bug.cgi?id=137782
+
+        Reviewed by Sergio Villar Senin.
+
+        * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp:
+        (WebKit::LayerTreeHostGtk::layerFlushTimerFired): Use microseconds
+        instead of milliseconds.
+
+2014-10-17  Carlos Garcia Campos  <[email protected]>
+
         [GTK] Move touch events handling from Platform to WebKit2
         https://bugs.webkit.org/show_bug.cgi?id=137735
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp (174817 => 174818)


--- trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp	2014-10-17 10:04:37 UTC (rev 174817)
+++ trunk/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp	2014-10-17 10:10:47 UTC (rev 174818)
@@ -259,7 +259,7 @@
         const double targetFPS = 60;
         double nextFlush = std::max((1 / targetFPS) - (currentTime() - m_lastFlushTime), 0.0);
         m_layerFlushTimerCallback.scheduleAfterDelay("[WebKit] layerFlushTimer", std::bind(&LayerTreeHostGtk::layerFlushTimerFired, this),
-            std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<double>(nextFlush)), GDK_PRIORITY_EVENTS);
+            std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::duration<double>(nextFlush)), GDK_PRIORITY_EVENTS);
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to