OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CCSchedulerStateMachine_h | 5 // Temporary forwarding header |
6 #define CCSchedulerStateMachine_h | 6 #include "cc/scheduler_state_machine.h" |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 | |
12 namespace cc { | |
13 | |
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. | |
17 // | |
18 // The state machine tracks internal state but is also influenced by external st
ate. | |
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. | |
21 // | |
22 // The scheduler seperates "what to do next" from the updating of its internal s
tate to | |
23 // make testing cleaner. | |
24 class CCSchedulerStateMachine { | |
25 public: | |
26 CCSchedulerStateMachine(); | |
27 | |
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, | |
33 }; | |
34 | |
35 enum TextureState { | |
36 LAYER_TEXTURE_STATE_UNLOCKED, | |
37 LAYER_TEXTURE_STATE_ACQUIRED_BY_MAIN_THREAD, | |
38 LAYER_TEXTURE_STATE_ACQUIRED_BY_IMPL_THREAD, | |
39 }; | |
40 | |
41 enum ContextState { | |
42 CONTEXT_ACTIVE, | |
43 CONTEXT_LOST, | |
44 CONTEXT_RECREATING, | |
45 }; | |
46 | |
47 bool commitPending() const | |
48 { | |
49 return m_commitState != COMMIT_STATE_IDLE; | |
50 } | |
51 | |
52 bool redrawPending() const { return m_needsRedraw; } | |
53 | |
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, | |
62 }; | |
63 Action nextAction() const; | |
64 void updateState(Action); | |
65 | |
66 // Indicates whether the scheduler needs a vsync callback in order to make | |
67 // progress. | |
68 bool vsyncCallbackNeeded() const; | |
69 | |
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(); | |
74 | |
75 // Indicates whether the LayerTreeHostImpl is visible. | |
76 void setVisible(bool); | |
77 | |
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(); | |
81 | |
82 // As setNeedsRedraw(), but ensures the draw will definitely happen even if | |
83 // we are not visible. | |
84 void setNeedsForcedRedraw(); | |
85 | |
86 // Indicates whether ACTION_DRAW_IF_POSSIBLE drew to the screen or not. | |
87 void didDrawIfPossibleCompleted(bool success); | |
88 | |
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(); | |
93 | |
94 // As setNeedsCommit(), but ensures the beginFrame will definitely happen ev
en if | |
95 // we are not visible. | |
96 void setNeedsForcedCommit(); | |
97 | |
98 // Call this only in response to receiving an ACTION_BEGIN_FRAME | |
99 // from nextState. Indicates that all painting is complete. | |
100 void beginFrameComplete(); | |
101 | |
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(); | |
105 | |
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(); | |
111 | |
112 // Indicates whether we can successfully begin a frame at this time. | |
113 void setCanBeginFrame(bool can) { m_canBeginFrame = can; } | |
114 | |
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; } | |
119 | |
120 void didLoseContext(); | |
121 void didRecreateContext(); | |
122 | |
123 // Exposed for testing purposes. | |
124 void setMaximumNumberOfFailedDrawsBeforeDrawIsForced(int); | |
125 | |
126 std::string toString(); | |
127 | |
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; | |
135 | |
136 CommitState m_commitState; | |
137 | |
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; | |
155 | |
156 DISALLOW_COPY_AND_ASSIGN(CCSchedulerStateMachine); | |
157 }; | |
158 | |
159 } | |
160 | |
161 #endif // CCSchedulerStateMachine_h | |
OLD | NEW |