| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 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 CC_SCHEDULER_SCHEDULER_H_ | 5 #ifndef CC_SCHEDULER_SCHEDULER_H_ |
| 6 #define CC_SCHEDULER_SCHEDULER_H_ | 6 #define CC_SCHEDULER_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/cancelable_callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 13 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
| 14 #include "cc/output/begin_frame_args.h" | 15 #include "cc/output/begin_frame_args.h" |
| 15 #include "cc/scheduler/scheduler_settings.h" | 16 #include "cc/scheduler/scheduler_settings.h" |
| 16 #include "cc/scheduler/scheduler_state_machine.h" | 17 #include "cc/scheduler/scheduler_state_machine.h" |
| 17 #include "cc/trees/layer_tree_host.h" | 18 #include "cc/trees/layer_tree_host.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 | 21 |
| 21 class Thread; | 22 class Thread; |
| 22 | 23 |
| 23 struct ScheduledActionDrawAndSwapResult { | 24 struct ScheduledActionDrawSwapReadbackResult { |
| 24 ScheduledActionDrawAndSwapResult() | 25 ScheduledActionDrawSwapReadbackResult() |
| 25 : did_draw(false), | 26 : did_draw(false), |
| 26 did_swap(false) {} | 27 did_swap(false), |
| 27 ScheduledActionDrawAndSwapResult(bool did_draw, bool did_swap) | 28 did_readback(false) {} |
| 29 ScheduledActionDrawSwapReadbackResult(bool did_draw, bool did_swap) |
| 28 : did_draw(did_draw), | 30 : did_draw(did_draw), |
| 29 did_swap(did_swap) {} | 31 did_swap(did_swap), |
| 32 did_readback(did_readback) {} |
| 30 bool did_draw; | 33 bool did_draw; |
| 31 bool did_swap; | 34 bool did_swap; |
| 35 bool did_readback; |
| 32 }; | 36 }; |
| 33 | 37 |
| 34 class SchedulerClient { | 38 class SchedulerClient { |
| 35 public: | 39 public: |
| 36 virtual void SetNeedsBeginFrameOnImplThread(bool enable) = 0; | 40 virtual void SetNeedsBeginFrameOnImplThread(bool enable) = 0; |
| 37 virtual void ScheduledActionSendBeginFrameToMainThread() = 0; | 41 virtual void ScheduledActionSendBeginFrameToMainThread() = 0; |
| 38 virtual ScheduledActionDrawAndSwapResult | 42 virtual ScheduledActionDrawSwapReadbackResult |
| 39 ScheduledActionDrawAndSwapIfPossible() = 0; | 43 ScheduledActionDrawAndSwapIfPossible() = 0; |
| 40 virtual ScheduledActionDrawAndSwapResult | 44 virtual ScheduledActionDrawSwapReadbackResult |
| 41 ScheduledActionDrawAndSwapForced() = 0; | 45 ScheduledActionDrawAndSwapForced() = 0; |
| 46 virtual ScheduledActionDrawSwapReadbackResult |
| 47 ScheduledActionDrawAndReadback() = 0; |
| 42 virtual void ScheduledActionCommit() = 0; | 48 virtual void ScheduledActionCommit() = 0; |
| 43 virtual void ScheduledActionCheckForCompletedTileUploads() = 0; | 49 virtual void ScheduledActionCheckForCompletedTileUploads() = 0; |
| 44 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0; | 50 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0; |
| 45 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; | 51 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0; |
| 46 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0; | 52 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0; |
| 47 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; | 53 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0; |
| 48 virtual base::TimeDelta DrawDurationEstimate() = 0; | 54 virtual base::TimeDelta DrawDurationEstimate() = 0; |
| 55 virtual void PostBeginFrameDeadline(const base::Closure& closure, |
| 56 base::TimeTicks deadline) = 0; |
| 57 virtual void DidBeginFrameDeadlineOnImplThread() = 0; |
| 49 | 58 |
| 50 protected: | 59 protected: |
| 51 virtual ~SchedulerClient() {} | 60 virtual ~SchedulerClient() {} |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 class CC_EXPORT Scheduler { | 63 class CC_EXPORT Scheduler { |
| 55 public: | 64 public: |
| 56 static scoped_ptr<Scheduler> Create( | 65 static scoped_ptr<Scheduler> Create( |
| 57 SchedulerClient* client, | 66 SchedulerClient* client, |
| 58 const SchedulerSettings& scheduler_settings) { | 67 const SchedulerSettings& scheduler_settings) { |
| 59 return make_scoped_ptr(new Scheduler(client, scheduler_settings)); | 68 return make_scoped_ptr(new Scheduler(client, scheduler_settings)); |
| 60 } | 69 } |
| 61 | 70 |
| 62 virtual ~Scheduler(); | 71 virtual ~Scheduler(); |
| 63 | 72 |
| 64 void SetCanStart(); | 73 void SetCanStart(); |
| 65 | 74 |
| 66 void SetVisible(bool visible); | 75 void SetVisible(bool visible); |
| 67 void SetCanDraw(bool can_draw); | 76 void SetCanDraw(bool can_draw); |
| 68 void SetHasPendingTree(bool has_pending_tree); | 77 void SetHasTrees(bool has_pending_tree, bool active_tree_is_null); |
| 69 | 78 |
| 70 void SetNeedsCommit(); | 79 void SetNeedsCommit(); |
| 71 | 80 |
| 72 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if | 81 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if |
| 73 // we are not visible. | 82 // we are not visible. Will eventually result in a forced draw internally. |
| 74 void SetNeedsForcedCommit(); | 83 void SetNeedsForcedCommitForReadback(); |
| 75 | 84 |
| 76 void SetNeedsRedraw(); | 85 void SetNeedsRedraw(); |
| 77 | 86 |
| 78 void SetMainThreadNeedsLayerTextures(); | 87 void SetMainThreadNeedsLayerTextures(); |
| 79 | 88 |
| 80 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if | |
| 81 // we are not visible. | |
| 82 void SetNeedsForcedRedraw(); | |
| 83 | |
| 84 void DidSwapUseIncompleteTile(); | 89 void DidSwapUseIncompleteTile(); |
| 85 | 90 |
| 86 void FinishCommit(); | 91 void FinishCommit(); |
| 87 void BeginFrameAbortedByMainThread(); | 92 void BeginFrameAbortedByMainThread(); |
| 88 | 93 |
| 89 void DidLoseOutputSurface(); | 94 void DidLoseOutputSurface(); |
| 90 void DidCreateAndInitializeOutputSurface(); | 95 void DidCreateAndInitializeOutputSurface(); |
| 91 bool HasInitializedOutputSurface() const { | 96 bool HasInitializedOutputSurface() const { |
| 92 return state_machine_.HasInitializedOutputSurface(); | 97 return state_machine_.HasInitializedOutputSurface(); |
| 93 } | 98 } |
| 94 | 99 |
| 95 bool CommitPending() const { return state_machine_.CommitPending(); } | 100 bool CommitPending() const { return state_machine_.CommitPending(); } |
| 96 bool RedrawPending() const { return state_machine_.RedrawPending(); } | 101 bool RedrawPending() const { return state_machine_.RedrawPending(); } |
| 97 | 102 |
| 98 bool WillDrawIfNeeded() const; | 103 bool WillDrawIfNeeded() const; |
| 99 | 104 |
| 100 base::TimeTicks AnticipatedDrawTime(); | 105 base::TimeTicks AnticipatedDrawTime(); |
| 101 | 106 |
| 102 base::TimeTicks LastBeginFrameOnImplThreadTime(); | 107 base::TimeTicks LastBeginFrameOnImplThreadTime(); |
| 103 | 108 |
| 104 void BeginFrame(const BeginFrameArgs& args); | 109 void BeginFrame(const BeginFrameArgs& args); |
| 110 void OnBeginFrameDeadline(); |
| 105 | 111 |
| 106 std::string StateAsStringForTesting() { return state_machine_.ToString(); } | 112 std::string StateAsStringForTesting() { return state_machine_.ToString(); } |
| 107 | 113 |
| 108 private: | 114 private: |
| 109 Scheduler(SchedulerClient* client, | 115 Scheduler(SchedulerClient* client, |
| 110 const SchedulerSettings& scheduler_settings); | 116 const SchedulerSettings& scheduler_settings); |
| 111 | 117 |
| 118 void PostBeginFrameDeadline(base::TimeTicks deadline); |
| 112 void SetupNextBeginFrameIfNeeded(); | 119 void SetupNextBeginFrameIfNeeded(); |
| 113 void DrawAndSwapIfPossible(); | 120 void DrawAndSwapIfPossible(); |
| 114 void DrawAndSwapForced(); | 121 void DrawAndSwapForced(); |
| 122 void DrawAndReadback(); |
| 115 void ProcessScheduledActions(); | 123 void ProcessScheduledActions(); |
| 116 | 124 |
| 117 const SchedulerSettings settings_; | 125 const SchedulerSettings settings_; |
| 118 SchedulerClient* client_; | 126 SchedulerClient* client_; |
| 119 | 127 |
| 120 base::WeakPtrFactory<Scheduler> weak_factory_; | 128 base::WeakPtrFactory<Scheduler> weak_factory_; |
| 121 bool last_set_needs_begin_frame_; | 129 bool last_set_needs_begin_frame_; |
| 122 bool has_pending_begin_frame_; | 130 bool has_pending_begin_frame_; |
| 123 // TODO(brianderson): crbug.com/249806 : Remove safe_to_expect_begin_frame_ | 131 // TODO(brianderson): crbug.com/249806 : Remove safe_to_expect_begin_frame_ |
| 124 // workaround. | 132 // workaround. |
| 125 bool safe_to_expect_begin_frame_; | 133 bool safe_to_expect_begin_frame_; |
| 126 BeginFrameArgs last_begin_frame_args_; | 134 BeginFrameArgs last_begin_frame_args_; |
| 135 base::CancelableClosure begin_frame_deadline_closure_; |
| 127 | 136 |
| 128 SchedulerStateMachine state_machine_; | 137 SchedulerStateMachine state_machine_; |
| 129 bool inside_process_scheduled_actions_; | 138 bool inside_process_scheduled_actions_; |
| 130 | 139 |
| 131 DISALLOW_COPY_AND_ASSIGN(Scheduler); | 140 DISALLOW_COPY_AND_ASSIGN(Scheduler); |
| 132 }; | 141 }; |
| 133 | 142 |
| 134 } // namespace cc | 143 } // namespace cc |
| 135 | 144 |
| 136 #endif // CC_SCHEDULER_SCHEDULER_H_ | 145 #endif // CC_SCHEDULER_SCHEDULER_H_ |
| OLD | NEW |