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