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

Side by Side Diff: cc/delay_based_time_source.cc

Issue 11344004: Remove WebKit::Platform dependencies from cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix webkit_compositor_bindings_unittests Created 8 years, 1 month 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
« no previous file with comments | « cc/delay_based_time_source.h ('k') | cc/frame_rate_controller.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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/delay_based_time_source.h" 7 #include "cc/delay_based_time_source.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
11 11
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h"
15 #include "cc/thread.h"
14 16
15 namespace cc { 17 namespace cc {
16 18
17 namespace { 19 namespace {
18 20
19 // doubleTickThreshold prevents ticks from running within the specified fraction of an interval. 21 // doubleTickThreshold prevents ticks from running within the specified fraction of an interval.
20 // This helps account for jitter in the timebase as well as quick timer reactiva tion. 22 // This helps account for jitter in the timebase as well as quick timer reactiva tion.
21 const double doubleTickThreshold = 0.25; 23 const double doubleTickThreshold = 0.25;
22 24
23 // intervalChangeThreshold is the fraction of the interval that will trigger an immediate interval change. 25 // intervalChangeThreshold is the fraction of the interval that will trigger an immediate interval change.
24 // phaseChangeThreshold is the fraction of the interval that will trigger an imm ediate phase change. 26 // phaseChangeThreshold is the fraction of the interval that will trigger an imm ediate phase change.
25 // If the changes are within the thresholds, the change will take place on the n ext tick. 27 // If the changes are within the thresholds, the change will take place on the n ext tick.
26 // If either change is outside the thresholds, the next tick will be canceled an d reissued immediately. 28 // If either change is outside the thresholds, the next tick will be canceled an d reissued immediately.
27 const double intervalChangeThreshold = 0.25; 29 const double intervalChangeThreshold = 0.25;
28 const double phaseChangeThreshold = 0.25; 30 const double phaseChangeThreshold = 0.25;
29 31
30 } // namespace 32 } // namespace
31 33
32 scoped_refptr<DelayBasedTimeSource> DelayBasedTimeSource::create(base::TimeDelta interval, Thread* thread) 34 scoped_refptr<DelayBasedTimeSource> DelayBasedTimeSource::create(base::TimeDelta interval, Thread* thread)
33 { 35 {
34 return make_scoped_refptr(new DelayBasedTimeSource(interval, thread)); 36 return make_scoped_refptr(new DelayBasedTimeSource(interval, thread));
35 } 37 }
36 38
37 DelayBasedTimeSource::DelayBasedTimeSource(base::TimeDelta interval, Thread* thr ead) 39 DelayBasedTimeSource::DelayBasedTimeSource(base::TimeDelta interval, Thread* thr ead)
38 : m_client(0) 40 : m_client(0)
39 , m_hasTickTarget(false) 41 , m_hasTickTarget(false)
40 , m_currentParameters(interval, base::TimeTicks()) 42 , m_currentParameters(interval, base::TimeTicks())
41 , m_nextParameters(interval, base::TimeTicks()) 43 , m_nextParameters(interval, base::TimeTicks())
42 , m_state(STATE_INACTIVE) 44 , m_state(STATE_INACTIVE)
43 , m_timer(thread, this) 45 , m_thread(thread)
46 , m_weakFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this))
44 { 47 {
45 } 48 }
46 49
47 DelayBasedTimeSource::~DelayBasedTimeSource() 50 DelayBasedTimeSource::~DelayBasedTimeSource()
48 { 51 {
49 } 52 }
50 53
51 void DelayBasedTimeSource::setActive(bool active) 54 void DelayBasedTimeSource::setActive(bool active)
52 { 55 {
53 TRACE_EVENT1("cc", "DelayBasedTimeSource::setActive", "active", active); 56 TRACE_EVENT1("cc", "DelayBasedTimeSource::setActive", "active", active);
54 if (!active) { 57 if (!active) {
55 m_state = STATE_INACTIVE; 58 m_state = STATE_INACTIVE;
56 m_timer.stop(); 59 m_weakFactory.InvalidateWeakPtrs();
57 return; 60 return;
58 } 61 }
59 62
60 if (m_state == STATE_STARTING || m_state == STATE_ACTIVE) 63 if (m_state == STATE_STARTING || m_state == STATE_ACTIVE)
61 return; 64 return;
62 65
63 if (!m_hasTickTarget) { 66 if (!m_hasTickTarget) {
64 // Becoming active the first time is deferred: we post a 0-delay task. W hen 67 // Becoming active the first time is deferred: we post a 0-delay task. W hen
65 // it runs, we use that to establish the timebase, become truly active, and 68 // it runs, we use that to establish the timebase, become truly active, and
66 // fire the first tick. 69 // fire the first tick.
67 m_state = STATE_STARTING; 70 m_state = STATE_STARTING;
68 m_timer.startOneShot(0); 71 m_thread->postTask(base::Bind(&DelayBasedTimeSource::onTimerFired, m_wea kFactory.GetWeakPtr()));
69 return; 72 return;
70 } 73 }
71 74
72 m_state = STATE_ACTIVE; 75 m_state = STATE_ACTIVE;
73 76
74 postNextTickTask(now()); 77 postNextTickTask(now());
75 } 78 }
76 79
77 bool DelayBasedTimeSource::active() const 80 bool DelayBasedTimeSource::active() const
78 { 81 {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 218 }
216 219
217 void DelayBasedTimeSource::postNextTickTask(base::TimeTicks now) 220 void DelayBasedTimeSource::postNextTickTask(base::TimeTicks now)
218 { 221 {
219 base::TimeTicks newTickTarget = nextTickTarget(now); 222 base::TimeTicks newTickTarget = nextTickTarget(now);
220 223
221 // Post another task *before* the tick and update state 224 // Post another task *before* the tick and update state
222 base::TimeDelta delay = newTickTarget - now; 225 base::TimeDelta delay = newTickTarget - now;
223 DCHECK(delay.InMillisecondsF() <= 226 DCHECK(delay.InMillisecondsF() <=
224 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh old)); 227 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh old));
225 m_timer.startOneShot(delay.InSecondsF()); 228 m_thread->postDelayedTask(base::Bind(&DelayBasedTimeSource::onTimerFired,
229 m_weakFactory.GetWeakPtr()),
230 delay.InMilliseconds());
226 231
227 m_nextParameters.tickTarget = newTickTarget; 232 m_nextParameters.tickTarget = newTickTarget;
228 m_currentParameters = m_nextParameters; 233 m_currentParameters = m_nextParameters;
229 } 234 }
230 235
231 } // namespace cc 236 } // namespace cc
OLDNEW
« no previous file with comments | « cc/delay_based_time_source.h ('k') | cc/frame_rate_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698