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 CC_SCHEDULER_SCHEDULER_H_
6 #define CC_SCHEDULER_SCHEDULER_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/output/begin_frame_args.h"
15 #include "cc/scheduler/scheduler_settings.h"
16 #include "cc/scheduler/scheduler_state_machine.h"
17 #include "cc/trees/layer_tree_host.h"
23 struct ScheduledActionDrawAndSwapResult
{
24 ScheduledActionDrawAndSwapResult()
27 ScheduledActionDrawAndSwapResult(bool did_draw
, bool did_swap
)
34 class SchedulerClient
{
36 virtual void SetNeedsBeginFrameOnImplThread(bool enable
) = 0;
37 virtual void ScheduledActionSendBeginFrameToMainThread() = 0;
38 virtual ScheduledActionDrawAndSwapResult
39 ScheduledActionDrawAndSwapIfPossible() = 0;
40 virtual ScheduledActionDrawAndSwapResult
41 ScheduledActionDrawAndSwapForced() = 0;
42 virtual void ScheduledActionCommit() = 0;
43 virtual void ScheduledActionUpdateVisibleTiles() = 0;
44 virtual void ScheduledActionActivatePendingTree() = 0;
45 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0;
46 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0;
47 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time
) = 0;
48 virtual base::TimeDelta
DrawDurationEstimate() = 0;
49 virtual base::TimeDelta
BeginFrameToCommitDurationEstimate() = 0;
50 virtual base::TimeDelta
CommitToActivateDurationEstimate() = 0;
53 virtual ~SchedulerClient() {}
56 class CC_EXPORT Scheduler
{
58 static scoped_ptr
<Scheduler
> Create(
59 SchedulerClient
* client
,
60 const SchedulerSettings
& scheduler_settings
) {
61 return make_scoped_ptr(new Scheduler(client
, scheduler_settings
));
68 void SetVisible(bool visible
);
69 void SetCanDraw(bool can_draw
);
70 void NotifyReadyToActivate();
72 void SetNeedsCommit();
74 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if
75 // we are not visible.
76 void SetNeedsForcedCommit();
78 void SetNeedsRedraw();
80 void SetMainThreadNeedsLayerTextures();
82 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if
83 // we are not visible.
84 void SetNeedsForcedRedraw();
86 void DidSwapUseIncompleteTile();
89 void BeginFrameAbortedByMainThread(bool did_handle
);
91 void DidLoseOutputSurface();
92 void DidCreateAndInitializeOutputSurface();
93 bool HasInitializedOutputSurface() const {
94 return state_machine_
.HasInitializedOutputSurface();
97 bool CommitPending() const { return state_machine_
.CommitPending(); }
98 bool RedrawPending() const { return state_machine_
.RedrawPending(); }
100 bool WillDrawIfNeeded() const;
102 base::TimeTicks
AnticipatedDrawTime();
104 base::TimeTicks
LastBeginFrameOnImplThreadTime();
106 void BeginFrame(const BeginFrameArgs
& args
);
108 scoped_ptr
<base::Value
> StateAsValue() {
109 return state_machine_
.AsValue().Pass();
113 Scheduler(SchedulerClient
* client
,
114 const SchedulerSettings
& scheduler_settings
);
116 void SetupNextBeginFrameIfNeeded();
117 void DrawAndSwapIfPossible();
118 void DrawAndSwapForced();
119 void ProcessScheduledActions();
121 const SchedulerSettings settings_
;
122 SchedulerClient
* client_
;
124 base::WeakPtrFactory
<Scheduler
> weak_factory_
;
125 bool last_set_needs_begin_frame_
;
126 bool has_pending_begin_frame_
;
127 // TODO(brianderson): crbug.com/249806 : Remove safe_to_expect_begin_frame_
129 bool safe_to_expect_begin_frame_
;
130 BeginFrameArgs last_begin_frame_args_
;
132 SchedulerStateMachine state_machine_
;
133 bool inside_process_scheduled_actions_
;
135 DISALLOW_COPY_AND_ASSIGN(Scheduler
);
140 #endif // CC_SCHEDULER_SCHEDULER_H_