Skip to content

Commit

Permalink
The current code does a lot of hooking in and out of javascript (afte…
Browse files Browse the repository at this point in the history
…r a timeout) to check if we're done scrolling yet. Instead, this patch will determine how many pixels to scroll right away, and let the C++ handle it from there. This should be simpler code, and should also reduce artificial jank introduced by the test harness.

BUG=155139


Review URL: https://chromiumcodereview.appspot.com/11226004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163154 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hartmanng@chromium.org committed Oct 20, 2012
1 parent 7242938 commit 267909d
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 105 deletions.
7 changes: 3 additions & 4 deletions content/browser/renderer_host/render_widget_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1632,15 +1632,14 @@ void RenderWidgetHostImpl::OnMsgInputEventAck(WebInputEvent::Type event_type,
}

void RenderWidgetHostImpl::OnMsgBeginSmoothScroll(
int gesture_id, bool scroll_down, bool scroll_far, int mouse_event_x,
int mouse_event_y) {
int gesture_id, const ViewHostMsg_BeginSmoothScroll_Params &params) {
if (!view_)
return;
active_smooth_scroll_gestures_.insert(
std::make_pair(gesture_id,
view_->CreateSmoothScrollGesture(
scroll_down, scroll_far, mouse_event_x,
mouse_event_y)));
params.scroll_down, params.pixels_to_scroll,
params.mouse_event_x, params.mouse_event_y)));

// If an input ack is pending, then hold off ticking the gesture
// until we get an input ack.
Expand Down
9 changes: 4 additions & 5 deletions content/browser/renderer_host/render_widget_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class WebCursor;
struct EditCommand;
struct ViewHostMsg_UpdateRect_Params;
struct ViewHostMsg_TextInputState_Params;
struct ViewHostMsg_BeginSmoothScroll_Params;

