Title: [98700] trunk/Source
Revision
98700
Author
[email protected]
Date
2011-10-27 23:50:19 -0700 (Thu, 27 Oct 2011)

Log Message

[chromium] Implement frame rate control portions of CCScheduler
https://bugs.webkit.org/show_bug.cgi?id=70713

Reviewed by James Robinson.

Source/WebCore:

* WebCore.gypi:
* platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp: Added.
(WebCore::CCDelayBasedTimeSource::setActive):
(WebCore::CCDelayBasedTimeSource::postTickTask):
(WebCore::CCDelayBasedTimeSource::onTick):
* platform/graphics/chromium/cc/CCDelayBasedTimeSource.h: Added.
(WebCore::CCDelayBasedTimeSource::CCDelayBasedTimeSource):
(WebCore::CCDelayBasedTimeSource::~CCDelayBasedTimeSource):
(WebCore::CCDelayBasedTimeSource::setClient):
(WebCore::CCDelayBasedTimeSource::monotonicallyIncreasingTime):
* platform/graphics/chromium/cc/CCFrameRateController.cpp: Added.
(WebCore::CCFrameRateControllerTimeSourceAdapter::create):
(WebCore::CCFrameRateControllerTimeSourceAdapter::~CCFrameRateControllerTimeSourceAdapter):
(WebCore::CCFrameRateControllerTimeSourceAdapter::onTimerTick):
(WebCore::CCFrameRateControllerTimeSourceAdapter::CCFrameRateControllerTimeSourceAdapter):
(WebCore::CCFrameRateController::CCFrameRateController):
(WebCore::CCFrameRateController::~CCFrameRateController):
(WebCore::CCFrameRateController::onTimerTick):
(WebCore::CCFrameRateController::didBeginFrame):
(WebCore::CCFrameRateController::didFinishFrame):
(WebCore::CCFrameRateController::didAbortAllPendingFrames):
* platform/graphics/chromium/cc/CCFrameRateController.h: Added.
(WebCore::CCFrameRateControllerClient::~CCFrameRateControllerClient):
(WebCore::CCFrameRateController::setClient):
(WebCore::CCFrameRateController::setActive):
* platform/graphics/chromium/cc/CCTimeSource.h: Added.
(WebCore::CCTimeSourceClient::~CCTimeSourceClient):
(WebCore::CCTimeSource::~CCTimeSource):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/CCDelayBasedTimeSourceTest.cpp: Added.
(WebKitTests::TEST):
* tests/CCFrameRateControllerTest.cpp: Added.
(WebKitTests::FakeCCFrameRateControllerClient::FakeCCFrameRateControllerClient):
(WebKitTests::FakeCCFrameRateControllerClient::reset):
(WebKitTests::FakeCCFrameRateControllerClient::frameBegun):
(WebKitTests::FakeCCFrameRateControllerClient::beginFrame):
(WebKitTests::TEST):
* tests/CCLayerTreeHostTest.cpp:
* tests/CCSchedulerTestCommon.h: Added.
(WebKitTests::FakeCCTimeSourceClient::FakeCCTimeSourceClient):
(WebKitTests::FakeCCTimeSourceClient::reset):
(WebKitTests::FakeCCTimeSourceClient::tickCalled):
(WebKitTests::FakeCCTimeSourceClient::onTimerTick):
(WebKitTests::FakeCCThread::FakeCCThread):
(WebKitTests::FakeCCThread::reset):
(WebKitTests::FakeCCThread::hasPendingTask):
(WebKitTests::FakeCCThread::runPendingTask):
(WebKitTests::FakeCCThread::pendingDelay):
(WebKitTests::FakeCCThread::postTask):
(WebKitTests::FakeCCThread::postDelayedTask):
(WebKitTests::FakeCCThread::threadID):
(WebKitTests::FakeCCDelayBasedTimeSource::FakeCCDelayBasedTimeSource):
(WebKitTests::FakeCCDelayBasedTimeSource::setMonotonicallyIncreasingTime):
(WebKitTests::FakeCCDelayBasedTimeSource::monotonicallyIncreasingTime):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (98699 => 98700)


