WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / scheduler.h
blobeee40efd94924d02850f94c26e7c401e8ec77077
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"
16 namespace cc {
18 class Thread;
20 struct ScheduledActionDrawAndSwapResult {
21 ScheduledActionDrawAndSwapResult()
22 : didDraw(false)
23 , didSwap(false)
26 ScheduledActionDrawAndSwapResult(bool didDraw, bool didSwap)
27 : didDraw(didDraw)
28 , didSwap(didSwap)
31 bool didDraw;
32 bool didSwap;
35 class SchedulerClient {
36 public:
37 virtual void scheduledActionBeginFrame() = 0;
38 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossible() = 0;
39 virtual ScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced() = 0;
40 virtual void scheduledActionCommit() = 0;
41 virtual void scheduledActionActivatePendingTreeIfNeeded() = 0;
42 virtual void scheduledActionBeginContextRecreation() = 0;
43 virtual void scheduledActionAcquireLayerTexturesForMainThread() = 0;
44 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) = 0;
46 protected:
47 virtual ~SchedulerClient() { }
50 class CC_EXPORT Scheduler : FrameRateControllerClient {
51 public:
52 static scoped_ptr<Scheduler> create(SchedulerClient* client, scoped_ptr<FrameRateController> frameRateController)
54 return make_scoped_ptr(new Scheduler(client, frameRateController.Pass()));
57 virtual ~Scheduler();
59 void setCanBeginFrame(bool);
61 void setVisible(bool);
62 void setCanDraw(bool);
63 void setHasPendingTree(bool);
65 void setNeedsCommit();
67 // Like setNeedsCommit(), but ensures a commit will definitely happen even if we are not visible.
68 void setNeedsForcedCommit();
70 void setNeedsRedraw();
72 void setMainThreadNeedsLayerTextures();
74 // Like setNeedsRedraw(), but ensures the draw will definitely happen even if we are not visible.
75 void setNeedsForcedRedraw();
77 void beginFrameComplete();
78 void beginFrameAborted();
80 void setMaxFramesPending(int);
81 void setSwapBuffersCompleteSupported(bool);
82 void didSwapBuffersComplete();
84 void didLoseOutputSurface();
85 void didRecreateOutputSurface();
87 bool commitPending() const { return m_stateMachine.commitPending(); }
88 bool redrawPending() const { return m_stateMachine.redrawPending(); }
90 void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelta interval);
92 base::TimeTicks anticipatedDrawTime();
94 // FrameRateControllerClient implementation
95 virtual void vsyncTick(bool throttled) OVERRIDE;
97 private:
98 Scheduler(SchedulerClient*, scoped_ptr<FrameRateController>);
100 void processScheduledActions();
102 SchedulerClient* m_client;
103 scoped_ptr<FrameRateController> m_frameRateController;
104 SchedulerStateMachine m_stateMachine;
105 bool m_insideProcessScheduledActions;
107 DISALLOW_COPY_AND_ASSIGN(Scheduler);
110 } // namespace cc
112 #endif // CC_SCHEDULER_H_