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

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: Rebase 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
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_state_machine.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_.BeginFrameNeededToDrawByImplThread()); 24 DCHECK(!state_machine_.BeginFrameNeededToDrawByImplThread());
28 } 25 }
29 26
30 Scheduler::~Scheduler() { 27 Scheduler::~Scheduler() {
31 client_->SetNeedsBeginFrameOnImplThread(false); 28 client_->SetNeedsBeginFrameOnImplThread(false);
32 } 29 }
33 30
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 safe_to_expect_begin_frame_ = false; 105 safe_to_expect_begin_frame_ = false;
109 ProcessScheduledActions(); 106 ProcessScheduledActions();
110 } 107 }
111 108
112 base::TimeTicks Scheduler::AnticipatedDrawTime() { 109 base::TimeTicks Scheduler::AnticipatedDrawTime() {
113 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime"); 110 TRACE_EVENT0("cc", "Scheduler::AnticipatedDrawTime");
114 if (!last_set_needs_begin_frame_) 111
112 if (!last_set_needs_begin_frame_ ||
113 last_begin_frame_args_.interval <= base::TimeDelta())
115 return base::TimeTicks(); 114 return base::TimeTicks();
116 115
116 // TODO(brianderson): Express this in terms of the deadline.
117 base::TimeTicks now = base::TimeTicks::Now(); 117 base::TimeTicks now = base::TimeTicks::Now();
118 int64 intervals = ((now - last_begin_frame_time_) / interval_) + 1; 118 int64 intervals = 1 + ((now - last_begin_frame_args_.frame_time) /
119 return last_begin_frame_time_ + (interval_ * intervals); 119 last_begin_frame_args_.interval);
120 return last_begin_frame_args_.frame_time +
121 (last_begin_frame_args_.interval * intervals);
120 } 122 }
121 123
122 base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() { 124 base::TimeTicks Scheduler::LastBeginFrameOnImplThreadTime() {
123 return last_begin_frame_time_; 125 return last_begin_frame_args_.frame_time;
124 } 126 }
125 127
126 void Scheduler::SetupNextBeginFrameIfNeeded() { 128 void Scheduler::SetupNextBeginFrameIfNeeded() {
127 bool needs_begin_frame_to_draw = 129 bool needs_begin_frame_to_draw =
128 state_machine_.BeginFrameNeededToDrawByImplThread(); 130 state_machine_.BeginFrameNeededToDrawByImplThread();
129 // We want to avoid proactive begin frames with the synchronous compositor 131 // We want to avoid proactive begin frames with the synchronous compositor
130 // because every SetNeedsBeginFrame will force a redraw. 132 // because every SetNeedsBeginFrame will force a redraw.
131 bool proactive_begin_frame_wanted = 133 bool proactive_begin_frame_wanted =
132 state_machine_.ProactiveBeginFrameWantedByImplThread() && 134 state_machine_.ProactiveBeginFrameWantedByImplThread() &&
133 !settings_.using_synchronous_renderer_compositor; 135 !settings_.using_synchronous_renderer_compositor;
(...skipping 21 matching lines...) Expand all
155 157
156 // Request another BeginFrame if we haven't drawn for now until we have 158 // Request another BeginFrame if we haven't drawn for now until we have
157 // deadlines implemented. 159 // deadlines implemented.
158 if (state_machine_.inside_begin_frame() && has_pending_begin_frame_) { 160 if (state_machine_.inside_begin_frame() && has_pending_begin_frame_) {
159 has_pending_begin_frame_ = false; 161 has_pending_begin_frame_ = false;
160 client_->SetNeedsBeginFrameOnImplThread(true); 162 client_->SetNeedsBeginFrameOnImplThread(true);
161 return; 163 return;
162 } 164 }
163 } 165 }
164 166
165 void Scheduler::BeginFrame(base::TimeTicks frame_time) { 167 void Scheduler::BeginFrame(const BeginFrameArgs& args) {
166 TRACE_EVENT0("cc", "Scheduler::BeginFrame"); 168 TRACE_EVENT0("cc", "Scheduler::BeginFrame");
167 DCHECK(!has_pending_begin_frame_); 169 DCHECK(!has_pending_begin_frame_);
168 has_pending_begin_frame_ = true; 170 has_pending_begin_frame_ = true;
169 last_begin_frame_time_ = frame_time;
170 safe_to_expect_begin_frame_ = true; 171 safe_to_expect_begin_frame_ = true;
171 state_machine_.DidEnterBeginFrame(); 172 last_begin_frame_args_ = args;
172 state_machine_.SetFrameTime(frame_time); 173 state_machine_.DidEnterBeginFrame(args);
173 ProcessScheduledActions(); 174 ProcessScheduledActions();
174 state_machine_.DidLeaveBeginFrame(); 175 state_machine_.DidLeaveBeginFrame();
175 } 176 }
176 177
177 void Scheduler::DrawAndSwapIfPossible() { 178 void Scheduler::DrawAndSwapIfPossible() {
178 ScheduledActionDrawAndSwapResult result = 179 ScheduledActionDrawAndSwapResult result =
179 client_->ScheduledActionDrawAndSwapIfPossible(); 180 client_->ScheduledActionDrawAndSwapIfPossible();
180 state_machine_.DidDrawIfPossibleCompleted(result.did_draw); 181 state_machine_.DidDrawIfPossibleCompleted(result.did_draw);
181 if (result.did_swap) 182 if (result.did_swap)
182 has_pending_begin_frame_ = false; 183 has_pending_begin_frame_ = false;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 234
234 SetupNextBeginFrameIfNeeded(); 235 SetupNextBeginFrameIfNeeded();
235 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime()); 236 client_->DidAnticipatedDrawTimeChange(AnticipatedDrawTime());
236 } 237 }
237 238
238 bool Scheduler::WillDrawIfNeeded() const { 239 bool Scheduler::WillDrawIfNeeded() const {
239 return !state_machine_.DrawSuspendedUntilCommit(); 240 return !state_machine_.DrawSuspendedUntilCommit();
240 } 241 }
241 242
242 } // namespace cc 243 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.h ('k') | cc/scheduler/scheduler_state_machine.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698