--- trunk/Source/WebCore/ChangeLog	2011-10-28 06:44:54 UTC (rev 98699)
+++ trunk/Source/WebCore/ChangeLog	2011-10-28 06:50:19 UTC (rev 98700)
@@ -1,3 +1,39 @@
+2011-10-26  Nat Duca  <[email protected]>
+
+        [chromium] Implement frame rate control portions of CCScheduler
+        https://bugs.webkit.org/show_bug.cgi?id=70713
+
+        Reviewed by James Robinson.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp: Added.
+        (WebCore::CCDelayBasedTimeSource::setActive):
+        (WebCore::CCDelayBasedTimeSource::postTickTask):
+        (WebCore::CCDelayBasedTimeSource::onTick):
+        * platform/graphics/chromium/cc/CCDelayBasedTimeSource.h: Added.
+        (WebCore::CCDelayBasedTimeSource::CCDelayBasedTimeSource):
+        (WebCore::CCDelayBasedTimeSource::~CCDelayBasedTimeSource):
+        (WebCore::CCDelayBasedTimeSource::setClient):
+        (WebCore::CCDelayBasedTimeSource::monotonicallyIncreasingTime):
+        * platform/graphics/chromium/cc/CCFrameRateController.cpp: Added.
+        (WebCore::CCFrameRateControllerTimeSourceAdapter::create):
+        (WebCore::CCFrameRateControllerTimeSourceAdapter::~CCFrameRateControllerTimeSourceAdapter):
+        (WebCore::CCFrameRateControllerTimeSourceAdapter::onTimerTick):
+        (WebCore::CCFrameRateControllerTimeSourceAdapter::CCFrameRateControllerTimeSourceAdapter):
+        (WebCore::CCFrameRateController::CCFrameRateController):
+        (WebCore::CCFrameRateController::~CCFrameRateController):
+        (WebCore::CCFrameRateController::onTimerTick):
+        (WebCore::CCFrameRateController::didBeginFrame):
+        (WebCore::CCFrameRateController::didFinishFrame):
+        (WebCore::CCFrameRateController::didAbortAllPendingFrames):
+        * platform/graphics/chromium/cc/CCFrameRateController.h: Added.
+        (WebCore::CCFrameRateControllerClient::~CCFrameRateControllerClient):
+        (WebCore::CCFrameRateController::setClient):
+        (WebCore::CCFrameRateController::setActive):
+        * platform/graphics/chromium/cc/CCTimeSource.h: Added.
+        (WebCore::CCTimeSourceClient::~CCTimeSourceClient):
+        (WebCore::CCTimeSource::~CCTimeSource):
+
 2011-10-27  Kentaro Hara  <[email protected]>
 
         Deprecate [V8ConstructorSetsActiveDOMWrapper] IDL

Modified: trunk/Source/WebCore/WebCore.gypi (98699 => 98700)


--- trunk/Source/WebCore/WebCore.gypi	2011-10-28 06:44:54 UTC (rev 98699)
+++ trunk/Source/WebCore/WebCore.gypi	2011-10-28 06:50:19 UTC (rev 98700)
@@ -3533,6 +3533,10 @@
             'platform/graphics/chromium/WebGLLayerChromium.h',
             'platform/graphics/chromium/cc/CCCanvasLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCCanvasLayerImpl.h',
+            'platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp',
+            'platform/graphics/chromium/cc/CCDelayBasedTimeSource.h',
+            'platform/graphics/chromium/cc/CCFrameRateController.cpp',
+            'platform/graphics/chromium/cc/CCFrameRateController.h',
             'platform/graphics/chromium/cc/CCHeadsUpDisplay.cpp',
             'platform/graphics/chromium/cc/CCHeadsUpDisplay.h',
             'platform/graphics/chromium/cc/CCInputHandler.h',
@@ -3575,6 +3579,7 @@
             'platform/graphics/chromium/cc/CCThreadTask.h',
             'platform/graphics/chromium/cc/CCTiledLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCTiledLayerImpl.h',
