Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / cc / scheduler / frame_rate_controller.h
blob9210a670d9992523c055a35e16310fcddbc6318b
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_FRAME_RATE_CONTROLLER_H_
6 #define CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time.h"
12 #include "cc/base/cc_export.h"
14 namespace cc {
16 class Thread;
17 class TimeSource;
19 class CC_EXPORT FrameRateControllerClient {
20 public:
21 // Throttled is true when we have a maximum number of frames pending.
22 virtual void BeginFrame(bool throttled) = 0;
24 protected:
25 virtual ~FrameRateControllerClient() {}
28 class FrameRateControllerTimeSourceAdapter;
30 class CC_EXPORT FrameRateController {
31 public:
32 enum {
33 DEFAULT_MAX_FRAMES_PENDING = 2
36 explicit FrameRateController(scoped_refptr<TimeSource> timer);
37 // Alternate form of FrameRateController with unthrottled frame-rate.
38 explicit FrameRateController(Thread* thread);
39 virtual ~FrameRateController();
41 void SetClient(FrameRateControllerClient* client) { client_ = client; }
43 void SetActive(bool active);
45 // Use the following methods to adjust target frame rate.
47 // Multiple frames can be in-progress, but for every DidSwapBuffers, a
48 // DidFinishFrame should be posted.
50 // If the rendering pipeline crashes, call DidAbortAllPendingFrames.
51 void DidSwapBuffers();
52 void DidSwapBuffersComplete();
53 void DidAbortAllPendingFrames();
54 void SetMaxFramesPending(int max_frames_pending); // 0 for unlimited.
55 int MaxFramesPending() const { return max_frames_pending_; }
56 int NumFramesPendingForTesting() const { return num_frames_pending_; }
58 // This returns null for unthrottled frame-rate.
59 base::TimeTicks NextTickTime();
61 // This returns now for unthrottled frame-rate.
62 base::TimeTicks LastTickTime();
64 void SetTimebaseAndInterval(base::TimeTicks timebase,
65 base::TimeDelta interval);
66 void SetSwapBuffersCompleteSupported(bool supported);
68 protected:
69 friend class FrameRateControllerTimeSourceAdapter;
70 void OnTimerTick();
72 void PostManualTick();
73 void ManualTick();
75 FrameRateControllerClient* client_;
76 int num_frames_pending_;
77 int max_frames_pending_;
78 scoped_refptr<TimeSource> time_source_;
79 scoped_ptr<FrameRateControllerTimeSourceAdapter> time_source_client_adapter_;
80 bool active_;
81 bool swap_buffers_complete_supported_;
83 // Members for unthrottled frame-rate.
84 bool is_time_source_throttling_;
85 base::WeakPtrFactory<FrameRateController> weak_factory_;
86 Thread* thread_;
88 DISALLOW_COPY_AND_ASSIGN(FrameRateController);
91 } // namespace cc
93 #endif // CC_SCHEDULER_FRAME_RATE_CONTROLLER_H_