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

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

Issue 17204002: Revert 206020 "cc: Emulate BeginFrame in OutputSurfaces that don..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 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 { 24 virtual void OnTimerTick() OVERRIDE { frame_rate_controller_->OnTimerTick(); }
25 frame_rate_controller_->OnTimerTick();
26 }
27 25
28 private: 26 private:
29 explicit FrameRateControllerTimeSourceAdapter( 27 explicit FrameRateControllerTimeSourceAdapter(
30 FrameRateController* frame_rate_controller) 28 FrameRateController* frame_rate_controller)
31 : frame_rate_controller_(frame_rate_controller) {} 29 : frame_rate_controller_(frame_rate_controller) {}
32 30
33 FrameRateController* frame_rate_controller_; 31 FrameRateController* frame_rate_controller_;
34 }; 32 };
35 33
36 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 34 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
37 : client_(NULL), 35 : client_(NULL),
38 num_frames_pending_(0), 36 num_frames_pending_(0),
39 max_swaps_pending_(0), 37 max_frames_pending_(0),
40 time_source_(timer), 38 time_source_(timer),
41 active_(false), 39 active_(false),
42 is_time_source_throttling_(true), 40 is_time_source_throttling_(true),
43 weak_factory_(this), 41 weak_factory_(this),
44 thread_(NULL) { 42 thread_(NULL) {
45 time_source_client_adapter_ = 43 time_source_client_adapter_ =
46 FrameRateControllerTimeSourceAdapter::Create(this); 44 FrameRateControllerTimeSourceAdapter::Create(this);
47 time_source_->SetClient(time_source_client_adapter_.get()); 45 time_source_->SetClient(time_source_client_adapter_.get());
48 } 46 }
49 47
50 FrameRateController::FrameRateController(Thread* thread) 48 FrameRateController::FrameRateController(Thread* thread)
51 : client_(NULL), 49 : client_(NULL),
52 num_frames_pending_(0), 50 num_frames_pending_(0),
53 max_swaps_pending_(0), 51 max_frames_pending_(0),
54 active_(false), 52 active_(false),
55 is_time_source_throttling_(false), 53 is_time_source_throttling_(false),
56 weak_factory_(this), 54 weak_factory_(this),
57 thread_(thread) {} 55 thread_(thread) {}
58 56
59 FrameRateController::~FrameRateController() { 57 FrameRateController::~FrameRateController() {
60 if (is_time_source_throttling_) 58 if (is_time_source_throttling_)
61 time_source_->SetActive(false); 59 time_source_->SetActive(false);
62 } 60 }
63 61
64 void FrameRateController::SetActive(bool active) { 62 void FrameRateController::SetActive(bool active) {
65 if (active_ == active) 63 if (active_ == active)
66 return; 64 return;
67 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active); 65 TRACE_EVENT1("cc", "FrameRateController::SetActive", "active", active);
68 active_ = active; 66 active_ = active;
69 67
70 if (is_time_source_throttling_) { 68 if (is_time_source_throttling_) {
71 time_source_->SetActive(active); 69 time_source_->SetActive(active);
72 } else { 70 } else {
73 if (active) 71 if (active)
74 PostManualTick(); 72 PostManualTick();
75 else 73 else
76 weak_factory_.InvalidateWeakPtrs(); 74 weak_factory_.InvalidateWeakPtrs();
77 } 75 }
78 } 76 }
79 77
80 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) { 78 void FrameRateController::SetMaxFramesPending(int max_frames_pending) {
81 DCHECK_GE(max_swaps_pending, 0); 79 DCHECK_GE(max_frames_pending, 0);
82 max_swaps_pending_ = max_swaps_pending; 80 max_frames_pending_ = max_frames_pending;
83 } 81 }
84 82
85 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, 83 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase,
86 base::TimeDelta interval) { 84 base::TimeDelta interval) {
87 if (is_time_source_throttling_) 85 if (is_time_source_throttling_)
88 time_source_->SetTimebaseAndInterval(timebase, interval); 86 time_source_->SetTimebaseAndInterval(timebase, interval);
89 } 87 }
90 88
91 void FrameRateController::OnTimerTick() { 89 void FrameRateController::OnTimerTick() {
92 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick");
93 DCHECK(active_); 90 DCHECK(active_);
94 91
95 // Check if we have too many frames in flight. 92 // Check if we have too many frames in flight.
96 bool throttled = 93 bool throttled =
97 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; 94 max_frames_pending_ && num_frames_pending_ >= max_frames_pending_;
98 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); 95 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled);
99 96
100 if (client_) { 97 if (client_)
101 client_->FrameRateControllerTick(throttled); 98 client_->BeginFrame(throttled);
102 }
103 99
104 if (!is_time_source_throttling_ && !throttled) 100 if (!is_time_source_throttling_ && !throttled)
105 PostManualTick(); 101 PostManualTick();
106 } 102 }
107 103
108 void FrameRateController::PostManualTick() { 104 void FrameRateController::PostManualTick() {
109 if (active_) { 105 if (active_) {
110 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, 106 thread_->PostTask(base::Bind(&FrameRateController::ManualTick,
111 weak_factory_.GetWeakPtr())); 107 weak_factory_.GetWeakPtr()));
112 } 108 }
113 } 109 }
114 110
115 void FrameRateController::ManualTick() { 111 void FrameRateController::ManualTick() { OnTimerTick(); }
116 OnTimerTick();
117 }
118 112
119 void FrameRateController::DidSwapBuffers() { 113 void FrameRateController::DidSwapBuffers() {
120 num_frames_pending_++; 114 num_frames_pending_++;
121 } 115 }
122 116
123 void FrameRateController::DidSwapBuffersComplete() { 117 void FrameRateController::DidSwapBuffersComplete() {
124 DCHECK_GT(num_frames_pending_, 0); 118 DCHECK_GT(num_frames_pending_, 0);
125 num_frames_pending_--; 119 num_frames_pending_--;
126 if (!is_time_source_throttling_) 120 if (!is_time_source_throttling_)
127 PostManualTick(); 121 PostManualTick();
(...skipping 11 matching lines...) Expand all
139 } 133 }
140 134
141 base::TimeTicks FrameRateController::LastTickTime() { 135 base::TimeTicks FrameRateController::LastTickTime() {
142 if (is_time_source_throttling_) 136 if (is_time_source_throttling_)
143 return time_source_->LastTickTime(); 137 return time_source_->LastTickTime();
144 138
145 return base::TimeTicks::Now(); 139 return base::TimeTicks::Now();
146 } 140 }
147 141
148 } // namespace cc 142 } // namespace cc
OLDNEW
« no previous file with comments | « trunk/src/cc/scheduler/frame_rate_controller.h ('k') | trunk/src/cc/scheduler/frame_rate_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698