Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Side by Side Diff: cc/scheduler/frame_rate_controller.cc

Issue 12623026: cc: Chromify TimeSource, DelayBasedTimeSource and test (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/scheduler/frame_rate_controller.h" 5 #include "cc/scheduler/frame_rate_controller.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/base/thread.h" 9 #include "cc/base/thread.h"
10 #include "cc/scheduler/delay_based_time_source.h" 10 #include "cc/scheduler/delay_based_time_source.h"
11 #include "cc/scheduler/time_source.h" 11 #include "cc/scheduler/time_source.h"
12 12
13 namespace cc { 13 namespace cc {
14 14
15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient { 15 class FrameRateControllerTimeSourceAdapter : public TimeSourceClient {
16 public: 16 public:
17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create( 17 static scoped_ptr<FrameRateControllerTimeSourceAdapter> Create(
18 FrameRateController* frame_rate_controller) { 18 FrameRateController* frame_rate_controller) {
19 return make_scoped_ptr( 19 return make_scoped_ptr(
20 new FrameRateControllerTimeSourceAdapter(frame_rate_controller)); 20 new FrameRateControllerTimeSourceAdapter(frame_rate_controller));
21 } 21 }
22 virtual ~FrameRateControllerTimeSourceAdapter() {} 22 virtual ~FrameRateControllerTimeSourceAdapter() {}
23 23
24 virtual void onTimerTick() OVERRIDE { frame_rate_controller_->OnTimerTick(); } 24 virtual void OnTimerTick() OVERRIDE { frame_rate_controller_->OnTimerTick(); }
25 25
26 private: 26 private:
27 explicit FrameRateControllerTimeSourceAdapter( 27 explicit FrameRateControllerTimeSourceAdapter(
28 FrameRateController* frame_rate_controller) 28 FrameRateController* frame_rate_controller)
29 : frame_rate_controller_(frame_rate_controller) {} 29 : frame_rate_controller_(frame_rate_controller) {}
30 30
31 FrameRateController* frame_rate_controller_; 31 FrameRateController* frame_rate_controller_;
32 }; 32 };
33 33
34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
35 : client_(NULL), 35 : client_(NULL),
36 num_frames_pending_(0), 36 num_frames_pending_(0),
37 max_frames_pending_(0), 37 max_frames_pending_(0),
38 time_source_(timer), 38 time_source_(timer),
39 active_(false), 39 active_(false),
40 swap_buffers_complete_supported_(true), 40 swap_buffers_complete_supported_(true),
41 is_time_source_throttling_(true), 41 is_time_source_throttling_(true),
42 thread_(NULL), 42 thread_(NULL),
43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 43 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
44 time_source_client_adapter_ = 44 time_source_client_adapter_ =
45 FrameRateControllerTimeSourceAdapter::Create(this); 45 FrameRateControllerTimeSourceAdapter::Create(this);
46 time_source_->setClient(time_source_client_adapter_.get()); 46 time_source_->SetClient(time_source_client_adapter_.get());
47 } 47 }
48 48
49 FrameRateController::FrameRateController(Thread* thread) 49 FrameRateController::FrameRateController(Thread* thread)
50 : client_(NULL), 50 : client_(NULL),
51 num_frames_pending_(0), 51 num_frames_pending_(0),
52 max_frames_pending_(0), 52 max_frames_pending_(0),
53 active_(false), 53 active_(false),
54 swap_buffers_complete_supported_(true), 54 swap_buffers_complete_supported_(true),
55 is_time_source_throttling_(false), 55 is_time_source_throttling_(false),
56 thread_(thread), 56 thread_(thread),
57 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} 57 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {}
58 58
59 FrameRateController::~FrameRateController() { 59 FrameRateController::~FrameRateController() {
60 if (is_time_source_throttling_) 60 if (is_time_source_throttling_)
61 time_source_->setActive(false); 61 time_source_->SetActive(false);
62 } 62 }
63 63
64 void FrameRateController::SetActive(bool active) { 64 void FrameRateController::SetActive(bool active) {
65 if (active_ == active) 65 if (active_ == active)
66 return; 66 return;
67 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); 67 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active);
68 active_ = active; 68 active_ = active;
69 69
70 if (is_time_source_throttling_) { 70 if (is_time_source_throttling_) {
71 time_source_->setActive(active); 71 time_source_->SetActive(active);
72 } else { 72 } else {
73 if (active) 73 if (active)
74 PostManualTick(); 74 PostManualTick();
75 else 75 else
76 weak_factory_.InvalidateWeakPtrs(); 76 weak_factory_.InvalidateWeakPtrs();
77 } 77 }
78 } 78 }
79 79
80 void FrameRateController::SetMaxFramesPending(int max_frames_pending) { 80 void FrameRateController::SetMaxFramesPending(int max_frames_pending) {
81 DCHECK_GE(max_frames_pending, 0); 81 DCHECK_GE(max_frames_pending, 0);
82 max_frames_pending_ = max_frames_pending; 82 max_frames_pending_ = max_frames_pending;
83 } 83 }
84 84
85 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, 85 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase,
86 base::TimeDelta interval) { 86 base::TimeDelta interval) {
87 if (is_time_source_throttling_) 87 if (is_time_source_throttling_)
88 time_source_->setTimebaseAndInterval(timebase, interval); 88 time_source_->SetTimebaseAndInterval(timebase, interval);
89 } 89 }
90 90
91 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) { 91 void FrameRateController::SetSwapBuffersCompleteSupported(bool supported) {
92 swap_buffers_complete_supported_ = supported; 92 swap_buffers_complete_supported_ = supported;
93 } 93 }
94 94
95 void FrameRateController::OnTimerTick() { 95 void FrameRateController::OnTimerTick() {
96 DCHECK(active_); 96 DCHECK(active_);
97 97
98 // Check if we have too many frames in flight. 98 // Check if we have too many frames in flight.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (!is_time_source_throttling_) 131 if (!is_time_source_throttling_)
132 PostManualTick(); 132 PostManualTick();
133 } 133 }
134 134
135 void FrameRateController::DidAbortAllPendingFrames() { 135 void FrameRateController::DidAbortAllPendingFrames() {
136 num_frames_pending_ = 0; 136 num_frames_pending_ = 0;
137 } 137 }
138 138
139 base::TimeTicks FrameRateController::NextTickTime() { 139 base::TimeTicks FrameRateController::NextTickTime() {
140 if (is_time_source_throttling_) 140 if (is_time_source_throttling_)
141 return time_source_->nextTickTime(); 141 return time_source_->NextTickTime();
142 142
143 return base::TimeTicks(); 143 return base::TimeTicks();
144 } 144 }
145 145
146 base::TimeTicks FrameRateController::LastTickTime() { 146 base::TimeTicks FrameRateController::LastTickTime() {
147 if (is_time_source_throttling_) 147 if (is_time_source_throttling_)
148 return time_source_->lastTickTime(); 148 return time_source_->LastTickTime();
149 149
150 return base::TimeTicks::Now(); 150 return base::TimeTicks::Now();
151 } 151 }
152 152
153 } // namespace cc 153 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698