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

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

Issue 2742473002: gpu benchmarking swipe for touchpad
Patch Set: gpu benchmarking swipe for touchpad 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
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 DCHECK(!set_velocity || velocity_x || velocity_y);
394 if (set_velocity && !velocity_x && !velocity_y)
bokan 2017/03/10 14:41:57 Ditto here for the DCHECK and |if|
sahel 2017/03/10 21:51:41 Done.
395 return false;
396
397 gfx::Vector2dF velocity;
386 gfx::Vector2dF distance; 398 gfx::Vector2dF distance;
387 if (direction == "down") 399
400 if (direction == "down") {
bokan 2017/03/10 14:41:57 Question: do we really need this direction paramet
sahel 2017/03/10 21:51:41 I am not sure why we have it here, but one reason
388 distance.set_y(-distance_length); 401 distance.set_y(-distance_length);
389 else if (direction == "up") 402 velocity.set_y(set_velocity ? -velocity_y : 0);
403 } else if (direction == "up") {
390 distance.set_y(distance_length); 404 distance.set_y(distance_length);
391 else if (direction == "right") 405 velocity.set_y(set_velocity ? velocity_y : 0);
406 } else if (direction == "right") {
392 distance.set_x(-distance_length); 407 distance.set_x(-distance_length);
393 else if (direction == "left") 408 velocity.set_x(set_velocity ? -velocity_x : 0);
409 } else if (direction == "left") {
394 distance.set_x(distance_length); 410 distance.set_x(distance_length);
395 else if (direction == "upleft") { 411 velocity.set_x(set_velocity ? velocity_x : 0);
412 } else if (direction == "upleft") {
396 distance.set_y(distance_length); 413 distance.set_y(distance_length);
397 distance.set_x(distance_length); 414 distance.set_x(distance_length);
415 velocity.set_y(set_velocity ? velocity_y : 0);
416 velocity.set_x(set_velocity ? velocity_x : 0);
398 } else if (direction == "upright") { 417 } else if (direction == "upright") {
399 distance.set_y(distance_length); 418 distance.set_y(distance_length);
400 distance.set_x(-distance_length); 419 distance.set_x(-distance_length);
420 velocity.set_y(set_velocity ? velocity_y : 0);
421 velocity.set_x(set_velocity ? -velocity_x : 0);
401 } else if (direction == "downleft") { 422 } else if (direction == "downleft") {
402 distance.set_y(-distance_length); 423 distance.set_y(-distance_length);
403 distance.set_x(distance_length); 424 distance.set_x(distance_length);
425 velocity.set_y(set_velocity ? -velocity_y : 0);
426 velocity.set_x(set_velocity ? velocity_x : 0);
404 } else if (direction == "downright") { 427 } else if (direction == "downright") {
405 distance.set_y(-distance_length); 428 distance.set_y(-distance_length);
406 distance.set_x(-distance_length); 429 distance.set_x(-distance_length);
430 velocity.set_y(set_velocity ? -velocity_y : 0);
431 velocity.set_x(set_velocity ? -velocity_x : 0);
407 } else { 432 } else {
408 return false; 433 return false;
409 } 434 }
435
410 gesture_params->distances.push_back(distance); 436 gesture_params->distances.push_back(distance);
437 gesture_params->velocity = velocity;
411 438
412 // TODO(678879): If the render_view_impl is destroyed while the gesture is in 439 // 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, 440 // progress, we will leak the callback and context. This needs to be fixed,
414 // somehow, see https://crbug.com/678879. 441 // somehow, see https://crbug.com/678879.
415 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( 442 context.render_view_impl()->GetWidget()->QueueSyntheticGesture(
416 std::move(gesture_params), 443 std::move(gesture_params),
417 base::Bind(&OnSyntheticGestureCompleted, 444 base::Bind(&OnSyntheticGestureCompleted,
418 base::RetainedRef(callback_and_context))); 445 base::RetainedRef(callback_and_context)));
419 446
420 return true; 447 return true;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 } 742 }
716 743
717 bool GpuBenchmarking::Swipe(gin::Arguments* args) { 744 bool GpuBenchmarking::Swipe(gin::Arguments* args) {
718 GpuBenchmarkingContext context; 745 GpuBenchmarkingContext context;
719 if (!context.Init(true)) 746 if (!context.Init(true))
720 return false; 747 return false;
721 748
722 float page_scale_factor = context.web_view()->pageScaleFactor(); 749 float page_scale_factor = context.web_view()->pageScaleFactor();
723 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); 750 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect();
724 751
725 std::string direction = "up"; 752 std::string direction = "down";
726 float pixels_to_scroll = 0; 753 float pixels_to_scroll = 0;
727 v8::Local<v8::Function> callback; 754 v8::Local<v8::Function> callback;
728 float start_x = rect.width / (page_scale_factor * 2); 755 float start_x = rect.width / (page_scale_factor * 2);
729 float start_y = rect.height / (page_scale_factor * 2); 756 float start_y = rect.height / (page_scale_factor * 2);
730 float speed_in_pixels_s = 800; 757 float speed_in_pixels_s = 800;
758 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT;
759 float velocity_x = 0;
760 float velocity_y = 0;
731 761
732 if (!GetOptionalArg(args, &direction) || 762 if (!GetOptionalArg(args, &direction) ||
733 !GetOptionalArg(args, &pixels_to_scroll) || 763 !GetOptionalArg(args, &pixels_to_scroll) ||
734 !GetOptionalArg(args, &callback) || 764 !GetOptionalArg(args, &callback) ||
735 !GetOptionalArg(args, &start_x) || 765 !GetOptionalArg(args, &start_x) ||
736 !GetOptionalArg(args, &start_y) || 766 !GetOptionalArg(args, &start_y) ||
737 !GetOptionalArg(args, &speed_in_pixels_s)) { 767 !GetOptionalArg(args, &speed_in_pixels_s)) {
738 return false; 768 return false;
739 } 769 }
740 770
771 // If no gesture source type is provided, do a touch swipe by default.
772 if (!GetOptionalArg(args, &gesture_source_type)) {
773 gesture_source_type = SyntheticGestureParams::TOUCH_INPUT;
774 }
775
776 if (gesture_source_type == SyntheticGestureParams::MOUSE_INPUT &&
777 (!GetOptionalArg(args, &velocity_x) ||
778 !GetOptionalArg(args, &velocity_y))) {
779 return false;
780 }
781
782 float direction_adjustment = SyntheticGestureParams::TOUCH_INPUT ? 1 : -1;
741 return BeginSmoothScroll(args->isolate(), 783 return BeginSmoothScroll(args->isolate(),
742 -pixels_to_scroll, 784 direction_adjustment * pixels_to_scroll, callback,
743 callback, 785 gesture_source_type, direction, speed_in_pixels_s,
744 1, // TOUCH_INPUT 786 false, start_x, start_y, velocity_x, velocity_y);
745 direction,
746 speed_in_pixels_s,
747 false,
748 start_x,
749 start_y);
750 } 787 }
751 788
752 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) { 789 bool GpuBenchmarking::ScrollBounce(gin::Arguments* args) {
753 GpuBenchmarkingContext context; 790 GpuBenchmarkingContext context;
754 if (!context.Init(false)) 791 if (!context.Init(false))
755 return false; 792 return false;
756 793
757 float page_scale_factor = context.web_view()->pageScaleFactor(); 794 float page_scale_factor = context.web_view()->pageScaleFactor();
758 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect(); 795 blink::WebRect rect = context.render_view_impl()->GetWidget()->viewRect();
759 796
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 &gpu_driver_bug_workarounds))) { 1137 &gpu_driver_bug_workarounds))) {
1101 return; 1138 return;
1102 } 1139 }
1103 1140
1104 v8::Local<v8::Value> result; 1141 v8::Local<v8::Value> result;
1105 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) 1142 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result))
1106 args->Return(result); 1143 args->Return(result);
1107 } 1144 }
1108 1145
1109 } // namespace content 1146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698