Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / cc / scheduler / scheduler.h
blobaec0cdf2b56dcb4e801f41af44f165831ae3205d
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 <string>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/scheduler/frame_rate_controller.h"
15 #include "cc/scheduler/scheduler_settings.h"
16 #include "cc/scheduler/scheduler_state_machine.h"
17 #include "cc/trees/layer_tree_host.h"
19 namespace cc {
21 class Thread;
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;
34 class SchedulerClient {
35 public:
36 virtual void ScheduledActionSendBeginFrameToMainThread() = 0;
37 virtual ScheduledActionDrawAndSwapResult
38 ScheduledActionDrawAndSwapIfPossible() = 0;
39 virtual ScheduledActionDrawAndSwapResult
40 ScheduledActionDrawAndSwapForced() = 0;
41 virtual void ScheduledActionCommit() = 0;
42 virtual void ScheduledActionCheckForCompletedTileUploads() = 0;
43 virtual void ScheduledActionActivatePendingTreeIfNeeded() = 0;
44 virtual void ScheduledActionBeginOutputSurfaceCreation() = 0;
45 virtual void ScheduledActionAcquireLayerTexturesForMainThread() = 0;
46 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks time) = 0;
48 protected:
49 virtual ~SchedulerClient() {}
52 class CC_EXPORT Scheduler : FrameRateControllerClient {
53 public:
54 static scoped_ptr<Scheduler> Create(
55 SchedulerClient* client,
56 scoped_ptr<FrameRateController> frame_rate_controller,
57 const SchedulerSettings& scheduler_settings) {
58 return make_scoped_ptr(new Scheduler(
59 client, frame_rate_controller.Pass(), scheduler_settings));
62 virtual ~Scheduler();
64 void SetCanStart();
66 void SetVisible(bool visible);
67 void SetCanDraw(bool can_draw);
68 void SetHasPendingTree(bool has_pending_tree);
70 void SetNeedsCommit();
72 // Like SetNeedsCommit(), but ensures a commit will definitely happen even if
73 // we are not visible.
74 void SetNeedsForcedCommit();
76 void SetNeedsRedraw();
78 void SetMainThreadNeedsLayerTextures();
80 // Like SetNeedsRedraw(), but ensures the draw will definitely happen even if
81 // we are not visible.
82 void SetNeedsForcedRedraw();
84 void DidSwapUseIncompleteTile();
86 void FinishCommit();
87 void BeginFrameAbortedByMainThread();
89 void SetMaxFramesPending(int max);
90 int MaxFramesPending() const;
91 int NumFramesPendingForTesting() const;
93 void SetSwapBuffersCompleteSupported(bool supported);
94 void DidSwapBuffersComplete();
96 void DidLoseOutputSurface();
97 void DidCreateAndInitializeOutputSurface();
98 bool HasInitializedOutputSurface() const {
99 return state_machine_.HasInitializedOutputSurface();
102 bool CommitPending() const { return state_machine_.CommitPending(); }
103 bool RedrawPending() const { return state_machine_.RedrawPending(); }
105 bool WillDrawIfNeeded() const;
107 void SetTimebaseAndInterval(base::TimeTicks timebase,
108 base::TimeDelta interval);
110 base::TimeTicks AnticipatedDrawTime();
112 base::TimeTicks LastBeginFrameOnImplThreadTime();
114 // FrameRateControllerClient implementation
115 virtual void BeginFrame(bool throttled) OVERRIDE;
117 std::string StateAsStringForTesting() { return state_machine_.ToString(); }
119 private:
120 Scheduler(SchedulerClient* client,
121 scoped_ptr<FrameRateController> frame_rate_controller,
122 const SchedulerSettings& scheduler_settings);
124 void ProcessScheduledActions();
126 const SchedulerSettings settings_;
127 SchedulerClient* client_;
128 scoped_ptr<FrameRateController> frame_rate_controller_;
129 SchedulerStateMachine state_machine_;
130 bool inside_process_scheduled_actions_;
132 DISALLOW_COPY_AND_ASSIGN(Scheduler);
135 } // namespace cc
137 #endif // CC_SCHEDULER_SCHEDULER_H_