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

Side by Side Diff: cc/scheduler/scheduler.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/scheduler.h" 5 #include "cc/scheduler/scheduler.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "cc/base/thread.h" 10 #include "cc/base/thread.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 Scheduler::Scheduler(SchedulerClient* client, 14 Scheduler::Scheduler(SchedulerClient* client,
15 const SchedulerSettings& scheduler_settings) 15 const SchedulerSettings& scheduler_settings)
16 : settings_(scheduler_settings), 16 : settings_(scheduler_settings),
17 client_(client), 17 client_(client),
18 weak_factory_(this), 18 weak_factory_(this),
19 last_set_needs_begin_frame_(false), 19 last_set_needs_begin_frame_(false),
20 has_pending_begin_frame_(false), 20 has_pending_begin_frame_(false),
21 last_begin_frame_time_(base::TimeTicks()),
22 // TODO(brianderson): Pass with BeginFrame in the near future.
23 interval_(base::TimeDelta::FromMicroseconds(16666)),
24 state_machine_(scheduler_settings), 21 state_machine_(scheduler_settings),
25 inside_process_scheduled_actions_(false) { 22 inside_process_scheduled_actions_(false) {
26 DCHECK(client_); 23 DCHECK(client_);
27 DCHECK(!state_machine_.BeginFrameNeededByImplThread()); 24 DCHECK(!state_machine_.BeginFrameNeededByImplThread());
28 } 25 }
29 26
30 Scheduler::~Scheduler() { 27 Scheduler::~Scheduler() {
31 client_->SetNeedsBeginFrameOnImplThread(false); 28 client_->SetNeedsBeginFrameOnImplThread(false);
32 } 29 }
33 30
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void Scheduler::DidCreateAndInitializeOutputSurface() { 100 void Scheduler::DidCreateAndInitializeOutputSurface() {
104 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface"); 101 TRACE_EVENT0("cc", "Scheduler::DidCreateAndInitializeOutputSurface");
105 state_machine_.DidCreateAndInitializeOutputSurface(); 102 state_machine_.DidCreateAndInitializeOutputSurface();
106 has_pending_begin_frame_ = false; 103 has_pending_begin_frame_ = false;
107 last_set_needs_begin_frame_ = false; 104 last_set_needs_begin_frame_ = false;
108 ProcessScheduledActions(); 105 ProcessScheduledActions();
109 } 106 }
110 107
111 base::TimeTicks Scheduler::AnticipatedDrawTime() { 108 base::TimeTicks Scheduler::AnticipatedDrawTime() {
112 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime"); 109 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime");
110
111 // TODO(brianderson): Express this in terms of the deadline.
113 base::TimeTicks now = base::TimeTicks::Now(); 112 base::TimeTicks now = base::TimeTicks::Now();
114 int64 intervals = ((now - last_begin_frame_time_) / interval_) + 1; 113
115 return last_begin_frame_time_ + (interval_ * intervals); 114 if (last_begin_frame_args_.interval() <= base::TimeDelta())
115 return now;
116
117 int64 intervals = 1 + ((now - last_begin_frame_args_.frame_time()) /
118 last_begin_frame_args_.interval());
119 return last_begin_frame_args_.frame_time() +
120 (last_begin_frame_args_.interval() * intervals);
116 } 121 }
117 122
118 base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() { 123 base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() {
119 return last_begin_frame_time_; 124 return last_begin_frame_args_.frame_time();
120 } 125 }
121 126
122 void Scheduler::SetupNextBeginFrameIfNeeded() { 127 void Scheduler::SetupNextBeginFrameIfNeeded() {
123 // Determine if we need BeginFrame notifications. 128 // Determine if we need BeginFrame notifications.
124 // If we do, always request the BeginFrame immediately. 129 // If we do, always request the BeginFrame immediately.
125 // If not, only disable on the next BeginFrame to avoid unnecessary toggles. 130 // If not, only disable on the next BeginFrame to avoid unnecessary toggles.
126 // The synchronous renderer compositor requires immediate disables though. 131 // The synchronous renderer compositor requires immediate disables though.
127 bool needs_begin_frame = state_machine_.BeginFrameNeededByImplThread(); 132 bool needs_begin_frame = state_machine_.BeginFrameNeededByImplThread();
128 if ((needs_begin_frame || 133 if ((needs_begin_frame ||
129 state_machine_.inside_begin_frame() || 134 state_machine_.inside_begin_frame() ||
130 settings_.using_synchronous_renderer_compositor) && 135 settings_.using_synchronous_renderer_compositor) &&
131 (needs_begin_frame != last_set_needs_begin_frame_)) { 136 (needs_begin_frame != last_set_needs_begin_frame_)) {
132 client_->SetNeedsBeginFrameOnImplThread(needs_begin_frame); 137 client_->SetNeedsBeginFrameOnImplThread(needs_begin_frame);
133 last_set_needs_begin_frame_ = needs_begin_frame; 138 last_set_needs_begin_frame_ = needs_begin_frame;
134 } 139 }
135 140
136 // Request another BeginFrame if we haven't drawn for now until we have 141 // Request another BeginFrame if we haven't drawn for now until we have
137 // deadlines implemented. 142 // deadlines implemented.
138 if (state_machine_.inside_begin_frame() && has_pending_begin_frame_) { 143 if (state_machine_.inside_begin_frame() && has_pending_begin_frame_) {
139 has_pending_begin_frame_ = false; 144 has_pending_begin_frame_ = false;
140 client_->SetNeedsBeginFrameOnImplThread(true); 145 client_->SetNeedsBeginFrameOnImplThread(true);
141 } 146 }
142 } 147 }
143 148
144 void Scheduler::BeginFrame(base::TimeTicks frame_time) { 149 void Scheduler::BeginFrame(BeginFrameArgs args) {
145 TRACE_EVENT0("cc", "Scheduler::BeginFrame"); 150 TRACE_EVENT0("cc", "Scheduler::BeginFrame");
151 last_begin_frame_args_ = args;
146 DCHECK(!has_pending_begin_frame_); 152 DCHECK(!has_pending_begin_frame_);
147 has_pending_begin_frame_ = true; 153 has_pending_begin_frame_ = true;
148 last_begin_frame_time_ = frame_time; 154 last_begin_frame_args_ = args;
Sami 2013/06/13 10:01:07 Dupe assignment?
brianderson 2013/06/14 20:12:02 Will fix.
149 state_machine_.DidEnterBeginFrame(); 155 state_machine_.DidEnterBeginFrame(args);
150 state_machine_.SetFrameTime(frame_time);
151 ProcessScheduledActions(); 156 ProcessScheduledActions();
152 state_machine_.DidLeaveBeginFrame(); 157 state_machine_.DidLeaveBeginFrame();
153 } 158 }
154 159
155 void Scheduler::DrawAndSwapIfPossible() { 160 void Scheduler::DrawAndSwapIfPossible() {
156 ScheduledActionDrawAndSwapResult result = 161 ScheduledActionDrawAndSwapResult result =
157 client_->ScheduledActionDrawAndSwapIfPossible(); 162 client_->ScheduledActionDrawAndSwapIfPossible();
158 state_machine_.DidDrawIfPossibleCompleted(result.did_draw); 163 state_machine_.DidDrawIfPossibleCompleted(result.did_draw);
159 if (result.did_swap) 164 if (result.did_swap)
160 has_pending_begin_frame_ = false; 165 has_pending_begin_frame_ = false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 216
212 SetupNextBeginFrameIfNeeded(); 217 SetupNextBeginFrameIfNeeded();
213 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); 218 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
214 } 219 }
215 220
216 bool Scheduler::WillDrawIfNeeded() const { 221 bool Scheduler::WillDrawIfNeeded() const {
217 return !state_machine_.DrawSuspendedUntilCommit(); 222 return !state_machine_.DrawSuspendedUntilCommit();
218 } 223 }
219 224
220 } // namespace cc 225 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698