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

Side by Side Diff: content/child/web_gesture_curve_impl.cc

Issue 764403002: Expand UMA coverage for compositor-handled events and fling FPS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build Created 6 years 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 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 "base/metrics/histogram.h"
8 #include "third_party/WebKit/public/platform/WebFloatSize.h" 9 #include "third_party/WebKit/public/platform/WebFloatSize.h"
9 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h" 10 #include "third_party/WebKit/public/platform/WebGestureCurveTarget.h"
10 #include "ui/events/gestures/fling_curve.h" 11 #include "ui/events/gestures/fling_curve.h"
11 #include "ui/gfx/vector2d.h" 12 #include "ui/gfx/geometry/safe_integer_conversions.h"
13 #include "ui/gfx/geometry/vector2d.h"
12 14
13 #if defined(OS_ANDROID) 15 #if defined(OS_ANDROID)
14 #include "ui/events/android/scroller.h" 16 #include "ui/events/android/scroller.h"
15 #endif 17 #endif
16 18
17 using blink::WebGestureCurve; 19 using blink::WebGestureCurve;
18 20
19 namespace content { 21 namespace content {
20 namespace { 22 namespace {
21 23
(...skipping 16 matching lines...) Expand all
38 return make_scoped_ptr( 40 return make_scoped_ptr(
39 new ui::FlingCurve(initial_velocity, base::TimeTicks())); 41 new ui::FlingCurve(initial_velocity, base::TimeTicks()));
40 #endif 42 #endif
41 } 43 }
42 44
43 } // namespace 45 } // namespace
44 46
45 // static 47 // static
46 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve( 48 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
47 const gfx::Vector2dF& initial_velocity, 49 const gfx::Vector2dF& initial_velocity,
48 const gfx::Vector2dF& initial_offset) { 50 const gfx::Vector2dF& initial_offset,
49 return CreateFrom(CreateDefaultPlatformCurve(initial_velocity), 51 bool on_main_thread) {
50 initial_offset); 52 return scoped_ptr<WebGestureCurve>(new WebGestureCurveImpl(
53 CreateDefaultPlatformCurve(initial_velocity), initial_offset,
54 on_main_thread ? ThreadType::MAIN : ThreadType::IMPL));
51 } 55 }
52 56
53 // static 57 // static
54 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFrom( 58 scoped_ptr<WebGestureCurve> WebGestureCurveImpl::CreateFromUICurveForTesting(
55 scoped_ptr<ui::GestureCurve> curve, 59 scoped_ptr<ui::GestureCurve> curve,
56 const gfx::Vector2dF& initial_offset) { 60 const gfx::Vector2dF& initial_offset) {
57 return scoped_ptr<WebGestureCurve>( 61 return scoped_ptr<WebGestureCurve>(
58 new WebGestureCurveImpl(curve.Pass(), initial_offset)); 62 new WebGestureCurveImpl(curve.Pass(), initial_offset, ThreadType::TEST));
59 } 63 }
60 64
61 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<ui::GestureCurve> curve, 65 WebGestureCurveImpl::WebGestureCurveImpl(scoped_ptr<ui::GestureCurve> curve,
62 const gfx::Vector2dF& initial_offset) 66 const gfx::Vector2dF& initial_offset,
63 : curve_(curve.Pass()), last_offset_(initial_offset) { 67 ThreadType animating_thread_type)
68 : curve_(curve.Pass()),
69 last_offset_(initial_offset),
70 animating_thread_type_(animating_thread_type),
71 ticks_since_first_animate_(0),
72 first_animate_time_(0),
73 last_animate_time_(0) {
64 } 74 }
65 75
66 WebGestureCurveImpl::~WebGestureCurveImpl() { 76 WebGestureCurveImpl::~WebGestureCurveImpl() {
77 if (ticks_since_first_animate_ <= 1)
78 return;
79
80 if (last_animate_time_ <= first_animate_time_)
81 return;
82
83 switch (animating_thread_type_) {
84 case ThreadType::MAIN:
85 UMA_HISTOGRAM_CUSTOM_COUNTS(
86 "Event.Frequency.Renderer.FlingAnimate",
87 gfx::ToRoundedInt(ticks_since_first_animate_ /
88 (last_animate_time_ - first_animate_time_)),
89 1, 240, 120);
90 break;
91 case ThreadType::IMPL:
92 UMA_HISTOGRAM_CUSTOM_COUNTS(
93 "Event.Frequency.RendererImpl.FlingAnimate",
94 gfx::ToRoundedInt(ticks_since_first_animate_ /
95 (last_animate_time_ - first_animate_time_)),
96 1, 240, 120);
97 break;
98 case ThreadType::TEST:
99 break;
100 }
67 } 101 }
68 102
69 bool WebGestureCurveImpl::apply(double time, 103 bool WebGestureCurveImpl::apply(double time,
70 blink::WebGestureCurveTarget* target) { 104 blink::WebGestureCurveTarget* target) {
71 // If the fling has yet to start, simply return and report true to prevent 105 // If the fling has yet to start, simply return and report true to prevent
72 // fling termination. 106 // fling termination.
73 if (time <= 0) 107 if (time <= 0)
74 return true; 108 return true;
75 109
110 if (!first_animate_time_) {
111 first_animate_time_ = last_animate_time_ = time;
112 } else if (time != last_animate_time_) {
113 // Animation can occur multiple times a frame, but with the same timestamp.
114 // Suppress recording of such redundant animate calls, avoiding artificially
115 // inflated FPS computation.
116 last_animate_time_ = time;
117 ++ticks_since_first_animate_;
118 }
119
76 const base::TimeTicks time_ticks = 120 const base::TimeTicks time_ticks =
77 base::TimeTicks() + base::TimeDelta::FromSecondsD(time); 121 base::TimeTicks() + base::TimeDelta::FromSecondsD(time);
78 gfx::Vector2dF offset, velocity; 122 gfx::Vector2dF offset, velocity;
79 bool still_active = 123 bool still_active =
80 curve_->ComputeScrollOffset(time_ticks, &offset, &velocity); 124 curve_->ComputeScrollOffset(time_ticks, &offset, &velocity);
81 125
82 gfx::Vector2dF delta = offset - last_offset_; 126 gfx::Vector2dF delta = offset - last_offset_;
83 last_offset_ = offset; 127 last_offset_ = offset;
84 128
85 // As successive timestamps can be arbitrarily close (but monotonic!), don't 129 // As successive timestamps can be arbitrarily close (but monotonic!), don't
86 // assume that a zero delta means the curve has terminated. 130 // assume that a zero delta means the curve has terminated.
87 if (delta.IsZero()) 131 if (delta.IsZero())
88 return still_active; 132 return still_active;
89 133
90 // scrollBy() could delete this curve if the animation is over, so don't touch 134 // scrollBy() could delete this curve if the animation is over, so don't touch
91 // any member variables after making that call. 135 // any member variables after making that call.
92 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta), 136 bool did_scroll = target->scrollBy(blink::WebFloatSize(delta),
93 blink::WebFloatSize(velocity)); 137 blink::WebFloatSize(velocity));
94 return did_scroll && still_active; 138 return did_scroll && still_active;
95 } 139 }
96 140
97 } // namespace content 141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698