Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / scheduler / scheduler.h
blob08da4add85cf8622c8c9081a1657a2ad60f3deb7
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"
17 namespace cc {
19 class Thread;
21 struct ScheduledActionDrawAndSwapResult {
22 ScheduledActionDrawAndSwapResult()
23 : did_draw(false),
24 did_swap(false) {}
25 ScheduledActionDrawAndSwapResult(bool did_draw, bool did_swap)
26 : did_draw(did_draw),
27 did_swap(did_swap) {}
28 bool did_draw;
29 bool did_swap;
32 class SchedulerClient {
33 public:
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;
46 protected:
47 virtual ~SchedulerClient() {}
50 class CC_EXPORT Scheduler : FrameRateControllerClient {
51 public:
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));
60 virtual ~Scheduler();
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;
111 private:
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);
127 } // namespace cc
129 #endif // CC_SCHEDULER_SCHEDULER_H_