Title: [98612] trunk/Source
Revision
98612
Author
nd...@chromium.org
Date
2011-10-27 11:29:40 -0700 (Thu, 27 Oct 2011)

Log Message

[chromium] Encapsulate state machine parts of scheduling in CCSchedulerStateMachine
https://bugs.webkit.org/show_bug.cgi?id=70714

Reviewed by James Robinson.

Source/WebCore:

* WebCore.gypi:
* platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp: Added.
(WebCore::CCSchedulerStateMachine::nextAction):
(WebCore::CCSchedulerStateMachine::updateState):
* platform/graphics/chromium/cc/CCSchedulerStateMachine.h: Added.
(WebCore::CCSchedulerStateMachine::CCSchedulerStateMachine):
(WebCore::CCSchedulerStateMachine::operator=):
(WebCore::CCSchedulerStateMachine::commitPending):
(WebCore::CCSchedulerStateMachine::setNeedsRedraw):
(WebCore::CCSchedulerStateMachine::setNeedsCommit):
(WebCore::CCSchedulerStateMachine::beginFrameComplete):
(WebCore::CCSchedulerStateMachine::updateResourcesComplete):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/CCSchedulerStateMachineTest.cpp: Added.
(WebCore::StateMachine::setCommitState):
(WebCore::StateMachine::commitState):
(WebCore::StateMachine::setNeedsCommit):
(WebCore::StateMachine::needsCommit):
(WebCore::StateMachine::setNeedsRedraw):
(WebCore::StateMachine::needsRedraw):
(WebCore::StateMachine::setUpdatedThisFrame):
(WebCore::StateMachine::updatedThisFrame):
(WebCore::TEST):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (98611 => 98612)


--- trunk/Source/WebCore/ChangeLog	2011-10-27 18:27:23 UTC (rev 98611)
+++ trunk/Source/WebCore/ChangeLog	2011-10-27 18:29:40 UTC (rev 98612)
@@ -1,3 +1,23 @@
+2011-10-24  Nat Duca  <nd...@chromium.org>
+
+        [chromium] Encapsulate state machine parts of scheduling in CCSchedulerStateMachine
+        https://bugs.webkit.org/show_bug.cgi?id=70714
+
+        Reviewed by James Robinson.
+
+        * WebCore.gypi:
+        * platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp: Added.
+        (WebCore::CCSchedulerStateMachine::nextAction):
+        (WebCore::CCSchedulerStateMachine::updateState):
+        * platform/graphics/chromium/cc/CCSchedulerStateMachine.h: Added.
+        (WebCore::CCSchedulerStateMachine::CCSchedulerStateMachine):
+        (WebCore::CCSchedulerStateMachine::operator=):
+        (WebCore::CCSchedulerStateMachine::commitPending):
+        (WebCore::CCSchedulerStateMachine::setNeedsRedraw):
+        (WebCore::CCSchedulerStateMachine::setNeedsCommit):
+        (WebCore::CCSchedulerStateMachine::beginFrameComplete):
+        (WebCore::CCSchedulerStateMachine::updateResourcesComplete):
+
 2011-10-27  Dan Bernstein  <m...@apple.com>
 
         <rdar://problem/10262205> Allow column progression to be independent of writing mode

Modified: trunk/Source/WebCore/WebCore.gypi (98611 => 98612)


--- trunk/Source/WebCore/WebCore.gypi	2011-10-27 18:27:23 UTC (rev 98611)
+++ trunk/Source/WebCore/WebCore.gypi	2011-10-27 18:29:40 UTC (rev 98612)
@@ -3560,6 +3560,8 @@
             'platform/graphics/chromium/cc/CCRenderSurface.h',
             'platform/graphics/chromium/cc/CCScheduler.cpp',
             'platform/graphics/chromium/cc/CCScheduler.h',
