Title: [104199] trunk/Source
Revision
104199
Author
[email protected]
Date
2012-01-05 12:53:18 -0800 (Thu, 05 Jan 2012)

Log Message

[chromium] Add CCTimer class for the compositor
https://bugs.webkit.org/show_bug.cgi?id=74769

Patch by Tien Ren Chen <[email protected]> on 2012-01-05
Reviewed by James Robinson.

Add a simple timer class for CCThread that the timered task can be
manually cancelled.

Source/WebCore:

* WebCore.gypi:
* platform/graphics/chromium/cc/CCTimer.cpp: Added.
(WebCore::CCTimerTask::CCTimerTask):
(WebCore::CCTimerTask::~CCTimerTask):
(WebCore::CCTimerTask::performTask):
(WebCore::CCTimer::CCTimer):
(WebCore::CCTimer::~CCTimer):
(WebCore::CCTimer::startOneShot):
(WebCore::CCTimer::stop):
* platform/graphics/chromium/cc/CCTimer.h: Added.
(WebCore::CCTimerClient::~CCTimerClient):
(WebCore::CCTimer::isActive):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/CCTimerTest.cpp: Added.
(WebKitTests::CCTimerTest::CCTimerTest):
(WebKitTests::CCTimerTest::onTimerFired):
(WebKitTests::TEST_F):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (104198 => 104199)


--- trunk/Source/WebCore/ChangeLog	2012-01-05 20:48:17 UTC (rev 104198)
+++ trunk/Source/WebCore/ChangeLog	2012-01-05 20:53:18 UTC (rev 104199)
@@ -1,3 +1,26 @@
+2012-01-05  Tien Ren Chen  <[email protected]>
+
+        [chromium] Add CCTimer class for the compositor
+        https://bugs.webkit.org/show_bug.cgi?id=74769
+
+        Reviewed by James Robinson.
+
+        Add a simple timer class for CCThread that the timered task can be
+        manually cancelled.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/cc/CCTimer.cpp: Added.
+        (WebCore::CCTimerTask::CCTimerTask):
+        (WebCore::CCTimerTask::~CCTimerTask):
+        (WebCore::CCTimerTask::performTask):
+        (WebCore::CCTimer::CCTimer):
+        (WebCore::CCTimer::~CCTimer):
+        (WebCore::CCTimer::startOneShot):
+        (WebCore::CCTimer::stop):
+        * platform/graphics/chromium/cc/CCTimer.h: Added.
+        (WebCore::CCTimerClient::~CCTimerClient):
+        (WebCore::CCTimer::isActive):
+
 2012-01-05  Eric Carlson  <[email protected]>
 
         Implement temporal dimension portion of Media Fragments URI specification for video/audio

Modified: trunk/Source/WebCore/WebCore.gypi (104198 => 104199)


--- trunk/Source/WebCore/WebCore.gypi	2012-01-05 20:48:17 UTC (rev 104198)
+++ trunk/Source/WebCore/WebCore.gypi	2012-01-05 20:53:18 UTC (rev 104199)
@@ -3658,6 +3658,8 @@
             'platform/graphics/chromium/cc/CCThreadTask.h',
             'platform/graphics/chromium/cc/CCTiledLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCTiledLayerImpl.h',