+            'platform/graphics/chromium/cc/CCTimeSource.h',
             'platform/graphics/chromium/cc/CCVideoLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCVideoLayerImpl.h',
             'platform/graphics/cocoa/FontPlatformDataCocoa.mm',

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp (0 => 98700)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2011 Google 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 "cc/CCDelayBasedTimeSource.h"
+
+#include "cc/CCThread.h"
+#include "cc/CCThreadTask.h"
+
+namespace WebCore {
+
+PassRefPtr<CCDelayBasedTimeSource> CCDelayBasedTimeSource::create(double intervalMs, CCThread* thread)
+{
+    return adoptRef(new CCDelayBasedTimeSource(intervalMs, thread));
+}
+
+CCDelayBasedTimeSource::CCDelayBasedTimeSource(double intervalMs, CCThread* thread)
+    : m_client(0)
+    , m_intervalMs(intervalMs)
+    , m_tickTarget(0)
+    , m_state(STATE_INACTIVE)
+    , m_thread(thread)
+{
+}
+
+void CCDelayBasedTimeSource::setActive(bool active)
+{
+    if (!active) {
+        m_state = STATE_INACTIVE;
+        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);
+}
+
+void CCDelayBasedTimeSource::postTickTask(long long delay)
+{
+    this->ref();
+    m_thread->postDelayedTask(createCCThreadTask(this, &CCDelayBasedTimeSource::onTick), delay);
+}
+
+void CCDelayBasedTimeSource::onTick()
+{
+    updateState();
+    this->deref();
+}
+
+// This code tries to achieve an average tick rate as close to m_intervalMs as possible.
+// To do this, it has to deal with a few basic issues:
+//   1. postDelayedTask can delay only at a millisecond granularity. So, 16.666 has to
+//      posted as 16 or 17.
+//   2. A delayed task may come back a bit late (a few ms), or really late (frames later)
+//
+// The basic idea with this scheduler here is to keep track of where we *want* to run in
+// m_tickTarget. We update this with the exact interval.
+//
+// Then, when we post our task, we take the floor of (m_tickTarget and now()). If we
+// started at now=0, and 60FPs:
+//      now=0    target=16.667   postDelayedTask(16)
+//
+// When our callback runs, we figure out how far off we were from that goal. Because of the flooring
+// operation, and assuming our timer runs exactly when it should, this yields:
+//      now=16   target=16.667
+//
+// Since we can't post a 0.667 ms task to get to now=16, we just treat this as a tick. Then,
+// we update target to be 33.333. We now post another task based on the difference between our target
+// and now:
+//      now=16   tickTarget=16.667  newTarget=33.333   --> postDelayedTask(floor(33.333 - 16)) --> postDelayedTask(17)
+//
+// Over time, with no late tasks, this leads to us posting tasks like this:
+//      now=0    tickTarget=0       newTarget=16.667   --> tick(), postDelayedTask(16)
+//      now=16   tickTarget=16.667  newTarget=33.333   --> tick(), postDelayedTask(17)
+//      now=33   tickTarget=33.333  newTarget=50.000   --> tick(), postDelayedTask(17)
+//      now=50   tickTarget=50.000  newTarget=66.667   --> tick(), postDelayedTask(16)
+//
+// We treat delays in tasks differently depending on the amount of delay we encounter. Suppose we
+// posted a task with a target=16.667:
+//   Case 1: late but not unrecoverably-so
+//      now=18 tickTarget=16.667
+//
+//   Case 2: so late we obviously missed the tick
+//      now=25.0 tickTarget=16.667
+//
+// We treat the first case as a tick anyway, and assume the delay was
+// unusual. Thus, we compute the newTarget based on the old timebase:
+//      now=18   tickTarget=16.667  newTarget=33.333   --> tick(), postDelayedTask(floor(33.333-18)) --> postDelayedTask(15)
+// This brings us back to 18+15 = 33, which was where we would have been if the task hadn't been late.
+//
+// For the really late delay, we fire a tick immediately reset the timebase from the current tim. E.g.:
+//      now=37   tickTarget=16.667  newTarget=53.6667   --> tick(), postDelayedTask(floor(53.667-37)) --> postDelayedTask(16)
+//
+// Here we realize we're more than a tick late. We adjust newTarget to be 16.667 from now, and post a task off that new
+// target.
+void CCDelayBasedTimeSource::updateState()
+{
+    if (m_state == STATE_INACTIVE)
+        return;
+
+    double now = monotonicallyIncreasingTime();
+
+    if (m_state == STATE_STARTING) {
+        m_tickTarget = now;
+        m_state = STATE_ACTIVE;
+    }
+
+    const double maxLateBeforeResettingTimebase = 5.0;
+
+    double newTickTarget = 0;
+    double amountLate = now - m_tickTarget;
+    if (amountLate <= maxLateBeforeResettingTimebase)
+        newTickTarget = m_tickTarget + m_intervalMs;
+    else
+        newTickTarget = now + m_intervalMs;
+
+    // Post another task *before* the tick and update state
+    ASSERT(newTickTarget > now);
+    postTickTask(static_cast<long long>(newTickTarget - now));
+    m_tickTarget = newTickTarget;
+
+    // Fire the tick
+    if (m_client)
+        m_client->onTimerTick();
+}
+
+}
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h (0 => 98700)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2011 Google 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 CCDelayBasedTimeSource_h
+#define CCDelayBasedTimeSource_h
+
+#include "cc/CCTimeSource.h"
+
+#include <wtf/CurrentTime.h>
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+class CCThread;
+
+// 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 {
+public:
+    static PassRefPtr<CCDelayBasedTimeSource> create(double intervalMs, CCThread*);
+
+    virtual ~CCDelayBasedTimeSource() { }
+
+    virtual void setClient(CCTimeSourceClient* client) { m_client = client; }
+
+    virtual void setActive(bool);
+
+    // Virtual for testing.
+    virtual double monotonicallyIncreasingTime() const { return WTF::monotonicallyIncreasingTime(); }
+
+protected:
+    CCDelayBasedTimeSource(double intervalMs, CCThread*);
+    void onTick();
+    void updateState();
+    void postTickTask(long long delay);
+
+    enum State {
+        STATE_INACTIVE,
+        STATE_STARTING,
+        STATE_ACTIVE,
+    };
+    CCTimeSourceClient* m_client;
+    double m_intervalMs;
+    double m_tickTarget;
+    State m_state;
+    CCThread* m_thread;
+};
+
+}
+#endif // CCDelayBasedTimeSource_h
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.h
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.cpp (0 => 98700)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.cpp	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011 Google 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 "cc/CCFrameRateController.h"
+
+#include "cc/CCThread.h"
+#include "cc/CCThreadTask.h"
+
+namespace WebCore {
+
+class CCFrameRateControllerTimeSourceAdapter : public CCTimeSourceClient {
+public:
+    static PassOwnPtr<CCFrameRateControllerTimeSourceAdapter> create(CCFrameRateController* frameRateController)
+    {
+        return adoptPtr(new CCFrameRateControllerTimeSourceAdapter(frameRateController));
+    }
+    virtual ~CCFrameRateControllerTimeSourceAdapter() { }
+
+    virtual void onTimerTick() { m_frameRateController->onTimerTick(); }
+private:
+    explicit CCFrameRateControllerTimeSourceAdapter(CCFrameRateController* frameRateController)
+            : m_frameRateController(frameRateController) { }
+
+    CCFrameRateController* m_frameRateController;
+};
+
+CCFrameRateController::CCFrameRateController(PassRefPtr<CCTimeSource> timer)
+    : m_client(0)
+    , m_numFramesPending(0)
+    , m_timeSource(timer)
+{
+    m_timeSourceClientAdapter = CCFrameRateControllerTimeSourceAdapter::create(this);
+    m_timeSource->setClient(m_timeSourceClientAdapter.get());
+}
+
+CCFrameRateController::~CCFrameRateController()
+{
+    m_timeSource->setActive(false);
+}
+
+void CCFrameRateController::onTimerTick()
+{
+    // Don't forward the tick if we have too many frames in flight.
+    if (m_numFramesPending >= kMaxFramesPending)
+        return;
+
+    if (m_client)
+        m_client->beginFrame();
+}
+
+void CCFrameRateController::didBeginFrame()
+{
+    m_numFramesPending++;
+}
+
+void CCFrameRateController::didFinishFrame()
+{
+    m_numFramesPending--;
+}
+
+void CCFrameRateController::didAbortAllPendingFrames()
+{
+    m_numFramesPending = 0;
+}
+
+}
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.cpp
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.h (0 => 98700)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.h	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 Google 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 CCFrameRateController_h
+#define CCFrameRateController_h
+
+#include "cc/CCTimeSource.h"
+#include <wtf/CurrentTime.h>
+#include <wtf/Deque.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace WebCore {
+
+class CCFrameRateControllerClient {
+public:
+    virtual void beginFrame() = 0;
+
+protected:
+    virtual ~CCFrameRateControllerClient() { }
+};
+
+class CCFrameRateControllerTimeSourceAdapter;
+
+class CCFrameRateController {
+public:
+    explicit CCFrameRateController(PassRefPtr<CCTimeSource>);
+    ~CCFrameRateController();
+
+    void setClient(CCFrameRateControllerClient* client) { m_client = client; }
+
+    void setActive(bool active) { m_timeSource->setActive(active); }
+
+    // Use the following methods to adjust target frame rate.
+    //
+    // Multiple frames can be in-progress, but for every didBeginFrame, a
+    // didFinishFrame should be posted.
+    //
+    // If the rendering pipeline crashes, call didAbortAllPendingFrames.
+    void didBeginFrame();
+    void didFinishFrame();
+    void didAbortAllPendingFrames();
+
+    enum {
+        kMaxFramesPending = 2
+    };
+
+protected:
+    friend class CCFrameRateControllerTimeSourceAdapter;
+    void onTimerTick();
+
+    CCFrameRateControllerClient* m_client;
+    int m_numFramesPending;
+    RefPtr<CCTimeSource> m_timeSource;
+    OwnPtr<CCFrameRateControllerTimeSourceAdapter> m_timeSourceClientAdapter;
+};
+
+}
+#endif // CCFrameRateController_h
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCFrameRateController.h
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimeSource.h (0 => 98700)


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimeSource.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimeSource.h	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011 Google 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 CCTimeSource_h
+#define CCTimeSource_h
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class CCThread;
+
+class CCTimeSourceClient {
+public:
+    virtual void onTimerTick() = 0;
+
+protected:
+    virtual ~CCTimeSourceClient() { }
+};
+
+// An generic interface for getting a reliably-ticking timesource of
+// a specified rate.
+//
+// Be sure to call setActive(false) before releasing your reference to the
+// timer, or it will keep on ticking!
+class CCTimeSource : public RefCounted<CCTimeSource> {
+public:
+    virtual ~CCTimeSource() { }
+    virtual void setClient(CCTimeSourceClient*) = 0;
+    virtual void setActive(bool) = 0;
+};
+
+}
+#endif // CCSmoothedTimer_h
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimeSource.h
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebKit/chromium/ChangeLog (98699 => 98700)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-10-28 06:44:54 UTC (rev 98699)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-10-28 06:50:19 UTC (rev 98700)
@@ -1,3 +1,37 @@
+2011-10-26  Nat Duca  <[email protected]>
+
+        [chromium] Implement frame rate control portions of CCScheduler
+        https://bugs.webkit.org/show_bug.cgi?id=70713
+
+        Reviewed by James Robinson.
+
+        * WebKit.gypi:
+        * tests/CCDelayBasedTimeSourceTest.cpp: Added.
+        (WebKitTests::TEST):
+        * tests/CCFrameRateControllerTest.cpp: Added.
+        (WebKitTests::FakeCCFrameRateControllerClient::FakeCCFrameRateControllerClient):
+        (WebKitTests::FakeCCFrameRateControllerClient::reset):
+        (WebKitTests::FakeCCFrameRateControllerClient::frameBegun):
+        (WebKitTests::FakeCCFrameRateControllerClient::beginFrame):
+        (WebKitTests::TEST):
+        * tests/CCLayerTreeHostTest.cpp:
+        * tests/CCSchedulerTestCommon.h: Added.
+        (WebKitTests::FakeCCTimeSourceClient::FakeCCTimeSourceClient):
+        (WebKitTests::FakeCCTimeSourceClient::reset):
+        (WebKitTests::FakeCCTimeSourceClient::tickCalled):
+        (WebKitTests::FakeCCTimeSourceClient::onTimerTick):
+        (WebKitTests::FakeCCThread::FakeCCThread):
+        (WebKitTests::FakeCCThread::reset):
+        (WebKitTests::FakeCCThread::hasPendingTask):
+        (WebKitTests::FakeCCThread::runPendingTask):
+        (WebKitTests::FakeCCThread::pendingDelay):
+        (WebKitTests::FakeCCThread::postTask):
+        (WebKitTests::FakeCCThread::postDelayedTask):
+        (WebKitTests::FakeCCThread::threadID):
+        (WebKitTests::FakeCCDelayBasedTimeSource::FakeCCDelayBasedTimeSource):
+        (WebKitTests::FakeCCDelayBasedTimeSource::setMonotonicallyIncreasingTime):
+        (WebKitTests::FakeCCDelayBasedTimeSource::monotonicallyIncreasingTime):
+
 2011-10-27  Vangelis Kokkevis  <[email protected]>
 
         Expose Settings::setAcceleratedCompositingForFixedPositionEnabled to WebSettingsImpl.

