diff options
author | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-09 04:59:15 +0000 |
---|---|---|
committer | bulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-09 04:59:15 +0000 |
commit | a252c67975257f2fed7008b13ef629cfe8021ff0 (patch) | |
tree | 7ca52548ab0a41bdc4986f1ff5586ed21e510621 /content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc | |
parent | aef1af4b193560aa51e9aaa858ae41a7e92b5c3a (diff) | |
download | chromium_src-a252c67975257f2fed7008b13ef629cfe8021ff0.zip chromium_src-a252c67975257f2fed7008b13ef629cfe8021ff0.tar.gz chromium_src-a252c67975257f2fed7008b13ef629cfe8021ff0.tar.bz2 |
Relands: Telemetry: hooks "chrome.gpuBenchmarking.smoothScrollBy" with java on android.
In order to provide more realistic benchmarks, instead of shortcutting in native via mousewheels,
let Telemetry cross all the boundaries and synthesize MotionEvents all the way up in java.
(relands after r173752 reverted https://codereview.chromium.org/11415227/)
BUG=166521,168599
TEST=tools/perf/run_multipage_benchmarks --browser=android-content-shell scrolling_benchmark tools/perf/page_sets/top_25.json
Review URL: https://chromiumcodereview.appspot.com/11793003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc')
-rw-r--r-- | content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc b/content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc new file mode 100644 index 0000000..c504f6c --- /dev/null +++ b/content/browser/renderer_host/touch_smooth_scroll_gesture_android.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/renderer_host/touch_smooth_scroll_gesture_android.h" + +#include "base/debug/trace_event.h" +#include "content/browser/renderer_host/render_widget_host_impl.h" +#include "jni/SmoothScroller_jni.h" + +namespace { +bool g_jni_initialized = false; + +void RegisterNativesIfNeeded(JNIEnv* env) { + if (!g_jni_initialized) { + content::RegisterNativesImpl(env); + g_jni_initialized = true; + } +} +} // namespace + +namespace content { + +TouchSmoothScrollGestureAndroid::TouchSmoothScrollGestureAndroid( + int pixels_to_scroll, + RenderWidgetHost* rwh, + base::android::ScopedJavaLocalRef<jobject> java_scroller) + : pixels_scrolled_(0), + has_started_(false), + has_sent_motion_up_(false), + pixels_to_scroll_(pixels_to_scroll), + rwh_(rwh), + java_scroller_(java_scroller) { + JNIEnv* env = base::android::AttachCurrentThread(); + RegisterNativesIfNeeded(env); +} + +TouchSmoothScrollGestureAndroid::~TouchSmoothScrollGestureAndroid() { +} + +bool TouchSmoothScrollGestureAndroid::ForwardInputEvents( + base::TimeTicks now, RenderWidgetHost* host) { + if (!has_started_) { + has_started_ = true; + JNIEnv* env = base::android::AttachCurrentThread(); + Java_SmoothScroller_start( + env, java_scroller_.obj(), reinterpret_cast<int>(this)); + } + + TRACE_COUNTER_ID1( + "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_); + + return !has_sent_motion_up_; +} + +double TouchSmoothScrollGestureAndroid::GetScrollDelta( + JNIEnv* env, jobject obj, double scale) { + double delta = smooth_scroll_calculator_.GetScrollDelta( + base::TimeTicks::Now(), + RenderWidgetHostImpl::From(rwh_)->GetSyntheticScrollMessageInterval()) + * scale; + pixels_scrolled_ += delta; + return delta; +} + +bool TouchSmoothScrollGestureAndroid::HasFinished(JNIEnv* env, jobject obj) { + return pixels_scrolled_ >= pixels_to_scroll_; +} + +void TouchSmoothScrollGestureAndroid::SetHasSentMotionUp( + JNIEnv* env, jobject obj) { + has_sent_motion_up_ = true; +} + +} // namespace content |