+            'platform/graphics/chromium/cc/CCTimer.cpp',
+            'platform/graphics/chromium/cc/CCTimer.h',
             'platform/graphics/chromium/cc/CCTimeSource.h',
             'platform/graphics/chromium/cc/CCVideoLayerImpl.cpp',
             'platform/graphics/chromium/cc/CCVideoLayerImpl.h',

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


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.cpp	2012-01-05 20:53:18 UTC (rev 104199)
@@ -0,0 +1,96 @@
+/*
+ * 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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 "cc/CCTimer.h"
+
+namespace WebCore {
+
+class CCTimerTask : public CCThread::Task {
+public:
+    explicit CCTimerTask(CCTimer* timer)
+        : CCThread::Task(0)
+        , m_timer(timer)
+    {
+    }
+
+    ~CCTimerTask()
+    {
+        if (!m_timer)
+            return;
+
+        ASSERT(m_timer->m_task == this);
+        m_timer->stop();
+    }
+
+    void performTask()
+    {
+        if (!m_timer || !m_timer->m_client)
+            return;
+
+        m_timer->m_client->onTimerFired();
+    }
+
+private:
+    friend class CCTimer;
+
+    CCTimer* m_timer; // null if cancelled
+};
+
+CCTimer::CCTimer(CCThread* thread, CCTimerClient* client)
+    : m_client(client)
+    , m_thread(thread)
+    , m_task(0)
+{
+}
+
+CCTimer::~CCTimer()
+{
+    stop();
+}
+
+void CCTimer::startOneShot(double intervalMs)
+{
+    stop();
+
+    m_task = new CCTimerTask(this);
+    m_thread->postDelayedTask(adoptPtr(m_task), intervalMs);
+}
+
+void CCTimer::stop()
+{
+    if (!m_task)
+        return;
+
+    m_task->m_timer = 0;
+    m_task = 0;
+}
+
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.cpp
___________________________________________________________________

Added: svn:eol-style

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


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.h	2012-01-05 20:53:18 UTC (rev 104199)
@@ -0,0 +1,68 @@
+/*
+ * 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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 CCTimer_h
+#define CCTimer_h
+
+#include "cc/CCThread.h"
+
+namespace WebCore {
+
+class CCTimerTask;
+
+class CCTimerClient {
+public:
+    virtual ~CCTimerClient() { }
+
+    virtual void onTimerFired() = 0;
+};
+
+class CCTimer {
+public:
+    CCTimer(CCThread*, CCTimerClient*);
+    ~CCTimer();
+
+    // If a previous task is pending, it will be replaced with the new one.
+    void startOneShot(double intervalMs);
+    void stop();
+
+    bool isActive() const { return m_task; }
+
+private:
+    friend class CCTimerTask;
+
+    CCTimerClient* m_client;
+    CCThread* m_thread;
+    CCTimerTask* m_task; // weak pointer
+};
+
+} // namespace WebCore
+
+#endif
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCTimer.h
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebKit/chromium/ChangeLog (104198 => 104199)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-01-05 20:48:17 UTC (rev 104198)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-01-05 20:53:18 UTC (rev 104199)
@@ -1,3 +1,19 @@
+2012-01-05  Tien Ren Chen  <[email protected]>
+
+        [chromium] Add CCTimer class for the compositor
+        https://bugs.webkit.org/show_bug.cgi?id=74769
+
+        Reviewed by James Robinson.
+
+        Add a simple timer class for CCThread that the timered task can be
+        manually cancelled.
+
+        * WebKit.gypi:
+        * tests/CCTimerTest.cpp: Added.
+        (WebKitTests::CCTimerTest::CCTimerTest):
+        (WebKitTests::CCTimerTest::onTimerFired):
+        (WebKitTests::TEST_F):
+
 2012-01-04  Adrienne Walker  <[email protected]>
 
         [chromium] Create unit tests for CCTiledLayerImpl

Modified: trunk/Source/WebKit/chromium/WebKit.gypi (104198 => 104199)


--- trunk/Source/WebKit/chromium/WebKit.gypi	2012-01-05 20:48:17 UTC (rev 104198)
+++ trunk/Source/WebKit/chromium/WebKit.gypi	2012-01-05 20:53:18 UTC (rev 104199)
@@ -76,6 +76,7 @@
             'tests/CCSchedulerTest.cpp',
             'tests/CCTiledLayerImplTest.cpp',
             'tests/CCThreadTaskTest.cpp',
+            'tests/CCTimerTest.cpp',
             'tests/CompositorFakeGraphicsContext3D.h',
             'tests/CompositorFakeWebGraphicsContext3D.h',
             'tests/FakeGraphicsContext3DTest.cpp',

Added: trunk/Source/WebKit/chromium/tests/CCTimerTest.cpp (0 => 104199)


--- trunk/Source/WebKit/chromium/tests/CCTimerTest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCTimerTest.cpp	2012-01-05 20:53:18 UTC (rev 104199)
@@ -0,0 +1,86 @@
+/*
+ * 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER 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 "cc/CCTimer.h"
+
+#include "CCSchedulerTestCommon.h"
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+using namespace WebKitTests;
+
+namespace {
+
+class CCTimerTest : public testing::Test, public CCTimerClient {
+public:
+    CCTimerTest() : m_flag(false) { }
+
+    void onTimerFired() { m_flag = true; }
+
+protected:
+    FakeCCThread m_thread;
+    bool m_flag;
+};
+
+TEST_F(CCTimerTest, OneShot)
+{
+    CCTimer timer(&m_thread, this);
+    timer.startOneShot(1);
+
+    m_thread.runPendingTask();
+    EXPECT_TRUE(m_flag);
+    EXPECT_FALSE(m_thread.hasPendingTask());
+}
+
+TEST_F(CCTimerTest, StopManually)
+{
+    CCTimer timer(&m_thread, this);
+    timer.startOneShot(1);
+    timer.stop();
+
+    m_thread.runPendingTask();
+    EXPECT_FALSE(m_flag);
+    EXPECT_FALSE(m_thread.hasPendingTask());
+}
+
+TEST_F(CCTimerTest, StopByScope)
+{
+    {
+        CCTimer timer(&m_thread, this);
+        timer.startOneShot(1);
+    }
+
+    m_thread.runPendingTask();
+    EXPECT_FALSE(m_flag);
+}
+
+}
Property changes on: trunk/Source/WebKit/chromium/tests/CCTimerTest.cpp
___________________________________________________________________

Added: svn:eol-style

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

Reply via email to