Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/gpu/gpu_benchmarking_extension.h" | 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool BeginSmoothScroll(v8::Isolate* isolate, | 332 bool BeginSmoothScroll(v8::Isolate* isolate, |
| 333 float pixels_to_scroll, | 333 float pixels_to_scroll, |
| 334 v8::Local<v8::Function> callback, | 334 v8::Local<v8::Function> callback, |
| 335 int gesture_source_type, | 335 int gesture_source_type, |
| 336 const std::string& direction, | 336 const std::string& direction, |
| 337 float speed_in_pixels_s, | 337 float speed_in_pixels_s, |
| 338 bool prevent_fling, | 338 bool prevent_fling, |
| 339 float start_x, | 339 float start_x, |
| 340 float start_y) { | 340 float start_y, |
| 341 float velocity_x = 0, | |
| 342 float velocity_y = 0) { | |
| 341 GpuBenchmarkingContext context; | 343 GpuBenchmarkingContext context; |
| 342 if (!context.Init(false)) | 344 if (!context.Init(false)) |
| 343 return false; | 345 return false; |
| 344 | 346 |
| 345 // Convert coordinates from CSS pixels to density independent pixels (DIPs). | 347 // Convert coordinates from CSS pixels to density independent pixels (DIPs). |
| 346 float page_scale_factor = context.web_view()->pageScaleFactor(); | 348 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 347 | 349 |
| 348 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT) { | 350 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT) { |
| 349 // Ensure the mouse is centered and visible, in case it will | 351 // Ensure the mouse is centered and visible, in case it will |
| 350 // trigger any hover or mousemove effects. | 352 // trigger any hover or mousemove effects. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 376 static_cast<SyntheticGestureParams::GestureSourceType>( | 378 static_cast<SyntheticGestureParams::GestureSourceType>( |
| 377 gesture_source_type); | 379 gesture_source_type); |
| 378 | 380 |
| 379 gesture_params->speed_in_pixels_s = speed_in_pixels_s; | 381 gesture_params->speed_in_pixels_s = speed_in_pixels_s; |
| 380 gesture_params->prevent_fling = prevent_fling; | 382 gesture_params->prevent_fling = prevent_fling; |
| 381 | 383 |
| 382 gesture_params->anchor.SetPoint(start_x * page_scale_factor, | 384 gesture_params->anchor.SetPoint(start_x * page_scale_factor, |
| 383 start_y * page_scale_factor); | 385 start_y * page_scale_factor); |
| 384 | 386 |
| 385 float distance_length = pixels_to_scroll * page_scale_factor; | 387 float distance_length = pixels_to_scroll * page_scale_factor; |
| 388 | |
| 389 bool set_velocity = | |
| 390 gesture_source_type == SyntheticGestureParams::MOUSE_INPUT && | |
| 391 !prevent_fling; | |
| 392 | |
| 393 if (set_velocity && !velocity_x && !velocity_y) | |
| 394 return false; | |
| 395 | |
| 396 gfx::Vector2dF velocity; | |
| 386 gfx::Vector2dF distance; | 397 gfx::Vector2dF distance; |
| 387 if (direction == "down") | 398 |
| 399 if (direction == "down") { | |
| 388 distance.set_y(-distance_length); | 400 distance.set_y(-distance_length); |
| 389 else if (direction == "up") | 401 velocity.set_y(set_velocity ? -velocity_y : 0); |
| 402 } else if (direction == "up") { | |
| 390 distance.set_y(distance_length); | 403 distance.set_y(distance_length); |
| 391 else if (direction == "right") | 404 velocity.set_y(set_velocity ? velocity_y : 0); |
| 405 } else if (direction == "right") { | |
| 392 distance.set_x(-distance_length); | 406 distance.set_x(-distance_length); |
| 393 else if (direction == "left") | 407 velocity.set_x(set_velocity ? -velocity_x : 0); |
| 408 } else if (direction == "left") { | |
| 394 distance.set_x(distance_length); | 409 distance.set_x(distance_length); |
| 395 else if (direction == "upleft") { | 410 velocity.set_x(set_velocity ? velocity_x : 0); |
| 411 } else if (direction == "upleft") { | |
| 396 distance.set_y(distance_length); | 412 distance.set_y(distance_length); |
| 397 distance.set_x(distance_length); | 413 distance.set_x(distance_length); |
| 414 velocity.set_y(set_velocity ? velocity_y : 0); | |
| 415 velocity.set_x(set_velocity ? velocity_x : 0); | |
| 398 } else if (direction == "upright") { | 416 } else if (direction == "upright") { |
| 399 distance.set_y(distance_length); | 417 distance.set_y(distance_length); |
| 400 distance.set_x(-distance_length); | 418 distance.set_x(-distance_length); |
| 419 velocity.set_y(set_velocity ? velocity_y : 0); | |
| 420 velocity.set_x(set_velocity ? -velocity_x : 0); | |
| 401 } else if (direction == "downleft") { | 421 } else if (direction == "downleft") { |
| 402 distance.set_y(-distance_length); | 422 distance.set_y(-distance_length); |
| 403 distance.set_x(distance_length); | 423 distance.set_x(distance_length); |
| 424 velocity.set_y(set_velocity ? -velocity_y : 0); | |
| 425 velocity.set_x(set_velocity ? velocity_x : 0); | |
| 404 } else if (direction == "downright") { | 426 } else if (direction == "downright") { |
| 405 distance.set_y(-distance_length); | 427 distance.set_y(-distance_length); |
| 406 distance.set_x(-distance_length); | 428 distance.set_x(-distance_length); |
| 429 velocity.set_y(set_velocity ? -velocity_y : 0); | |
| 430 velocity.set_x(set_velocity ? -velocity_x : 0); | |
| 407 } else { | 431 } else { |
| 408 return false; | 432 return false; |
| 409 } | 433 } |
| 434 | |
| 410 gesture_params->distances.push_back(distance); | 435 gesture_params->distances.push_back(distance); |
| 436 gesture_params->velocity = velocity; | |
|
tdresser
2017/03/22 19:44:02
Instead of all the ternary operators above, could
sahel
2017/03/22 21:30:28
Done.
| |
| 411 | 437 |
| 412 // TODO(678879): If the render_view_impl is destroyed while the gesture is in | 438 // TODO(678879): If the render_view_impl is destroyed while the gesture is in |
| 413 // progress, we will leak the callback and context. This needs to be fixed, | 439 // progress, we will leak the callback and context. This needs to be fixed, |
| 414 // somehow, see https://crbug.com/678879. | 440 // somehow, see https://crbug.com/678879. |
| 415 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( | 441 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( |
| 416 std::move(gesture_params), | 442 std::move(gesture_params), |
| 417 base::Bind(&OnSyntheticGestureCompleted, | 443 base::Bind(&OnSyntheticGestureCompleted, |
| 418 base::RetainedRef(callback_and_context))); | 444 base::RetainedRef(callback_and_context))); |
| 419 | 445 |
| 420 return true; | 446 return true; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 } | 741 } |
| 716 | 742 |
| 717 bool GpuBenchmarking::Swipe(gin::Arguments* args) { | 743 bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
| 718 GpuBenchmarkingContext context; | 744 GpuBenchmarkingContext context; |
| 719 if (!context.Init(true)) | 745 if (!context.Init(true)) |
| 720 return false; | 746 return false; |
| 721 | 747 |
| 722 float page_scale_factor = context.web_view()->pageScaleFactor(); | 748 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 723 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); | 749 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); |
| 724 | 750 |
| 725 std::string direction = "up"; | 751 std::string direction = "down"; |
| 726 float pixels_to_scroll = 0; | 752 float pixels_to_scroll = 0; |
| 727 v8::Local<v8::Function> callback; | 753 v8::Local<v8::Function> callback; |
| 728 float start_x = rect.width / (page_scale_factor * 2); | 754 float start_x = rect.width / (page_scale_factor * 2); |
| 729 float start_y = rect.height / (page_scale_factor * 2); | 755 float start_y = rect.height / (page_scale_factor * 2); |
| 730 float speed_in_pixels_s = 800; | 756 float speed_in_pixels_s = 800; |
| 757 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | |
| 758 float velocity_x = 0; | |
| 759 float velocity_y = 0; | |
| 731 | 760 |
| 732 if (!GetOptionalArg(args, &direction) || | 761 if (!GetOptionalArg(args, &direction) || |
| 733 !GetOptionalArg(args, &pixels_to_scroll) || | 762 !GetOptionalArg(args, &pixels_to_scroll) || |
| 734 !GetOptionalArg(args, &callback) || | 763 !GetOptionalArg(args, &callback) || |
| 735 !GetOptionalArg(args, &start_x) || | 764 !GetOptionalArg(args, &start_x) || |
| 736 !GetOptionalArg(args, &start_y) || | 765 !GetOptionalArg(args, &start_y) || |
| 737 !GetOptionalArg(args, &speed_in_pixels_s)) { | 766 !GetOptionalArg(args, &speed_in_pixels_s)) { |
| 738 return false; | 767 return false; |
| 739 } | 768 } |
| 740 | 769 |
| 741 return BeginSmoothScroll(args->isolate(), | 770 // If no gesture source type is provided, do a touch swipe by default. |
| 742 -pixels_to_scroll, | 771 if (!GetOptionalArg(args, &gesture_source_type)) |
| 743 callback, | 772 gesture_source_type = SyntheticGestureParams::TOUCH_INPUT; |
| 744 1, // TOUCH_INPUT | 773 |
| 745 direction, | 774 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT && |
| 746 speed_in_pixels_s, | 775 (!GetOptionalArg(args, &velocity_x) || |
| 747 false, | 776 !GetOptionalArg(args, &velocity_y))) { |
| 748 start_x, | 777 return false; |
| 749 start_y); | 778 } |
| 779 | |
| 780 return BeginSmoothScroll(args->isolate(), pixels_to_scroll, callback, | |
| 781 gesture_source_type, direction, speed_in_pixels_s, | |
| 782 false, start_x, start_y, velocity_x, velocity_y); | |
| 750 } | 783 } |
| 751 | 784 |
| 752 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { | 785 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { |
| 753 GpuBenchmarkingContext context; | 786 GpuBenchmarkingContext context; |
| 754 if (!context.Init(false)) | 787 if (!context.Init(false)) |
| 755 return false; | 788 return false; |
| 756 | 789 |
| 757 float page_scale_factor = context.web_view()->pageScaleFactor(); | 790 float page_scale_factor = context.web_view()->pageScaleFactor(); |
| 758 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); | 791 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); |
| 759 | 792 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1100 &gpu_driver_bug_workarounds))) { | 1133 &gpu_driver_bug_workarounds))) { |
| 1101 return; | 1134 return; |
| 1102 } | 1135 } |
| 1103 | 1136 |
| 1104 v8::Local<v8::Value> result; | 1137 v8::Local<v8::Value> result; |
| 1105 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 1138 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
| 1106 args->Return(result); | 1139 args->Return(result); |
| 1107 } | 1140 } |
| 1108 | 1141 |
| 1109 } // namespace content | 1142 } // namespace content |
| OLD | NEW |