OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/web_gesture_curve_impl.h" | 5 #include "content/child/web_gesture_curve_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 8 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" | 9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" |
10 #include "ui/events/gestures/fling_curve.h" | 10 #include "ui/events/gestures/fling_curve.h" |
11 #include "ui/gfx/vector2d.h" | 11 #include "ui/gfx/geometry/safe_integer_conversions.h" |
12 #include "ui/gfx/geometry/vector2d.h" | |
12 | 13 |
13 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
14 #include "ui/events/android/scroller.h" | 15 #include "ui/events/android/scroller.h" |
15 #endif | 16 #endif |
16 | 17 |
17 using blink::WebGestureCurve; | 18 using blink::WebGestureCurve; |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 namespace { | 21 namespace { |
21 | 22 |
(...skipping 16 matching lines...) Expand all Loading... | |
38 return make_scoped_ptr( | 39 return make_scoped_ptr( |
39 new ui::FlingCurve(initial_velocity, base::TimeTicks())); | 40 new ui::FlingCurve(initial_velocity, base::TimeTicks())); |
40 #endif | 41 #endif |
41 } | 42 } |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 // static | 46 // static |
46 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( | 47 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( |
47 const gfx::Vector2dF& initial_velocity, | 48 const gfx::Vector2dF& initial_velocity, |
48 const gfx::Vector2dF& initial_offset) { | 49 const gfx::Vector2dF& initial_offset, |
49 return CreateFrom(CreateDefaultPlatformCurve(initial_velocity), | 50 bool on_main_thread) { |
50 initial_offset); | 51 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl( |
52 CreateDefaultPlatformCurve(initial_velocity), initial_offset, | |
53 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL)); | |
51 } | 54 } |
52 | 55 |
53 // static | 56 // static |
54 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFrom( | 57 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting( |
55 scoped_ptr<ui::GestureCurve> curve, | 58 scoped_ptr<ui::GestureCurve> curve, |
56 const gfx::Vector2dF& initial_offset) { | 59 const gfx::Vector2dF& initial_offset) { |
57 return scoped_ptr<WebGestureCurve>( | 60 return scoped_ptr<WebGestureCurve>( |
58 new WebGestureCurveImpl(curve.Pass(), initial_offset)); | 61 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST)); |
59 } | 62 } |
60 | 63 |
61 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<ui::GestureCurve> curve, | 64 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<ui::GestureCurve> curve, |
62 const gfx::Vector2dF& initial_offset) | 65 const gfx::Vector2dF& initial_offset, |
63 : curve_(curve.Pass()), last_offset_(initial_offset) { | 66 ThreadType animating_thread_type) |
67 : curve_(curve.Pass()), | |
68 last_offset_(initial_offset), | |
69 animating_thread_type_(animating_thread_type), | |
70 ticks_since_first_animate_(0), | |
71 first_animate_time_(0), | |
72 last_animate_time_(0) { | |
64 } | 73 } |
65 | 74 |
66 WebGestureCurveImpl::~WebGestureCurveImpl() { | 75 WebGestureCurveImpl::~WebGestureCurveImpl() { |
76 if (ticks_since_first_animate_ <= 1) | |
77 return; | |
78 | |
79 if (first_animate_time_ >= last_animate_time_) | |
80 return; | |
81 | |
82 switch (animating_thread_type_) { | |
83 case ThreadType::MAIN: | |
84 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
85 "Event.FPS.Renderer.Fling", | |
86 gfx::ToRoundedInt(ticks_since_first_animate_ / | |
87 (last_animate_time_ - first_animate_time_)), | |
88 1, 200, 100); | |
jdduke (slow)
2014/12/01 18:20:59
Any thoughts on bucket extents/count?
Yufeng Shen (Slow to review)
2014/12/01 18:57:07
You can try a few test flings on your device and c
jdduke (slow)
2014/12/01 20:20:28
Well, it *should* be capped by the refresh rate, s
Yufeng Shen (Slow to review)
2014/12/01 20:40:14
Do we push out frames as whatever the display refr
| |
89 break; | |
90 case ThreadType::IMPL: | |
91 UMA_HISTOGRAM_CUSTOM_COUNTS( | |
92 "Event.FPS.RendererImpl.Fling", | |
jdduke (slow)
2014/12/01 18:20:59
Also not sure about the preferred naming scheme...
Rick Byers
2014/12/01 19:47:10
We have Event.Latency.* for all latency measures.
jdduke (slow)
2014/12/01 20:20:29
Yeah, frequency is a nice name for this family.
| |
93 gfx::ToRoundedInt(ticks_since_first_animate_ / | |
94 (last_animate_time_ - first_animate_time_)), | |
95 1, 200, 100); | |
96 break; | |
97 case ThreadType::TEST: | |
98 break; | |
99 } | |
67 } | 100 } |
68 | 101 |
69 bool WebGestureCurveImpl::apply(double time, | 102 bool WebGestureCurveImpl::apply(double time, |
70 blink::WebGestureCurveTarget* target) { | 103 blink::WebGestureCurveTarget* target) { |
71 // If the fling has yet to start, simply return and report true to prevent | 104 // If the fling has yet to start, simply return and report true to prevent |
72 // fling termination. | 105 // fling termination. |
73 if (time <= 0) | 106 if (time <= 0) |
74 return true; | 107 return true; |
75 | 108 |
109 if (!first_animate_time_) { | |
110 first_animate_time_ = time; | |
111 } else if (time != last_animate_time_) { | |
112 // Animation can occur multiple times a frame, but with the same timestamp. | |
113 // Suppress recording of such redundant animate calls, avoiding artificially | |
Yufeng Shen (Slow to review)
2014/12/01 18:57:07
If this is true, do you want to also guard against
jdduke (slow)
2014/12/01 20:20:28
Good catch, done.
| |
114 // inflated FPS computation. | |
115 last_animate_time_ = time; | |
116 ++ticks_since_first_animate_; | |
117 } | |
118 | |
76 const base::TimeTicks time_ticks = | 119 const base::TimeTicks time_ticks = |
77 base::TimeTicks() + base::TimeDelta::FromSecondsD(time); | 120 base::TimeTicks() + base::TimeDelta::FromSecondsD(time); |
78 gfx::Vector2dF offset, velocity; | 121 gfx::Vector2dF offset, velocity; |
79 bool still_active = | 122 bool still_active = |
80 curve_->ComputeScrollOffset(time_ticks, &offset, &velocity); | 123 curve_->ComputeScrollOffset(time_ticks, &offset, &velocity); |
81 | 124 |
82 gfx::Vector2dF delta = offset - last_offset_; | 125 gfx::Vector2dF delta = offset - last_offset_; |
83 last_offset_ = offset; | 126 last_offset_ = offset; |
84 | 127 |
85 // As successive timestamps can be arbitrarily close (but monotonic!), don't | 128 // As successive timestamps can be arbitrarily close (but monotonic!), don't |
86 // assume that a zero delta means the curve has terminated. | 129 // assume that a zero delta means the curve has terminated. |
87 if (delta.IsZero()) | 130 if (delta.IsZero()) |
88 return still_active; | 131 return still_active; |
89 | 132 |
90 // scrollBy() could delete this curve if the animation is over, so don't touch | 133 // scrollBy() could delete this curve if the animation is over, so don't touch |
91 // any member variables after making that call. | 134 // any member variables after making that call. |
92 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), | 135 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), |
93 blink::WebFloatSize(velocity)); | 136 blink::WebFloatSize(velocity)); |
94 return did_scroll && still_active; | 137 return did_scroll && still_active; |
95 } | 138 } |
96 | 139 |
97 } // namespace content | 140 } // namespace content |
OLD | NEW |