Modified: trunk/Source/WebKit/chromium/WebKit.gypi (98699 => 98700)


--- trunk/Source/WebKit/chromium/WebKit.gypi	2011-10-28 06:44:54 UTC (rev 98699)
+++ trunk/Source/WebKit/chromium/WebKit.gypi	2011-10-28 06:50:19 UTC (rev 98700)
@@ -54,6 +54,8 @@
         'webkit_unittest_files': [
             'tests/ArenaTestHelpers.h',
             'tests/AssociatedURLLoaderTest.cpp',
+            'tests/CCDelayBasedTimeSourceTest.cpp',
+            'tests/CCFrameRateControllerTest.cpp',
             'tests/CCLayerImplTest.cpp',
             'tests/CCLayerSorterTest.cpp',
             'tests/CCLayerTreeHostCommonTest.cpp',
@@ -61,6 +63,7 @@
             'tests/CCLayerTreeHostTest.cpp',
             'tests/CCSchedulerTest.cpp',
             'tests/CCSchedulerStateMachineTest.cpp',
+            'tests/CCSchedulerTestCommon.h',
             'tests/CCThreadTaskTest.cpp',
             'tests/CCThreadTest.cpp',
             'tests/FrameTestHelpers.cpp',

Added: trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp (0 => 98700)


--- trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2011 Google 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 "cc/CCDelayBasedTimeSource.h"
+
+#include "CCSchedulerTestCommon.h"
+#include "cc/CCThread.h"
+#include <gtest/gtest.h>
+#include <wtf/RefPtr.h>
+
+using namespace WTF;
+using namespace WebCore;
+using namespace WebKitTests;
+
+namespace {
+
+TEST(CCDelayBasedTimeSourceTest, TaskPostedAndTickCalled)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+
+    timer->setMonotonicallyIncreasingTime(0);
+    timer->setActive(true);
+    EXPECT_TRUE(thread.hasPendingTask());
+
+    timer->setMonotonicallyIncreasingTime(16);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.tickCalled());
+}
+
+TEST(CCDelayBasedTimeSource, TickNotCalledWithTaskPosted)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+    timer->setActive(true);
+    EXPECT_TRUE(thread.hasPendingTask());
+    timer->setActive(false);
+    thread.runPendingTask();
+    EXPECT_FALSE(client.tickCalled());
+}
+
+TEST(CCDelayBasedTimeSource, StartTwiceEnqueuesOneTask)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+    timer->setActive(true);
+    EXPECT_TRUE(thread.hasPendingTask());
+    thread.reset();
+    timer->setActive(true);
+    EXPECT_FALSE(thread.hasPendingTask());
+}
+
+TEST(CCDelayBasedTimeSource, StartWhenRunningDoesntTick)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+    timer->setActive(true);
+    thread.runPendingTask();
+    thread.reset();
+    timer->setActive(true);
+    EXPECT_FALSE(thread.hasPendingTask());
+}
+
+TEST(CCDelayBasedTimeSourceTest, AchievesTargetRateWithNoNoise)
+{
+    int numIterations = 1000;
+
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+    timer->setActive(true);
+
+    double totalFrameTime = 0;
+    for (int i = 0; i < numIterations; ++i) {
+        long long delay = thread.pendingDelay();
+
+        // accumulate the "delay"
+        totalFrameTime += delay;
+
+        // Run the callback exactly when asked
+        double now = timer->monotonicallyIncreasingTime() + delay;
+        timer->setMonotonicallyIncreasingTime(now);
+        thread.runPendingTask();
+    }
+    double averageInterval = totalFrameTime / static_cast<double>(numIterations);
+    EXPECT_NEAR(1000.0 / 60.0, averageInterval, 0.1);
+}
+
+TEST(CCDelayBasedTimeSource, TestUnrefWhilePending)
+{
+    FakeCCThread thread;
+    FakeCCTimeSourceClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timer = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    timer->setClient(&client);
+    timer->setActive(true); // Should post a task.
+    timer->setActive(false);
+    timer.clear();
+    thread.runPendingTask(); // Should run the posted task, and delete the timer object.
+}
+
+}
Property changes on: trunk/Source/WebKit/chromium/tests/CCDelayBasedTimeSourceTest.cpp
___________________________________________________________________

