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

Side by Side Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 2742473002: gpu benchmarking swipe for touchpad
Patch Set: comments addressed. Created 3 years, 9 months 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
« no previous file with comments | « content/renderer/gpu/gpu_benchmarking_extension.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(0, 0);
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(-velocity_y);
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(velocity_y);
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(-velocity_x);
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(velocity_x);
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(velocity_y);
415 velocity.set_x(velocity_x);
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(velocity_y);
420 velocity.set_x(-velocity_x);
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(-velocity_y);
425 velocity.set_x(velocity_x);
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(-velocity_y);
430 velocity.set_x(-velocity_x);
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);
411 436
437 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.
438 gesture_params->velocity = velocity;
439
412 // TODO(678879): If the render_view_impl is destroyed while the gesture is in 440 // 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, 441 // progress, we will leak the callback and context. This needs to be fixed,
414 // somehow, see https://crbug.com/678879. 442 // somehow, see https://crbug.com/678879.
415 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( 443 context.render_view_impl()->GetWidget()->QueueSyntheticGesture(
416 std::move(gesture_params), 444 std::move(gesture_params),
417 base::Bind(&OnSyntheticGestureCompleted, 445 base::Bind(&OnSyntheticGestureCompleted,
418 base::RetainedRef(callback_and_context))); 446 base::RetainedRef(callback_and_context)));
419 447
420 return true; 448 return true;
421 } 449 }
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 743 }
716 744
717 bool GpuBenchmarking::Swipe(gin::Arguments* args) { 745 bool GpuBenchmarking::Swipe(gin::Arguments* args) {
718 GpuBenchmarkingContext context; 746 GpuBenchmarkingContext context;
719 if (!context.Init(true)) 747 if (!context.Init(true))
720 return false; 748 return false;
721 749
722 float page_scale_factor = context.web_view()->pageScaleFactor(); 750 float page_scale_factor = context.web_view()->pageScaleFactor();
723 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); 751 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect();
724 752
725 std::string direction = "up"; 753 std::string direction = "down";
726 float pixels_to_scroll = 0; 754 float pixels_to_scroll = 0;
727 v8::Local<v8::Function> callback; 755 v8::Local<v8::Function> callback;
728 float start_x = rect.width / (page_scale_factor * 2); 756 float start_x = rect.width / (page_scale_factor * 2);
729 float start_y = rect.height / (page_scale_factor * 2); 757 float start_y = rect.height / (page_scale_factor * 2);
730 float speed_in_pixels_s = 800; 758 float speed_in_pixels_s = 800;
759 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT;
760 float velocity_x = 0;
761 float velocity_y = 0;
731 762
732 if (!GetOptionalArg(args, &direction) || 763 if (!GetOptionalArg(args, &direction) ||
733 !GetOptionalArg(args, &pixels_to_scroll) || 764 !GetOptionalArg(args, &pixels_to_scroll) ||
734 !GetOptionalArg(args, &callback) || 765 !GetOptionalArg(args, &callback) ||
735 !GetOptionalArg(args, &start_x) || 766 !GetOptionalArg(args, &start_x) ||
736 !GetOptionalArg(args, &start_y) || 767 !GetOptionalArg(args, &start_y) ||
737 !GetOptionalArg(args, &speed_in_pixels_s)) { 768 !GetOptionalArg(args, &speed_in_pixels_s)) {
738 return false; 769 return false;
739 } 770 }
740 771
741 return BeginSmoothScroll(args->isolate(), 772 // If no gesture source type is provided, do a touch swipe by default.
742 -pixels_to_scroll, 773 if (!GetOptionalArg(args, &gesture_source_type))
743 callback, 774 gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
744 1, // TOUCH_INPUT 775
745 direction, 776 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT &&
746 speed_in_pixels_s, 777 (!GetOptionalArg(args, &velocity_x) ||
747 false, 778 !GetOptionalArg(args, &velocity_y))) {
748 start_x, 779 return false;
749 start_y); 780 }
781
782 return BeginSmoothScroll(args->isolate(), pixels_to_scroll, callback,
783 gesture_source_type, direction, speed_in_pixels_s,
784 false, start_x, start_y, velocity_x, velocity_y);
750 } 785 }
751 786
752 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { 787 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) {
753 GpuBenchmarkingContext context; 788 GpuBenchmarkingContext context;
754 if (!context.Init(false)) 789 if (!context.Init(false))
755 return false; 790 return false;
756 791
757 float page_scale_factor = context.web_view()->pageScaleFactor(); 792 float page_scale_factor = context.web_view()->pageScaleFactor();
758 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); 793 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect();
759 794
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 &gpu_driver_bug_workarounds))) { 1135 &gpu_driver_bug_workarounds))) {
1101 return; 1136 return;
1102 } 1137 }
1103 1138
1104 v8::Local<v8::Value> result; 1139 v8::Local<v8::Value> result;
1105 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) 1140 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result))
1106 args->Return(result); 1141 args->Return(result);
1107 } 1142 }
1108 1143
1109 } // namespace content 1144 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/gpu/gpu_benchmarking_extension.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698