Remove extra line from unit_tests.isolate
[chromium-blink-merge.git] / cc / CCSchedulerStateMachine.h
blob092231f59c345d1fa0486a4202907abc812db69e
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CCSchedulerStateMachine_h
6 #define CCSchedulerStateMachine_h
8 #include <string>
10 #include "base/basictypes.h"
12 namespace cc {
14 // The CCSchedulerStateMachine decides how to coordinate main thread activites
15 // like painting/running javascript with rendering and input activities on the
16 // impl thread.
18 // The state machine tracks internal state but is also influenced by external state.
19 // Internal state includes things like whether a frame has been requested, while
20 // external state includes things like the current time being near to the vblank time.
22 // The scheduler seperates "what to do next" from the updating of its internal state to
23 // make testing cleaner.
24 class CCSchedulerStateMachine {
25 public:
26 CCSchedulerStateMachine();
28 enum CommitState {
29 COMMIT_STATE_IDLE,
30 COMMIT_STATE_FRAME_IN_PROGRESS,
31 COMMIT_STATE_READY_TO_COMMIT,
32 COMMIT_STATE_WAITING_FOR_FIRST_DRAW,
35 enum TextureState {
36 LAYER_TEXTURE_STATE_UNLOCKED,
37 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD,
38 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD,
41 enum ContextState {
42 CONTEXT_ACTIVE,
43 CONTEXT_LOST,
44 CONTEXT_RECREATING,
47 bool commitPending() const
49 return m_commitState != COMMIT_STATE_IDLE;
52 bool redrawPending() const { return m_needsRedraw; }
54 enum Action {
55 ACTION_NONE,
56 ACTION_BEGIN_FRAME,
57 ACTION_COMMIT,
58 ACTION_DRAW_IF_POSSIBLE,
59 ACTION_DRAW_FORCED,
60 ACTION_BEGIN_CONTEXT_RECREATION,
61 ACTION_ACQUIRE_LAYER_TEXTURES_FOR_MAIN_THREAD,
63 Action nextAction() const;
64 void updateState(Action);
66 // Indicates whether the scheduler needs a vsync callback in order to make
67 // progress.
68 bool vsyncCallbackNeeded() const;
70 // Indicates that the system has entered and left a vsync callback.
71 // The scheduler will not draw more than once in a given vsync callback.
72 void didEnterVSync();
73 void didLeaveVSync();
75 // Indicates whether the LayerTreeHostImpl is visible.
76 void setVisible(bool);
78 // Indicates that a redraw is required, either due to the impl tree changing
79 // or the screen being damaged and simply needing redisplay.
80 void setNeedsRedraw();
82 // As setNeedsRedraw(), but ensures the draw will definitely happen even if
83 // we are not visible.
84 void setNeedsForcedRedraw();
86 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not.
87 void didDrawIfPossibleCompleted(bool success);
89 // Indicates that a new commit flow needs to be performed, either to pull
90 // updates from the main thread to the impl, or to push deltas from the impl
91 // thread to main.
92 void setNeedsCommit();
94 // As setNeedsCommit(), but ensures the beginFrame will definitely happen even if
95 // we are not visible.
96 void setNeedsForcedCommit();
98 // Call this only in response to receiving an ACTION_BEGIN_FRAME
99 // from nextState. Indicates that all painting is complete.
100 void beginFrameComplete();
102 // Call this only in response to receiving an ACTION_BEGIN_FRAME
103 // from nextState if the client rejects the beginFrame message.
104 void beginFrameAborted();
106 // Request exclusive access to the textures that back single buffered
107 // layers on behalf of the main thread. Upon acqusition,
108 // ACTION_DRAW_IF_POSSIBLE will not draw until the main thread releases the
109 // textures to the impl thread by committing the layers.
110 void setMainThreadNeedsLayerTextures();
112 // Indicates whether we can successfully begin a frame at this time.
113 void setCanBeginFrame(bool can) { m_canBeginFrame = can; }
115 // Indicates whether drawing would, at this time, make sense.
116 // canDraw can be used to supress flashes or checkerboarding
117 // when such behavior would be undesirable.
118 void setCanDraw(bool can) { m_canDraw = can; }
120 void didLoseContext();
121 void didRecreateContext();
123 // Exposed for testing purposes.
124 void setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int);
126 std::string toString();
128 protected:
129 bool shouldDrawForced() const;
130 bool drawSuspendedUntilCommit() const;
131 bool scheduledToDraw() const;
132 bool shouldDraw() const;
133 bool shouldAcquireLayerTexturesForMainThread() const;
134 bool hasDrawnThisFrame() const;
136 CommitState m_commitState;
138 int m_currentFrameNumber;
139 int m_lastFrameNumberWhereDrawWasCalled;
140 int m_consecutiveFailedDraws;
141 int m_maximumNumberOfFailedDrawsBeforeDrawIsForced;
142 bool m_needsRedraw;
143 bool m_needsForcedRedraw;
144 bool m_needsForcedRedrawAfterNextCommit;
145 bool m_needsCommit;
146 bool m_needsForcedCommit;
147 bool m_mainThreadNeedsLayerTextures;
148 bool m_insideVSync;
149 bool m_visible;
150 bool m_canBeginFrame;
151 bool m_canDraw;
152 bool m_drawIfPossibleFailed;
153 TextureState m_textureState;
154 ContextState m_contextState;
156 DISALLOW_COPY_AND_ASSIGN(CCSchedulerStateMachine);
161 #endif // CCSchedulerStateMachine_h