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

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

Issue 16863005: cc: Add BeginFrameArgs (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc12
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
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"
(...skipping 19 matching lines...) Expand all
30 FrameRateController* frame_rate_controller) 30 FrameRateController* frame_rate_controller)
31 : frame_rate_controller_(frame_rate_controller) {} 31 : frame_rate_controller_(frame_rate_controller) {}
32 32
33 FrameRateController* frame_rate_controller_; 33 FrameRateController* frame_rate_controller_;
34 }; 34 };
35 35
36 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer) 36 FrameRateController::FrameRateController(scoped_refptr<TimeSource> timer)
37 : client_(NULL), 37 : client_(NULL),
38 num_frames_pending_(0), 38 num_frames_pending_(0),
39 max_swaps_pending_(0), 39 max_swaps_pending_(0),
40 interval_(base::TimeDelta::FromMicroseconds(16666)),
Sami 2013/06/13 10:01:07 It might be worth making the default frame interva
brianderson 2013/06/14 20:12:02 Good idea.
40 time_source_(timer), 41 time_source_(timer),
41 active_(false), 42 active_(false),
42 is_time_source_throttling_(true), 43 is_time_source_throttling_(true),
43 weak_factory_(this), 44 weak_factory_(this),
44 thread_(NULL) { 45 thread_(NULL) {
45 time_source_client_adapter_ = 46 time_source_client_adapter_ =
46 FrameRateControllerTimeSourceAdapter::Create(this); 47 FrameRateControllerTimeSourceAdapter::Create(this);
47 time_source_->SetClient(time_source_client_adapter_.get()); 48 time_source_->SetClient(time_source_client_adapter_.get());
48 } 49 }
49 50
50 FrameRateController::FrameRateController(Thread* thread) 51 FrameRateController::FrameRateController(Thread* thread)
51 : client_(NULL), 52 : client_(NULL),
52 num_frames_pending_(0), 53 num_frames_pending_(0),
53 max_swaps_pending_(0), 54 max_swaps_pending_(0),
55 interval_(base::TimeDelta::FromMicroseconds(16666)),
54 active_(false), 56 active_(false),
55 is_time_source_throttling_(false), 57 is_time_source_throttling_(false),
56 weak_factory_(this), 58 weak_factory_(this),
57 thread_(thread) {} 59 thread_(thread) {}
58 60
59 FrameRateController::~FrameRateController() { 61 FrameRateController::~FrameRateController() {
60 if (is_time_source_throttling_) 62 if (is_time_source_throttling_)
61 time_source_->SetActive(false); 63 time_source_->SetActive(false);
62 } 64 }
63 65
(...skipping 13 matching lines...) Expand all
77 } 79 }
78 } 80 }
79 81
80 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) { 82 void FrameRateController::SetMaxSwapsPending(int max_swaps_pending) {
81 DCHECK_GE(max_swaps_pending, 0); 83 DCHECK_GE(max_swaps_pending, 0);
82 max_swaps_pending_ = max_swaps_pending; 84 max_swaps_pending_ = max_swaps_pending;
83 } 85 }
84 86
85 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase, 87 void FrameRateController::SetTimebaseAndInterval(base::TimeTicks timebase,
86 base::TimeDelta interval) { 88 base::TimeDelta interval) {
89 interval_ = interval;
87 if (is_time_source_throttling_) 90 if (is_time_source_throttling_)
88 time_source_->SetTimebaseAndInterval(timebase, interval); 91 time_source_->SetTimebaseAndInterval(timebase, interval);
89 } 92 }
90 93
94 void FrameRateController::SetDeadlineAdjustment(base::TimeDelta delta) {
95 deadline_adjustment_ = delta;
96 }
97
91 void FrameRateController::OnTimerTick() { 98 void FrameRateController::OnTimerTick() {
92 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick"); 99 TRACE_EVENT0("cc", "FrameRateController::OnTimerTick");
93 DCHECK(active_); 100 DCHECK(active_);
94 101
95 // Check if we have too many frames in flight. 102 // Check if we have too many frames in flight.
96 bool throttled = 103 bool throttled =
97 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_; 104 max_swaps_pending_ && num_frames_pending_ >= max_swaps_pending_;
98 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled); 105 TRACE_COUNTER_ID1("cc", "ThrottledCompositor", thread_, throttled);
99 106
100 if (client_) { 107 if (client_) {
101 client_->FrameRateControllerTick(throttled); 108 // TODO(brianderson): Use an adaptive parent compositor deadline.
109 base::TimeTicks frame_time = LastTickTime();
110 base::TimeTicks deadline = NextTickTime() + deadline_adjustment_;
111 client_->FrameRateControllerTick(
112 throttled,
113 BeginFrameArgs::CreateBeginFrame(frame_time, deadline, interval_));
102 } 114 }
103 115
104 if (!is_time_source_throttling_ && !throttled) 116 if (!is_time_source_throttling_ && !throttled)
105 PostManualTick(); 117 PostManualTick();
106 } 118 }
107 119
108 void FrameRateController::PostManualTick() { 120 void FrameRateController::PostManualTick() {
109 if (active_) { 121 if (active_) {
110 thread_->PostTask(base::Bind(&FrameRateController::ManualTick, 122 thread_->PostTask(base::Bind(&FrameRateController::ManualTick,
111 weak_factory_.GetWeakPtr())); 123 weak_factory_.GetWeakPtr()));
(...skipping 27 matching lines...) Expand all
139 } 151 }
140 152
141 base::TimeTicks FrameRateController::LastTickTime() { 153 base::TimeTicks FrameRateController::LastTickTime() {
142 if (is_time_source_throttling_) 154 if (is_time_source_throttling_)
143 return time_source_->LastTickTime(); 155 return time_source_->LastTickTime();
144 156
145 return base::TimeTicks::Now(); 157 return base::TimeTicks::Now();
146 } 158 }
147 159
148 } // namespace cc 160 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698