Added: svn:eol-style

Added: trunk/Source/WebKit/chromium/tests/CCFrameRateControllerTest.cpp (0 => 98700)


--- trunk/Source/WebKit/chromium/tests/CCFrameRateControllerTest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCFrameRateControllerTest.cpp	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2011 Google 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 "cc/CCFrameRateController.h"
+
+#include "CCSchedulerTestCommon.h"
+#include <gtest/gtest.h>
+
+using namespace WTF;
+using namespace WebCore;
+using namespace WebKitTests;
+
+namespace {
+
+class FakeCCFrameRateControllerClient : public WebCore::CCFrameRateControllerClient {
+public:
+    FakeCCFrameRateControllerClient() { reset(); }
+
+    void reset() { m_frameBegun = false; }
+    bool frameBegun() const { return m_frameBegun; }
+
+    virtual void beginFrame() { m_frameBegun = true; }
+
+protected:
+    bool m_frameBegun;
+};
+
+
+TEST(CCFrameRateControllerTest, TestFrameThrottling_ImmediateAck)
+{
+    FakeCCThread thread;
+    FakeCCFrameRateControllerClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    CCFrameRateController controller(timeSource);
+
+    controller.setClient(&client);
+    controller.setActive(true);
+
+    double elapsed = 0; // Muck around with time a bit
+
+    // Trigger one frame, make sure the vsync callback is called
+    elapsed += thread.pendingDelay();
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.frameBegun());
+    client.reset();
+
+    // Tell the controller we drew
+    controller.didBeginFrame();
+
+    // Tell the controller the frame ended 5ms later
+    timeSource->setMonotonicallyIncreasingTime(timeSource->monotonicallyIncreasingTime() + 5);
+    controller.didFinishFrame();
+
+    // Trigger another frame, make sure vsync runs again
+    elapsed += thread.pendingDelay();
+    EXPECT_TRUE(elapsed >= timeSource->monotonicallyIncreasingTime()); // Sanity check that previous code didn't move time backward.
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.frameBegun());
+}
+
+TEST(CCFrameRateControllerTest, TestFrameThrottling_TwoFramesInFlight)
+{
+    // This test only works for the case of kMaxFramesPending = 2
+    ASSERT_EQ(2, CCFrameRateController::kMaxFramesPending);
+
+    FakeCCThread thread;
+    FakeCCFrameRateControllerClient client;
+    RefPtr<FakeCCDelayBasedTimeSource> timeSource = FakeCCDelayBasedTimeSource::create(1000.0 / 60.0, &thread);
+    CCFrameRateController controller(timeSource);
+
+    controller.setClient(&client);
+    controller.setActive(true);
+
+    double elapsed = 0; // Muck around with time a bit
+
+    // Trigger one frame, make sure the vsync callback is called
+    elapsed += thread.pendingDelay();
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.frameBegun());
+    client.reset();
+
+    // Tell the controller we drew
+    controller.didBeginFrame();
+
+    // Trigger another frame, make sure vsync callback runs again
+    elapsed += thread.pendingDelay();
+    EXPECT_TRUE(elapsed >= timeSource->monotonicallyIncreasingTime()); // Sanity check that previous code didn't move time backward.
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.frameBegun());
+    client.reset();
+
+    // Tell the controller we drew, again.
+    controller.didBeginFrame();
+
+    // Trigger another frame. Since two frames are pending, we should not draw.
+    elapsed += thread.pendingDelay();
+    EXPECT_TRUE(elapsed >= timeSource->monotonicallyIncreasingTime()); // Sanity check that previous code didn't move time backward.
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_FALSE(client.frameBegun());
+
+    // Tell the controller the first frame ended 5ms later
+    timeSource->setMonotonicallyIncreasingTime(timeSource->monotonicallyIncreasingTime() + 5);
+    controller.didFinishFrame();
+
+    // Tick should not have been called
+    EXPECT_FALSE(client.frameBegun());
+
+    // Trigger yet another frame. Since one frames is pending, another vsync callback should run.
+    elapsed += thread.pendingDelay();
+    EXPECT_TRUE(elapsed >= timeSource->monotonicallyIncreasingTime()); // Sanity check that previous code didn't move time backward.
+    timeSource->setMonotonicallyIncreasingTime(elapsed);
+    thread.runPendingTask();
+    EXPECT_TRUE(client.frameBegun());
+}
+
+}
Property changes on: trunk/Source/WebKit/chromium/tests/CCFrameRateControllerTest.cpp
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp (98699 => 98700)


--- trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp	2011-10-28 06:44:54 UTC (rev 98699)
+++ trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp	2011-10-28 06:50:19 UTC (rev 98700)
@@ -753,4 +753,3 @@
 }
 
 } // namespace
-

Added: trunk/Source/WebKit/chromium/tests/CCSchedulerTestCommon.h (0 => 98700)


--- trunk/Source/WebKit/chromium/tests/CCSchedulerTestCommon.h	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCSchedulerTestCommon.h	2011-10-28 06:50:19 UTC (rev 98700)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2011 Google 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 CCSchedulerTestCommon_h
+#define CCSchedulerTestCommon_h
+
+#include "cc/CCDelayBasedTimeSource.h"
+#include "cc/CCThread.h"
+#include <gtest/gtest.h>
+#include <wtf/OwnPtr.h>
+
+namespace WebKitTests {
+
+class FakeCCTimeSourceClient : public WebCore::CCTimeSourceClient {
+public:
+    FakeCCTimeSourceClient() { reset(); }
+    void reset() { m_tickCalled = false; }
+    bool tickCalled() const { return m_tickCalled; }
+
+    virtual void onTimerTick() { m_tickCalled = true; }
+
+protected:
+    bool m_tickCalled;
+};
+
+class FakeCCThread : public WebCore::CCThread {
+public:
+    FakeCCThread() { reset(); }
+    void reset()
+    {
+        m_pendingTaskDelay = 0;
+        m_pendingTask.clear();
+    }
+
+    bool hasPendingTask() const { return m_pendingTask; }
+    void runPendingTask()
+    {
+        ASSERT(m_pendingTask);
+        OwnPtr<Task> task = m_pendingTask.release();
+        task->performTask();
+    }
+
+    long long pendingDelay() const
+    {
+        EXPECT_TRUE(hasPendingTask());
+        return m_pendingTaskDelay;
+    }
+
+    virtual void postTask(PassOwnPtr<Task>) { ASSERT_NOT_REACHED(); }
+    virtual void postDelayedTask(PassOwnPtr<Task> task, long long delay)
+    {
+        EXPECT_TRUE(!hasPendingTask());
+        m_pendingTask = task;
+        m_pendingTaskDelay = delay;
+    }
+    virtual WTF::ThreadIdentifier threadID() const { ASSERT_NOT_REACHED(); return 0; }
+
+protected:
+    OwnPtr<Task> m_pendingTask;
+    long long m_pendingTaskDelay;
+};
+
+class FakeCCDelayBasedTimeSource : public WebCore::CCDelayBasedTimeSource {
+public:
+    static PassRefPtr<FakeCCDelayBasedTimeSource> create(double intervalMs, WebCore::CCThread* thread)
+    {
+        return adoptRef(new FakeCCDelayBasedTimeSource(intervalMs, thread));
+    }
+
+    void setMonotonicallyIncreasingTime(double time) { m_monotonicallyIncreasingTime = time; }
+    virtual double monotonicallyIncreasingTime() const { return m_monotonicallyIncreasingTime; }
+
+protected:
+    FakeCCDelayBasedTimeSource(double intervalMs, WebCore::CCThread* thread)
+        : CCDelayBasedTimeSource(intervalMs, thread)
+        , m_monotonicallyIncreasingTime(0) { }
+
+    double m_monotonicallyIncreasingTime;
+};
+
+}
+
+#endif // CCSchedulerTestCommon_h
Property changes on: trunk/Source/WebKit/chromium/tests/CCSchedulerTestCommon.h
___________________________________________________________________

Added: svn:eol-style

_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to