namespace base {
class TimeTicks;
Expand Down Expand Up @@ -549,11 +550,9 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
void OnMsgUpdateIsDelayed();
void OnMsgInputEventAck(WebKit::WebInputEvent::Type event_type,
bool processed);
void OnMsgBeginSmoothScroll(int gesture_id,
bool scroll_down,
bool scroll_far,
int mouse_event_x,
int mouse_event_y);
void OnMsgBeginSmoothScroll(
int gesture_id,
const ViewHostMsg_BeginSmoothScroll_Params &params);
void OnMsgSelectRangeAck();
virtual void OnMsgFocus();
virtual void OnMsgBlur();
Expand Down
51 changes: 14 additions & 37 deletions content/browser/renderer_host/render_widget_host_view_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@

namespace content {

// How long a smooth scroll gesture should run when it is a near scroll.
static const int64 kDurationOfNearScrollGestureMs = 150;

// How long a smooth scroll gesture should run when it is a far scroll.
static const int64 kDurationOfFarScrollGestureMs = 500;

static const int64 kWheelTicksPerSecond = 1500;

// static
RenderWidgetHostViewPort* RenderWidgetHostViewPort::FromRWHV(
RenderWidgetHostView* rwhv) {
Expand Down Expand Up @@ -418,43 +410,25 @@ void RenderWidgetHostViewBase::UpdateScreenInfo(gfx::NativeView view) {
class BasicMouseWheelSmoothScrollGesture
: public SmoothScrollGesture {
public:
BasicMouseWheelSmoothScrollGesture(bool scroll_down, bool scroll_far,
BasicMouseWheelSmoothScrollGesture(bool scroll_down, int pixels_to_scroll,
int mouse_event_x, int mouse_event_y)
: start_time_(base::TimeTicks::HighResNow()),
last_forward_time_(start_time_),
scroll_down_(scroll_down),
scroll_far_(scroll_far),
: scroll_down_(scroll_down),
pixels_scrolled_(0),
pixels_to_scroll_(pixels_to_scroll),
mouse_event_x_(mouse_event_x),
mouse_event_y_(mouse_event_y) { }

virtual bool ForwardInputEvents(base::TimeTicks now,
RenderWidgetHost* host) OVERRIDE {
int64 duration_in_ms;
if (scroll_far_)
duration_in_ms = kDurationOfFarScrollGestureMs;
else
duration_in_ms = kDurationOfNearScrollGestureMs;

if (now - start_time_ > base::TimeDelta::FromMilliseconds(duration_in_ms))
if (pixels_scrolled_ >= pixels_to_scroll_)
return false;

// Figure out how many wheel ticks to send.
double seconds_since_last_tick = (now - last_forward_time_).InSecondsF();
int num_wheel_ticks = static_cast<int>(
seconds_since_last_tick * kWheelTicksPerSecond);
if (!num_wheel_ticks) {
TRACE_EVENT_INSTANT1("input", "NoMovement",
"seconds_since_last_tick", seconds_since_last_tick);
return true;
}

last_forward_time_ = now;

WebKit::WebMouseWheelEvent event;
event.type = WebKit::WebInputEvent::MouseWheel;
// TODO(nduca): Figure out plausible value.
event.deltaY = scroll_down_ ? -10 : 10;
event.wheelTicksY = (scroll_down_ ? 1 : -1) * num_wheel_ticks;
event.wheelTicksY = (scroll_down_ ? 1 : -1);
event.modifiers = 0;

// TODO(nduca): Figure out plausible x and y values.
Expand All @@ -465,22 +439,25 @@ class BasicMouseWheelSmoothScrollGesture
event.windowX = event.x;
event.windowY = event.y;
host->ForwardWheelEvent(event);

pixels_scrolled_ += abs(event.deltaY);

return true;
}

private:
virtual ~BasicMouseWheelSmoothScrollGesture() { }
base::TimeTicks start_time_;
base::TimeTicks last_forward_time_;
bool scroll_down_;
bool scroll_far_;
int pixels_scrolled_;
int pixels_to_scroll_;
int mouse_event_x_;
int mouse_event_y_;
};

SmoothScrollGesture* RenderWidgetHostViewBase::CreateSmoothScrollGesture(
bool scroll_down, bool scroll_far, int mouse_event_x, int mouse_event_y) {
return new BasicMouseWheelSmoothScrollGesture(scroll_down, scroll_far,
bool scroll_down, int pixels_to_scroll, int mouse_event_x,
int mouse_event_y) {
return new BasicMouseWheelSmoothScrollGesture(scroll_down, pixels_to_scroll,
mouse_event_x, mouse_event_y);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
virtual void ProcessAckedTouchEvent(const WebKit::WebTouchEvent& touch,
bool processed) OVERRIDE;
virtual SmoothScrollGesture* CreateSmoothScrollGesture(
bool scroll_down, bool scroll_far, int mouse_event_x,
bool scroll_down, int pixels_to_scroll, int mouse_event_x,
int mouse_event_y) OVERRIDE;

void SetBrowserAccessibilityManager(BrowserAccessibilityManager* manager);
Expand Down
14 changes: 9 additions & 5 deletions content/common/view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1732,12 +1732,16 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_HandleInputEvent_ACK,
WebKit::WebInputEvent::Type,
bool /* processed */)

IPC_MESSAGE_ROUTED5(ViewHostMsg_BeginSmoothScroll,
IPC_STRUCT_BEGIN(ViewHostMsg_BeginSmoothScroll_Params)
IPC_STRUCT_MEMBER(bool, scroll_down)
IPC_STRUCT_MEMBER(int, pixels_to_scroll)
IPC_STRUCT_MEMBER(int, mouse_event_x)
IPC_STRUCT_MEMBER(int, mouse_event_y)
IPC_STRUCT_END()

IPC_MESSAGE_ROUTED2(ViewHostMsg_BeginSmoothScroll,
int /* gesture_id */,
bool /* scroll_down */,
bool /* scroll_far */,
int /* mouse_event_x */,
int /* mouse_event_y */)
ViewHostMsg_BeginSmoothScroll_Params /* params */)

IPC_MESSAGE_ROUTED0(ViewHostMsg_Focus)
IPC_MESSAGE_ROUTED0(ViewHostMsg_Blur)
Expand Down
2 changes: 1 addition & 1 deletion content/port/browser/render_widget_host_view_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CONTENT_EXPORT RenderWidgetHostViewPort : public RenderWidgetHostView {
// Asks the view to create a smooth scroll gesture that will be used to
// simulate a user-initiated scroll.
virtual SmoothScrollGesture* CreateSmoothScrollGesture(
bool scroll_down, bool scroll_far, int mouse_event_x,
bool scroll_down, int pixels_to_scroll, int mouse_event_x,
int mouse_event_y) = 0;

virtual void SetHasHorizontalScrollbar(bool has_horizontal_scrollbar) = 0;
Expand Down
41 changes: 13 additions & 28 deletions content/renderer/gpu/gpu_benchmarking_extension.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,20 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" native function PrintToSkPicture();"
" return PrintToSkPicture(dirname);"
"};"
"chrome.gpuBenchmarking.beginSmoothScrollSupportsPositioning = true;"
"chrome.gpuBenchmarking.beginSmoothScrollDown = "
" function(scroll_far, opt_callback, opt_mouse_event_x,"
"chrome.gpuBenchmarking.smoothScrollBy = "
" function(pixels_to_scroll, opt_callback, opt_mouse_event_x,"
" opt_mouse_event_y) {"
" scroll_far = scroll_far || false;"
" pixels_to_scroll = pixels_to_scroll || 0;"
" callback = opt_callback || function() { };"
" native function BeginSmoothScroll();"
" if (typeof opt_mouse_event_x !== 'undefined' &&"
" typeof opt_mouse_event_y !== 'undefined') {"
" return BeginSmoothScroll(true, scroll_far, callback,"
" return BeginSmoothScroll(pixels_to_scroll >= 0, callback,"
" Math.abs(pixels_to_scroll),"
" opt_mouse_event_x, opt_mouse_event_y);"
" } else {"
" return BeginSmoothScroll(true, scroll_far, callback);"
" }"
"};"
"chrome.gpuBenchmarking.beginSmoothScrollUp = "
" function(scroll_far, opt_callback, opt_mouse_event_x,"
" opt_mouse_event_y) {"
" scroll_far = scroll_far || false;"
" callback = opt_callback || function() { };"
" native function BeginSmoothScroll();"
" if (typeof opt_mouse_event_x !== 'undefined' &&"
" typeof opt_mouse_event_y !== 'undefined') {"
" return BeginSmoothScroll(false, scroll_far, callback,"
" opt_mouse_event_x, opt_mouse_event_y);"
" } else {"
" return BeginSmoothScroll(false, scroll_far, callback);"
" return BeginSmoothScroll(pixels_to_scroll >= 0, callback,"
" Math.abs(pixels_to_scroll));"
" }"
"};"
"chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {"
Expand Down Expand Up @@ -280,19 +267,20 @@ class GpuBenchmarkingWrapper : public v8::Extension {
int arglen = args.Length();
if (arglen < 3 ||
!args[0]->IsBoolean() ||
!args[1]->IsBoolean() ||
!args[2]->IsFunction())
!args[1]->IsFunction() ||
!args[2]->IsNumber())
return v8::False();

bool scroll_down = args[0]->BooleanValue();
bool scroll_far = args[1]->BooleanValue();
v8::Local<v8::Function> callback_local =
v8::Local<v8::Function>(v8::Function::Cast(*args[2]));
v8::Local<v8::Function>(v8::Function::Cast(*args[1]));
v8::Persistent<v8::Function> callback =
v8::Persistent<v8::Function>::New(callback_local);
v8::Persistent<v8::Context> context =
v8::Persistent<v8::Context>::New(web_frame->mainWorldScriptContext());

int pixels_to_scroll = args[2]->IntegerValue();

int mouse_event_x = 0;
int mouse_event_y = 0;

Expand All @@ -302,9 +290,6 @@ class GpuBenchmarkingWrapper : public v8::Extension {
mouse_event_y = rect.y + rect.height / 2;
} else {
if (arglen != 5 ||
!args[0]->IsBoolean() ||
!args[1]->IsBoolean() ||
!args[2]->IsFunction() ||
!args[3]->IsNumber() ||
!args[4]->IsNumber())
return v8::False();
Expand All @@ -318,10 +303,10 @@ class GpuBenchmarkingWrapper : public v8::Extension {
// somehow.
render_view_impl->BeginSmoothScroll(
scroll_down,
scroll_far,
base::Bind(&OnSmoothScrollCompleted,
callback,
context),
pixels_to_scroll,
mouse_event_x,
mouse_event_y);

Expand Down
12 changes: 9 additions & 3 deletions content/renderer/render_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1877,14 +1877,20 @@ bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {

void RenderWidget::BeginSmoothScroll(
bool down,
bool scroll_far,
const SmoothScrollCompletionCallback& callback,
int pixels_to_scroll,
int mouse_event_x,
int mouse_event_y) {
DCHECK(!callback.is_null());
int id = next_smooth_scroll_gesture_id_++;
Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, down, scroll_far,
mouse_event_x, mouse_event_y));

ViewHostMsg_BeginSmoothScroll_Params params;
params.scroll_down = down;
params.pixels_to_scroll = pixels_to_scroll;
params.mouse_event_x = mouse_event_x;
params.mouse_event_y = mouse_event_y;

Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
}

Expand Down
2 changes: 1 addition & 1 deletion content/renderer/render_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ class CONTENT_EXPORT RenderWidget
// performance characteristics as a user-initiated scroll. Returns an ID of
// the scroll gesture.
void BeginSmoothScroll(bool scroll_down,
bool scroll_far,
const SmoothScrollCompletionCallback& callback,
int pixels_to_scroll,
int mouse_event_x,
int mouse_event_y);

Expand Down
26 changes: 6 additions & 20 deletions tools/perf/perf_tools/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,17 @@
return r;
};

function rectsDoIntersect(r1, r2) {
return (r1.right >= r2.left &&
r1.left <= r2.right &&
r1.bottom >= r2.top &&
r1.top <= r2.bottom);
};

SmoothScrollDownGesture.prototype.start = function(callback) {
this.callback_ = callback;
if (chrome &&
chrome.gpuBenchmarking &&
chrome.gpuBenchmarking.beginSmoothScrollDown) {
chrome.gpuBenchmarking.smoothScrollBy) {
rect = getBoundingVisibleRect(this.element_);
if (chrome.gpuBenchmarking.beginSmoothScrollSupportsPositioning ||
rectsDoIntersect(rect, {left: 0,
top: 0,
right: 1,
bottom: 1,
height: 1,
width: 1})) {
chrome.gpuBenchmarking.beginSmoothScrollDown(true, function() {
callback();
}, rect.left + rect.width / 2, rect.top + rect.height / 2);
return;
}
chrome.gpuBenchmarking.smoothScrollBy(
this.element_.scrollHeight, function() {
callback();
}, rect.left + rect.width / 2, rect.top + rect.height / 2);
return;
}

var SCROLL_DELTA = 100;
Expand Down

0 comments on commit 267909d

Please sign in to comment.