Title: [104644] trunk/Source
Revision
104644
Author
[email protected]
Date
2012-01-10 15:50:35 -0800 (Tue, 10 Jan 2012)

Log Message

[chromium] Reuse old timebase when activating CCDelayBasedTimeSource
https://bugs.webkit.org/show_bug.cgi?id=75938

Reviewed by James Robinson.

Source/WebCore:

* platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp:
(WebCore::CCDelayBasedTimeSource::CCDelayBasedTimeSource):
(WebCore::CCDelayBasedTimeSource::setActive):
(WebCore::CCDelayBasedTimeSource::onTimerFired):
(WebCore::CCDelayBasedTimeSource::postNextTickTask):
* platform/graphics/chromium/cc/CCDelayBasedTimeSource.h:

Source/WebKit/chromium:

* tests/CCDelayBasedTimeSourceTest.cpp:
(WebKitTests::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (104643 => 104644)


--- trunk/Source/WebCore/ChangeLog	2012-01-10 23:48:39 UTC (rev 104643)
+++ trunk/Source/WebCore/ChangeLog	2012-01-10 23:50:35 UTC (rev 104644)
@@ -1,3 +1,17 @@
+2012-01-10  Nat Duca  <[email protected]>
+
+        [chromium] Reuse old timebase when activating CCDelayBasedTimeSource
+        https://bugs.webkit.org/show_bug.cgi?id=75938
+
+        Reviewed by James Robinson.
+
+        * platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp:
+        (WebCore::CCDelayBasedTimeSource::CCDelayBasedTimeSource):
+        (WebCore::CCDelayBasedTimeSource::setActive):
+        (WebCore::CCDelayBasedTimeSource::onTimerFired):
+        (WebCore::CCDelayBasedTimeSource::postNextTickTask):
+        * platform/graphics/chromium/cc/CCDelayBasedTimeSource.h:
+
 2012-01-10  Kentaro Hara  <[email protected]>
 
         Support the [Supplemental] IDL on methods

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp (104643 => 104644)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp	2012-01-10 23:48:39 UTC (rev 104643)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp	2012-01-10 23:50:35 UTC (rev 104644)
@@ -40,10 +40,11 @@
 
 CCDelayBasedTimeSource::CCDelayBasedTimeSource(double intervalMs, CCThread* thread)
     : m_client(0)
+    , m_hasTickTarget(false)
     , m_intervalMs(intervalMs)
     , m_tickTarget(0)
     , m_state(STATE_INACTIVE)
-    , m_thread(thread)
+    , m_timer(thread, this)
 {
 }
 
@@ -51,29 +52,45 @@
 {
     if (!active) {
         m_state = STATE_INACTIVE;
+        m_timer.stop();
         return;
     }
 
-    // Becoming active is deferred: we post a 0-delay task. When it runs, we use
-    // that to establish the timebase, become truly active, and fire the first
-    // tick.
     if (m_state == STATE_STARTING || m_state == STATE_ACTIVE)
         return;
 
-    m_state = STATE_STARTING;
-    postTickTask(0);
+    if (!m_hasTickTarget) {
+        // Becoming active the first time is deferred: we post a 0-delay task. When
+        // it runs, we use that to establish the timebase, become truly active, and
+        // fire the first tick.
+        m_state = STATE_STARTING;
+        m_timer.startOneShot(0);
+        return;
+    }
+
+    m_state = STATE_ACTIVE;
+
+    double nowMs = monotonicallyIncreasingTimeMs();
+    postNextTickTask(nowMs);
 }
 
-void CCDelayBasedTimeSource::postTickTask(long long delay)
+void CCDelayBasedTimeSource::onTimerFired()
 {
-    this->ref();
-    m_thread->postDelayedTask(createCCThreadTask(this, &CCDelayBasedTimeSource::onTick), delay);
-}
+    ASSERT(m_state != STATE_INACTIVE);
 
-void CCDelayBasedTimeSource::onTick()
-{
-    updateState();
-    this->deref();
+    double nowMs = monotonicallyIncreasingTimeMs();
+
+    if (m_state == STATE_STARTING) {
+        m_hasTickTarget = true;
+        m_tickTarget = nowMs;
+        m_state = STATE_ACTIVE;
+    }
+
+    postNextTickTask(nowMs);
+
+    // Fire the tick
+    if (m_client)
+        m_client->onTimerTick();
 }
 
 double CCDelayBasedTimeSource::monotonicallyIncreasingTimeMs() const
@@ -124,36 +141,22 @@
 //
 // For the really late delay, we we move to the next logical tick. The timebase is not reset.
 //      now=37   tickTarget=16.667  newTarget=50.000  --> tick(), postDelayedTask(floor(50.000-37)) --> postDelayedTask(13)
-void CCDelayBasedTimeSource::updateState()
+void CCDelayBasedTimeSource::postNextTickTask(double nowMs)
 {
-    if (m_state == STATE_INACTIVE)
-        return;
-
-    double now = monotonicallyIncreasingTimeMs();
-
-    if (m_state == STATE_STARTING) {
-        m_tickTarget = now;
-        m_state = STATE_ACTIVE;
-    }
-
-    int numIntervalsElapsed = static_cast<int>(floor((now - m_tickTarget) / m_intervalMs));
+    int numIntervalsElapsed = static_cast<int>(floor((nowMs - m_tickTarget) / m_intervalMs));
     double lastEffectiveTick = m_tickTarget + m_intervalMs * numIntervalsElapsed;
     double newTickTarget = lastEffectiveTick + m_intervalMs;
 
-    long long delay = static_cast<long long>(newTickTarget - now);
+    long long delay = static_cast<long long>(newTickTarget - nowMs);
     if (!delay) {
         newTickTarget = newTickTarget + m_intervalMs;
-        delay = static_cast<long long>(newTickTarget - now);
+        delay = static_cast<long long>(newTickTarget - nowMs);
     }
 
     // Post another task *before* the tick and update state
-    ASSERT(newTickTarget > now);
-    postTickTask(delay);
+    ASSERT(newTickTarget > nowMs);
+    m_timer.startOneShot(delay);
     m_tickTarget = newTickTarget;
-
-    // Fire the tick
-    if (m_client)
-        m_client->onTimerTick();
 }
 
 }

Modified: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h (104643 => 104644)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h	2012-01-10 23:48:39 UTC (rev 104643)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h	2012-01-10 23:50:35 UTC (rev 104644)
@@ -26,6 +26,7 @@
 #define CCDelayBasedTimeSource_h
 
 #include "cc/CCTimeSource.h"
+#include "cc/CCTimer.h"
 
 #include <wtf/PassRefPtr.h>
 
@@ -35,7 +36,7 @@
 
 // This timer implements a time source that achieves the specified interval
 // in face of millisecond-precision delayed callbacks and random queueing delays.
-class CCDelayBasedTimeSource : public CCTimeSource {
+class CCDelayBasedTimeSource : public CCTimeSource, CCTimerClient {
 public:
     static PassRefPtr<CCDelayBasedTimeSource> create(double intervalMs, CCThread*);
 
@@ -45,14 +46,15 @@
 
     virtual void setActive(bool);
 
+    // CCTimerClient implementation.
+    virtual void onTimerFired();
+
     // Virtual for testing.
     virtual double monotonicallyIncreasingTimeMs() const;
 
 protected:
     CCDelayBasedTimeSource(double intervalMs, CCThread*);
-    void onTick();
-    void updateState();
-    void postTickTask(long long delay);
+    void postNextTickTask(double nowMs);
 
     enum State {
         STATE_INACTIVE,
@@ -60,10 +62,12 @@
         STATE_ACTIVE,
     };
     CCTimeSourceClient* m_client;
+    bool m_hasTickTarget;
     double m_intervalMs;
     double m_tickTarget;
     State m_state;
     CCThread* m_thread;
+    CCTimer m_timer;
 };
 
 }

Modified: trunk/Source/WebKit/chromium/ChangeLog (104643 => 104644)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-01-10 23:48:39 UTC (rev 104643)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-01-10 23:50:35 UTC (rev 104644)
@@ -1,3 +1,13 @@
+2012-01-10  Nat Duca  <[email protected]>
+
+        [chromium] Reuse old timebase when activating CCDelayBasedTimeSource
+        https://bugs.webkit.org/show_bug.cgi?id=75938
+
+        Reviewed by James Robinson.
+
+        * tests/CCDelayBasedTimeSourceTest.cpp:
+        (WebKitTests::TEST):
+
 2012-01-10  Tony Chang  <[email protected]>
 
         [chromium] Unreviewed, roll Chromium DEPS to r117109.

Modified: trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp (104643 => 104644)


--- trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp	2012-01-10 23:48:39 UTC (rev 104643)
+++ trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp	2012-01-10 23:50:35 UTC (rev 104644)
@@ -224,7 +224,7 @@
     EXPECT_NEAR(1000.0 / 60.0, averageInterval, 0.1);
 }
 
-TEST(CCDelayBasedTimeSource, TestUnrefWhilePending)
+TEST(CCDelayBasedTimeSource, TestDeactivateWhilePending)
 {
     FakeCCThread thread;
     FakeCCTimeSourceClient client;
@@ -233,7 +233,57 @@
     timer->setActive(true); // Should post a task.
     timer->setActive(false);
     timer.clear();
-    thread.runPendingTask(); // Should run the posted task, and delete the timer object.
+    thread.runPendingTask(); // Should run the posted task without crashing.
 }
 
+TEST(CCDelayBasedTimeSource, TestDeactivateAndReactivateBeforeNextTickTime)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+
+    // Should run the activate task, and pick up a new timebase.
+    timer->setActive(true);
+    timer->setMonotonicallyIncreasingTimeMs(0);
+    thread.runPendingTask();
+
+    // Stop the timer
+    timer->setActive(false);
+
+    // Task will be pending anyway, run it
+    thread.runPendingTask();
+
+    // Start the timer again, but before the next tick time the timer previously
+    // planned on using. That same tick time should still be targeted.
+    timer->setMonotonicallyIncreasingTimeMs(4);
+    timer->setActive(true);
+    EXPECT_EQ(12, thread.pendingDelay());
 }
+
+TEST(CCDelayBasedTimeSource, TestDeactivateAndReactivateAfterNextTickTime)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+
+    // Should run the activate task, and pick up a new timebase.
+    timer->setActive(true);
+    timer->setMonotonicallyIncreasingTimeMs(0);
+    thread.runPendingTask();
+
+    // Stop the timer
+    timer->setActive(false);
+
+    // Task will be pending anyway, run it
+    thread.runPendingTask();
+
+    // Start the timer again, but before the next tick time the timer previously
+    // planned on using. That same tick time should still be targeted.
+    timer->setMonotonicallyIncreasingTimeMs(20);
+    timer->setActive(true);
+    EXPECT_EQ(13, thread.pendingDelay());
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to