Chromium Code Reviews| Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
| diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc |
| index 1cabf083f5f5f9ef6763f6b639c883950ee1dfe1..5acdb1945025d2eed26208ef8758ce697bffd136 100644 |
| --- a/content/renderer/gpu/gpu_benchmarking_extension.cc |
| +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc |
| @@ -337,7 +337,9 @@ bool BeginSmoothScroll(v8::Isolate* isolate, |
| float speed_in_pixels_s, |
| bool prevent_fling, |
| float start_x, |
| - float start_y) { |
| + float start_y, |
| + float velocity_x = 0, |
| + float velocity_y = 0) { |
| GpuBenchmarkingContext context; |
| if (!context.Init(false)) |
| return false; |
| @@ -383,32 +385,58 @@ bool BeginSmoothScroll(v8::Isolate* isolate, |
| start_y * page_scale_factor); |
| float distance_length = pixels_to_scroll * page_scale_factor; |
| + |
| + bool set_velocity = |
| + gesture_source_type == SyntheticGestureParams::MOUSE_INPUT && |
| + !prevent_fling; |
| + |
| + if (set_velocity && !velocity_x && !velocity_y) |
| + return false; |
| + |
| + gfx::Vector2dF velocity(0, 0); |
| gfx::Vector2dF distance; |
| - if (direction == "down") |
| + |
| + if (direction == "down") { |
| distance.set_y(-distance_length); |
| - else if (direction == "up") |
| + velocity.set_y(-velocity_y); |
| + } else if (direction == "up") { |
| distance.set_y(distance_length); |
| - else if (direction == "right") |
| + velocity.set_y(velocity_y); |
| + } else if (direction == "right") { |
| distance.set_x(-distance_length); |
| - else if (direction == "left") |
| + velocity.set_x(-velocity_x); |
| + } else if (direction == "left") { |
| distance.set_x(distance_length); |
| - else if (direction == "upleft") { |
| + velocity.set_x(velocity_x); |
| + } else if (direction == "upleft") { |
| distance.set_y(distance_length); |
| distance.set_x(distance_length); |
| + velocity.set_y(velocity_y); |
| + velocity.set_x(velocity_x); |
| } else if (direction == "upright") { |
| distance.set_y(distance_length); |
| distance.set_x(-distance_length); |
| + velocity.set_y(velocity_y); |
| + velocity.set_x(-velocity_x); |
| } else if (direction == "downleft") { |
| distance.set_y(-distance_length); |
| distance.set_x(distance_length); |
| + velocity.set_y(-velocity_y); |
| + velocity.set_x(velocity_x); |
| } else if (direction == "downright") { |
| distance.set_y(-distance_length); |
| distance.set_x(-distance_length); |
| + velocity.set_y(-velocity_y); |
| + velocity.set_x(-velocity_x); |
| } else { |
| return false; |
| } |
| + |
| gesture_params->distances.push_back(distance); |
| + if (set_velocity) |
|
tdresser
2017/03/23 15:47:33
I suppose we don't even need the condition here, s
sahel
2017/03/24 20:21:57
Done.
|
| + gesture_params->velocity = velocity; |
| + |
| // TODO(678879): If the render_view_impl is destroyed while the gesture is in |
| // progress, we will leak the callback and context. This needs to be fixed, |
| // somehow, see https://crbug.com/678879. |
| @@ -722,12 +750,15 @@ bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
| float page_scale_factor = context.web_view()->pageScaleFactor(); |
| blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); |
| - std::string direction = "up"; |
| + std::string direction = "down"; |
| float pixels_to_scroll = 0; |
| v8::Local<v8::Function> callback; |
| float start_x = rect.width / (page_scale_factor * 2); |
| float start_y = rect.height / (page_scale_factor * 2); |
| float speed_in_pixels_s = 800; |
| + int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
| + float velocity_x = 0; |
| + float velocity_y = 0; |
| if (!GetOptionalArg(args, &direction) || |
| !GetOptionalArg(args, &pixels_to_scroll) || |
| @@ -738,15 +769,19 @@ bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
| return false; |
| } |
| - return BeginSmoothScroll(args->isolate(), |
| - -pixels_to_scroll, |
| - callback, |
| - 1, // TOUCH_INPUT |
| - direction, |
| - speed_in_pixels_s, |
| - false, |
| - start_x, |
| - start_y); |
| + // If no gesture source type is provided, do a touch swipe by default. |
| + if (!GetOptionalArg(args, &gesture_source_type)) |
| + gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| + |
| + if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT && |
| + (!GetOptionalArg(args, &velocity_x) || |
| + !GetOptionalArg(args, &velocity_y))) { |
| + return false; |
| + } |
| + |
| + return BeginSmoothScroll(args->isolate(), pixels_to_scroll, callback, |
| + gesture_source_type, direction, speed_in_pixels_s, |
| + false, start_x, start_y, velocity_x, velocity_y); |
| } |
| bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { |