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_H_
6 #define CC_SCHEDULER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h"
11 #include "cc/cc_export.h"
12 #include "cc/frame_rate_controller.h"
13 #include "cc/layer_tree_host.h"
14 #include "cc/scheduler_state_machine.h"
20 struct ScheduledActionDrawAndSwapResult
{
21 ScheduledActionDrawAndSwapResult()
26 ScheduledActionDrawAndSwapResult(bool didDraw
, bool didSwap
)
35 class SchedulerClient
{
37 virtual void scheduledActionBeginFrame() = 0;
38 virtual ScheduledActionDrawAndSwapResult
scheduledActionDrawAndSwapIfPossible() = 0;
39 virtual ScheduledActionDrawAndSwapResult
scheduledActionDrawAndSwapForced() = 0;
40 virtual void scheduledActionCommit() = 0;
41 virtual void scheduledActionBeginContextRecreation() = 0;
42 virtual void scheduledActionAcquireLayerTexturesForMainThread() = 0;
43 virtual void didAnticipatedDrawTimeChange(base::TimeTicks
) = 0;
46 virtual ~SchedulerClient() { }
49 class CC_EXPORT Scheduler
: FrameRateControllerClient
{
51 static scoped_ptr
<Scheduler
> create(SchedulerClient
* client
, scoped_ptr
<FrameRateController
> frameRateController
)
53 return make_scoped_ptr(new Scheduler(client
, frameRateController
.Pass()));
58 void setCanBeginFrame(bool);
60 void setVisible(bool);
61 void setCanDraw(bool);
62 void setHasPendingTree(bool);
64 void setNeedsCommit();
66 // Like setNeedsCommit(), but ensures a commit will definitely happen even if we are not visible.
67 void setNeedsForcedCommit();
69 void setNeedsRedraw();
71 void setMainThreadNeedsLayerTextures();
73 // Like setNeedsRedraw(), but ensures the draw will definitely happen even if we are not visible.
74 void setNeedsForcedRedraw();
76 void beginFrameComplete();
77 void beginFrameAborted();
79 void setMaxFramesPending(int);
80 void setSwapBuffersCompleteSupported(bool);
81 void didSwapBuffersComplete();
83 void didLoseOutputSurface();
84 void didRecreateOutputSurface();
86 bool commitPending() const { return m_stateMachine
.commitPending(); }
87 bool redrawPending() const { return m_stateMachine
.redrawPending(); }
89 void setTimebaseAndInterval(base::TimeTicks timebase
, base::TimeDelta interval
);
91 base::TimeTicks
anticipatedDrawTime();
93 // FrameRateControllerClient implementation
94 virtual void vsyncTick(bool throttled
) OVERRIDE
;
97 Scheduler(SchedulerClient
*, scoped_ptr
<FrameRateController
>);
99 void processScheduledActions();
101 SchedulerClient
* m_client
;
102 scoped_ptr
<FrameRateController
> m_frameRateController
;
103 SchedulerStateMachine m_stateMachine
;
104 bool m_insideProcessScheduledActions
;
106 DISALLOW_COPY_AND_ASSIGN(Scheduler
);
111 #endif // CC_SCHEDULER_H_