+            'platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp',
+            'platform/graphics/chromium/cc/CCSchedulerStateMachine.h',
             'platform/graphics/chromium/cc/CCScopedMainThreadProxy.h',
             'platform/graphics/chromium/cc/CCScrollController.h',
             'platform/graphics/chromium/cc/CCSingleThreadProxy.cpp',

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


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp	2011-10-27 18:29:40 UTC (rev 98612)
@@ -0,0 +1,134 @@
+/*
+ * 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/CCSchedulerStateMachine.h"
+
+namespace WebCore {
+
+CCSchedulerStateMachine::CCSchedulerStateMachine()
+    : m_commitState(COMMIT_STATE_IDLE)
+    , m_needsRedraw(false)
+    , m_needsCommit(false)
+    , m_updatedThisFrame(false) { }
+
+CCSchedulerStateMachine::CCSchedulerStateMachine(const CCSchedulerStateMachine& that)
+{
+    *this = that;
+}
+
+CCSchedulerStateMachine::CCSchedulerStateMachine& operator=(const CCSchedulerStateMachine& that)
+{
+    m_commitState = that.m_commitState;
+    m_needsRedraw = that.m_needsRedraw;
+    m_needsCommit = that.m_needsCommit;
+    m_updatedThisFrame = that.m_updatedThisFrame;
+    return *this;
+}
+
+CCSchedulerStateMachine::Action CCSchedulerStateMachine::nextAction(bool insideVSyncTick) const
+{
+    switch (m_commitState) {
+    case COMMIT_STATE_IDLE:
+        if (m_needsRedraw && insideVSyncTick)
+            return ACTION_DRAW;
+        if (m_needsCommit)
+            return ACTION_BEGIN_FRAME;
+        return ACTION_NONE;
+
+    case COMMIT_STATE_FRAME_IN_PROGRESS:
+        if (m_needsRedraw && insideVSyncTick)
+            return ACTION_DRAW;
+        return ACTION_NONE;
+
+    case COMMIT_STATE_UPDATING_RESOURCES:
+        if (m_needsRedraw && insideVSyncTick)
+            return ACTION_DRAW;
+        if (!m_updatedThisFrame)
+            return ACTION_UPDATE_MORE_RESOURCES;
+        return ACTION_NONE;
+
+    case COMMIT_STATE_READY_TO_COMMIT:
+        return ACTION_COMMIT;
+    }
+}
+
+void CCSchedulerStateMachine::updateState(Action action)
+{
+    switch (action) {
+    case ACTION_NONE:
+        return;
+
+    case ACTION_BEGIN_FRAME:
+        m_commitState = COMMIT_STATE_FRAME_IN_PROGRESS;
+        m_needsCommit = false;
+        return;
+
+    case ACTION_UPDATE_MORE_RESOURCES:
+        ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES);
+        // getNextState() in COMMIT_STATE_UPDATING_RESOURCES will only return
+        // ACTION_UPDATE_MORE_RESOURCES when m_updatedThisFrame is true. Here,
+        // set m_updatedThisFrame to true to prevent additional
+        // ACTION_UPDATE_MORE_RESOURCES from being issued.
+        // This will then be cleared by a draw action, effectively limiting us
+        // to one ACTION_UPDATE_MORE_RESOURCES per frame.
+        m_updatedThisFrame = true;
+        return;
+
+    case ACTION_COMMIT:
+        m_commitState = COMMIT_STATE_IDLE;
+        m_needsRedraw = true;
+        return;
+
+    case ACTION_DRAW:
+        m_updatedThisFrame = false;
+        m_needsRedraw = false;
+        return;
+    }
+}
+
+void CCSchedulerStateMachine::setNeedsRedraw()
+{
+    m_needsRedraw = true;
+}
+
+void CCSchedulerStateMachine::setNeedsCommit()
+{
+    m_needsCommit = true;
+}
+
+void CCSchedulerStateMachine::beginFrameComplete()
+{
+    ASSERT(m_commitState == COMMIT_STATE_FRAME_IN_PROGRESS);
+    m_commitState = COMMIT_STATE_UPDATING_RESOURCES;
+}
+
+void CCSchedulerStateMachine::updateResourcesComplete()
+{
+    ASSERT(m_commitState == COMMIT_STATE_UPDATING_RESOURCES);
+    m_commitState = COMMIT_STATE_READY_TO_COMMIT;
+}
+
+}
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.cpp
___________________________________________________________________

Added: svn:eol-style

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


--- trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.h	2011-10-27 18:29:40 UTC (rev 98612)
@@ -0,0 +1,97 @@
+/*
+ * 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 CCSchedulerStateMachine_h
+#define CCSchedulerStateMachine_h
+
+namespace WebCore {
+
+// The CCSchedulerStateMachine decides how to coordinates main thread activites
+// like painting/running _javascript_ with rendering and input activities on the
+// impl thread.
+//
+// The state machine tracks internal state but is also influenced by external state.
+// Internal state includes things like whether a frame has been requested, while
+// external state includes things like the current time being near to the vblank time.
+//
+// The scheduler seperates "what to do next" from the updating of its internal state to
+// make testing cleaner.
+class CCSchedulerStateMachine {
+public:
+    CCSchedulerStateMachine();
+    CCSchedulerStateMachine(const CCSchedulerStateMachine& that);
+    CCSchedulerStateMachine& operator=(const CCSchedulerStateMachine& that);
+
+    enum CommitState {
+        COMMIT_STATE_IDLE,
+        COMMIT_STATE_FRAME_IN_PROGRESS,
+        COMMIT_STATE_UPDATING_RESOURCES,
+        COMMIT_STATE_READY_TO_COMMIT,
+    };
+
+    bool commitPending() const
+    {
+        return m_commitState != COMMIT_STATE_IDLE;
+    }
+
+    enum Action {
+        ACTION_NONE,
+        ACTION_BEGIN_FRAME,
+        ACTION_UPDATE_MORE_RESOURCES,
+        ACTION_COMMIT,
+        ACTION_DRAW,
+    };
+    Action nextAction(bool insideVSyncTick) const;
+    void updateState(Action);
+
+    // Indicates that a redraw is required, either due to the impl tree changing
+    // or the screen being damaged and simply needing redisplay.
+    void setNeedsRedraw();
+
+    // Indicates that a new commit flow needs to be performed, either to pull
+    // updates from the main thread to the impl, or to push deltas from the impl
+    // thread to main.
+    void setNeedsCommit();
+
+    // Call this only in response to receiving an ACTION_BEGIN_FRAME
+    // from nextState. Indicates that all painting is complete and that
+    // updating of compositor resources can begin.
+    void beginFrameComplete();
+
+    // Call this only in response to receiving an ACTION_UPDATE_MORE_RESOURCES
+    // from nextState. Indicatest that all resouces have been updated and that
+    // the main thread tree can be committed to the impl tree.
+    void updateResourcesComplete();
+
+protected:
+    CommitState m_commitState;
+
+    bool m_needsRedraw;
+    bool m_needsCommit;
+    bool m_updatedThisFrame;
+};
+
+}
+
+#endif // CCSchedulerStateMachine_h
Property changes on: trunk/Source/WebCore/platform/graphics/chromium/cc/CCSchedulerStateMachine.h
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebKit/chromium/ChangeLog (98611 => 98612)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-10-27 18:27:23 UTC (rev 98611)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-10-27 18:29:40 UTC (rev 98612)
@@ -1,3 +1,22 @@
+2011-10-24  Nat Duca  <nd...@chromium.org>
+
+        [chromium] Encapsulate state machine parts of scheduling in CCSchedulerStateMachine
+        https://bugs.webkit.org/show_bug.cgi?id=70714
+
+        Reviewed by James Robinson.
+
+        * WebKit.gypi:
+        * tests/CCSchedulerStateMachineTest.cpp: Added.
+        (WebCore::StateMachine::setCommitState):
+        (WebCore::StateMachine::commitState):
+        (WebCore::StateMachine::setNeedsCommit):
+        (WebCore::StateMachine::needsCommit):
+        (WebCore::StateMachine::setNeedsRedraw):
+        (WebCore::StateMachine::needsRedraw):
+        (WebCore::StateMachine::setUpdatedThisFrame):
+        (WebCore::StateMachine::updatedThisFrame):
+        (WebCore::TEST):
+
 2011-10-27  Dave Michael  <dmich...@chromium.org>
 
         Chromium ui_tests WorkerTest.WorkerMessagePort[GC] were broken by https://bugs.webkit.org/attachment.cgi?id=112342

Modified: trunk/Source/WebKit/chromium/WebKit.gypi (98611 => 98612)


--- trunk/Source/WebKit/chromium/WebKit.gypi	2011-10-27 18:27:23 UTC (rev 98611)
+++ trunk/Source/WebKit/chromium/WebKit.gypi	2011-10-27 18:29:40 UTC (rev 98612)
@@ -59,6 +59,7 @@
             'tests/CCLayerTreeHostImplTest.cpp',
             'tests/CCLayerTreeHostTest.cpp',
             'tests/CCSchedulerTest.cpp',
+            'tests/CCSchedulerStateMachineTest.cpp',
             'tests/CCThreadTaskTest.cpp',
             'tests/CCThreadTest.cpp',
             'tests/FrameTestHelpers.cpp',

Added: trunk/Source/WebKit/chromium/tests/CCSchedulerStateMachineTest.cpp (0 => 98612)


--- trunk/Source/WebKit/chromium/tests/CCSchedulerStateMachineTest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/CCSchedulerStateMachineTest.cpp	2011-10-27 18:29:40 UTC (rev 98612)
@@ -0,0 +1,261 @@
+/*
+ * 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/CCSchedulerStateMachine.h"
+
+#include <gtest/gtest.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
+
+using namespace WTF;
+using namespace WebCore;
+
+namespace {
+
+const CCSchedulerStateMachine::CommitState allCommitStates[] = {
+    CCSchedulerStateMachine::COMMIT_STATE_IDLE,
+    CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS,
+    CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES,
+    CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT
+};
+
+// Exposes the protected state fields of the CCSchedulerStateMachine for testing
+class StateMachine : public CCSchedulerStateMachine {
+public:
+    void setCommitState(CommitState cs) { m_commitState = cs; }
+    CommitState commitState() const { return  m_commitState; }
+
+    void setNeedsCommit(bool b) { m_needsCommit = b; }
+    bool needsCommit() const { return m_needsCommit; }
+
+    void setNeedsRedraw(bool b) { m_needsRedraw = b; }
+    bool needsRedraw() const { return m_needsRedraw; }
+
+    void setUpdatedThisFrame(bool b) { m_updatedThisFrame = b; }
+    bool updatedThisFrame() const { return m_updatedThisFrame; }
+};
+
+TEST(CCSchedulerStateMachineTest, TestNextActionBeginsFrameIfNeeded)
+{
+    StateMachine state;
+    // If no commit needed, do nothing
+    state = StateMachine();
+    state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE);
+    state.setNeedsRedraw(false);
+    state.setNeedsCommit(false);
+    state.setUpdatedThisFrame(false);
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(true));
+
+    // If commit requested, begin a frame
+    state = StateMachine();
+    state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_IDLE);
+    state.setNeedsRedraw(false);
+    state.setNeedsCommit(true);
+    state.setUpdatedThisFrame(false);
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction(false));
+
+    // Begin the frame, make sure needsCommit and commitState update correctly.
+    state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME);
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState());
+    EXPECT_FALSE(state.needsCommit());
+}
+
+TEST(CCSchedulerStateMachineTest, TestNextActionDrawsOnVSync)
+{
+    // When not on vsync, don't draw.
+    size_t numCommitStates = sizeof(allCommitStates) / sizeof(CCSchedulerStateMachine::CommitState);
+    for (size_t i = 0; i < numCommitStates; ++i) {
+        StateMachine state;
+        state.setCommitState(allCommitStates[i]);
+        state.setNeedsRedraw(true);
+
+        // Case 1: needsCommit=false updatedThisFrame=false vsync=false.
+        state.setNeedsCommit(false);
+        state.setUpdatedThisFrame(false);
+        EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(false));
+
+        // Case 2: needsCommit=false updatedThisFrame=true vsync=false.
+        state.setNeedsCommit(false);
+        state.setUpdatedThisFrame(true);
+        EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(false));
+
+        // Case 3: needsCommit=true updatedThisFrame=false vsync=false.
+        state.setNeedsCommit(true);
+        state.setUpdatedThisFrame(false);
+        EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(false));
+
+        // Case 4: needsCommit=true updatedThisFrame=true vsync=false.
+        state.setNeedsCommit(true);
+        state.setUpdatedThisFrame(true);
+        EXPECT_NE(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(false));
+    }
+
+    // When on vsync, you should always draw. Expect if you're ready to commit, in which case commit.
+    for (size_t i = 0; i < numCommitStates; ++i) {
+        StateMachine state;
+        state.setCommitState(allCommitStates[i]);
+        state.setNeedsRedraw(true);
+        CCSchedulerStateMachine::Action expectedAction;
+        if (allCommitStates[i] != CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT)
+            expectedAction = CCSchedulerStateMachine::ACTION_DRAW;
+        else
+            expectedAction = CCSchedulerStateMachine::ACTION_COMMIT;
+
+        // Case 1: needsCommit=false updatedThisFrame=false vsync=true.
+        state.setNeedsCommit(false);
+        state.setUpdatedThisFrame(false);
+        EXPECT_EQ(expectedAction, state.nextAction(true));
+
+        // Case 2: needsCommit=false updatedThisFrame=true vsync=true.
+        state.setNeedsCommit(false);
+        state.setUpdatedThisFrame(true);
+        EXPECT_EQ(expectedAction, state.nextAction(true));
+
+        // Case 3: needsCommit=true updatedThisFrame=false vsync=true.
+        state.setNeedsCommit(true);
+        state.setUpdatedThisFrame(false);
+        EXPECT_EQ(expectedAction, state.nextAction(true));
+
+        // Case 4: needsCommit=true updatedThisFrame=true vsync=true.
+        state.setNeedsCommit(true);
+        state.setUpdatedThisFrame(true);
+        EXPECT_EQ(expectedAction, state.nextAction(true));
+    }
+}
+
+TEST(CCSchedulerStateMachineTest, TestUpdatesResourcesOncePerFrame)
+{
+    // When no redraw is needed --- update until done
+    {
+        StateMachine state;
+        state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES);
+        state.setNeedsRedraw(false);
+        state.setUpdatedThisFrame(false);
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(false));
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(true));
+    }
+
+    // Once we update resources, don't do it again until a draw
+    {
+        StateMachine state;
+        state.setCommitState(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES);
+        state.setNeedsRedraw(true);
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(false));
+        state.updateState(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES);
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+
+        // once we've drawn again, it should allow us to update (regardless of vsync state)
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(true));
+        state.updateState(CCSchedulerStateMachine::ACTION_DRAW);
+
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(true));
+        EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(false));
+    }
+}
+
+TEST(CCSchedulerStateMachineTest, TestSetNeedsCommitIsNotLost)
+{
+    StateMachine state;
+    state.setNeedsCommit(true);
+
+    // Begin the frame.
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction(false));
+    state.updateState(state.nextAction(false));
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState());
+
+    // Now, while the frame is in progress, set another commit.
+    state.setNeedsCommit(true);
+    EXPECT_TRUE(state.needsCommit());
+
+    // Let the frame finish.
+    state.beginFrameComplete();
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.commitState());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(false));
+    state.updateState(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES);
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+    state.updateResourcesComplete();
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction(false));
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction(true));
+    state.updateState(CCSchedulerStateMachine::ACTION_COMMIT);
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
+
+    // verify that another commit will begin
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction(false));
+}
+
+TEST(CCSchedulerStateMachineTest, TestFullCycle)
+{
+    StateMachine state;
+
+    // Start clean and set commit.
+    state.setNeedsCommit(true);
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_BEGIN_FRAME, state.nextAction(false));
+
+    // Begin the frame.
+    state.updateState(CCSchedulerStateMachine::ACTION_BEGIN_FRAME);
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_FRAME_IN_PROGRESS, state.commitState());
+    EXPECT_FALSE(state.needsCommit());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+
+    // Tell the scheduler the frame finished.
+    state.beginFrameComplete();
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_UPDATING_RESOURCES, state.commitState());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_UPDATE_MORE_RESOURCES, state.nextAction(false));
+
+    // Tell the scheduler the update is done.
+    state.updateResourcesComplete();
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_READY_TO_COMMIT, state.commitState());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_COMMIT, state.nextAction(false));
+
+    // Commit.
+    state.updateState(CCSchedulerStateMachine::ACTION_COMMIT);
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
+    EXPECT_TRUE(state.needsRedraw());
+
+    // Expect to do nothing until vsync.
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+
+    // At vsync, draw.
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_DRAW, state.nextAction(true));
+    state.updateState(CCSchedulerStateMachine::ACTION_DRAW);
+
+    // Should be synchronized, no draw needed, no action needed.
+    EXPECT_EQ(CCSchedulerStateMachine::COMMIT_STATE_IDLE, state.commitState());
+    EXPECT_FALSE(state.needsRedraw());
+    EXPECT_EQ(CCSchedulerStateMachine::ACTION_NONE, state.nextAction(false));
+}
+
+TEST(CCSchedulerStateMachineTest, TestFullCycleWithCommitRequestInbetween)
+{
+}
+
+TEST(CCSchedulerStateMachineTest, TestFullCycleWithRedrawInbetween)
+{
+}
+
+}
Property changes on: trunk/Source/WebKit/chromium/tests/CCSchedulerStateMachineTest.cpp
___________________________________________________________________

Added: svn:eol-style

_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to