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_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/scheduler/frame_rate_controller.h"
13 #include "cc/scheduler/scheduler_settings.h"
14 #include "cc/scheduler/scheduler_state_machine.h"
15 #include "cc/trees/layer_tree_host.h"
21 struct ScheduledActionDrawAndSwapResult
{
22 ScheduledActionDrawAndSwapResult()
25 ScheduledActionDrawAndSwapResult(bool did_draw
, bool did_swap
)
32 class SchedulerClient
{
34 virtual void ScheduledActionBeginFrame() = 0;
35 virtual ScheduledActionDrawAndSwapResult
36 ScheduledActionDrawAndSwapIfPossible() = 0;
37 virtual ScheduledActionDrawAndSwapResult
38 ScheduledActionDrawAndSwapForced() = 0;
39 virtual void ScheduledActionCommit() = 0;
40 virtual void ScheduledActionCheckForCompletedTileUploads() = 0;
41 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0;
42 virtual void ScheduledActionBeginContextRecreation() = 0;
43 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0;
44 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time
) = 0;
47 virtual ~SchedulerClient() {}
50 class CC_EXPORT Scheduler
: FrameRateControllerClient
{
52 static scoped_ptr
<Scheduler
> Create(
53 SchedulerClient
* client
,
54 scoped_ptr
<FrameRateController
> frame_rate_controller
,
55 const SchedulerSettings
& scheduler_settings
) {
56 return make_scoped_ptr(new Scheduler(
57 client
, frame_rate_controller
.Pass(), scheduler_settings
));
62 void SetCanBeginFrame(bool can
);
64 void SetVisible(bool visible
);
65 void SetCanDraw(bool can_draw
);
66 void SetHasPendingTree(bool has_pending_tree
);
68 void SetNeedsCommit();
70 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if
71 // we are not visible.
72 void SetNeedsForcedCommit();
74 void SetNeedsRedraw();
76 void SetMainThreadNeedsLayerTextures();
78 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if
79 // we are not visible.
80 void SetNeedsForcedRedraw();
82 void DidSwapUseIncompleteTile();
84 void BeginFrameComplete();
85 void BeginFrameAborted();
87 void SetMaxFramesPending(int max
);
88 int MaxFramesPending() const;
90 void SetSwapBuffersCompleteSupported(bool supported
);
91 void DidSwapBuffersComplete();
93 void DidLoseOutputSurface();
94 void DidRecreateOutputSurface();
96 bool CommitPending() const { return state_machine_
.CommitPending(); }
97 bool RedrawPending() const { return state_machine_
.RedrawPending(); }
99 bool WillDrawIfNeeded() const;
101 void SetTimebaseAndInterval(base::TimeTicks timebase
,
102 base::TimeDelta interval
);
104 base::TimeTicks
AnticipatedDrawTime();
106 base::TimeTicks
LastVSyncTime();
108 // FrameRateControllerClient implementation
109 virtual void VSyncTick(bool throttled
) OVERRIDE
;
112 Scheduler(SchedulerClient
* client
,
113 scoped_ptr
<FrameRateController
> frame_rate_controller
,
114 const SchedulerSettings
& scheduler_settings
);
116 void ProcessScheduledActions();
118 const SchedulerSettings settings_
;
119 SchedulerClient
* client_
;
120 scoped_ptr
<FrameRateController
> frame_rate_controller_
;
121 SchedulerStateMachine state_machine_
;
122 bool inside_process_scheduled_actions_
;
124 DISALLOW_COPY_AND_ASSIGN(Scheduler
);
129 #endif // CC_SCHEDULER_SCHEDULER_H_