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

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

Issue 929333002: Adding synthetic touch/mouse drag [Part1] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing errors. Created 5 years, 10 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 <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "cc/layers/layer.h" 14 #include "cc/layers/layer.h"
15 #include "content/common/input/synthetic_gesture_params.h" 15 #include "content/common/input/synthetic_gesture_params.h"
16 #include "content/common/input/synthetic_pinch_gesture_params.h" 16 #include "content/common/input/synthetic_pinch_gesture_params.h"
17 #include "content/common/input/synthetic_smooth_drag_gesture_params.h"
17 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" 18 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
18 #include "content/common/input/synthetic_tap_gesture_params.h" 19 #include "content/common/input/synthetic_tap_gesture_params.h"
19 #include "content/public/child/v8_value_converter.h" 20 #include "content/public/child/v8_value_converter.h"
20 #include "content/public/renderer/render_thread.h" 21 #include "content/public/renderer/render_thread.h"
21 #include "content/renderer/chrome_object_extensions_utils.h" 22 #include "content/renderer/chrome_object_extensions_utils.h"
22 #include "content/renderer/gpu/render_widget_compositor.h" 23 #include "content/renderer/gpu/render_widget_compositor.h"
23 #include "content/renderer/render_thread_impl.h" 24 #include "content/renderer/render_thread_impl.h"
24 #include "content/renderer/render_view_impl.h" 25 #include "content/renderer/render_view_impl.h"
25 #include "content/renderer/skia_benchmarking_extension.h" 26 #include "content/renderer/skia_benchmarking_extension.h"
26 #include "gin/arguments.h" 27 #include "gin/arguments.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // TODO(nduca): If the render_view_impl is destroyed while the gesture is in 375 // TODO(nduca): If the render_view_impl is destroyed while the gesture is in
375 // progress, we will leak the callback and context. This needs to be fixed, 376 // progress, we will leak the callback and context. This needs to be fixed,
376 // somehow. 377 // somehow.
377 context.render_view_impl()->QueueSyntheticGesture( 378 context.render_view_impl()->QueueSyntheticGesture(
378 gesture_params.Pass(), 379 gesture_params.Pass(),
379 base::Bind(&OnSyntheticGestureCompleted, callback_and_context)); 380 base::Bind(&OnSyntheticGestureCompleted, callback_and_context));
380 381
381 return true; 382 return true;
382 } 383 }
383 384
385 bool BeginSmoothDrag(v8::Isolate* isolate,
386 int start_x,
387 int start_y,
388 int end_x,
389 int end_y,
390 v8::Handle<v8::Function> callback,
391 int gesture_source_type,
392 int speed_in_pixels_s) {
393 GpuBenchmarkingContext context;
394 if (!context.Init(false))
395 return false;
396 scoped_refptr<CallbackAndContext> callback_and_context =
397 new CallbackAndContext(isolate, callback,
398 context.web_frame()->mainWorldScriptContext());
399
400 scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params(
401 new SyntheticSmoothDragGestureParams);
402
403 // Convert coordinates from CSS pixels to density independent pixels (DIPs).
404 float page_scale_factor = context.web_view()->pageScaleFactor();
405
406 gesture_params->start_point.SetPoint(start_x * page_scale_factor,
407 start_y * page_scale_factor);
408 gfx::Vector2d distance((end_x - start_x) * page_scale_factor,
409 (end_y - start_y) * page_scale_factor);
410 gesture_params->distances.push_back(distance);
411 gesture_params->speed_in_pixels_s = speed_in_pixels_s * page_scale_factor;
412 gesture_params->gesture_source_type =
413 static_cast<SyntheticGestureParams::GestureSourceType>(
414 gesture_source_type);
415
416 context.render_view_impl()->QueueSyntheticGesture(
417 gesture_params.Pass(),
418 base::Bind(&OnSyntheticGestureCompleted, callback_and_context));
419
420 return true;
421 }
422
384 } // namespace 423 } // namespace
385 424
386 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; 425 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin};
387 426
388 // static 427 // static
389 void GpuBenchmarking::Install(blink::WebFrame* frame) { 428 void GpuBenchmarking::Install(blink::WebFrame* frame) {
390 v8::Isolate* isolate = blink::mainThreadIsolate(); 429 v8::Isolate* isolate = blink::mainThreadIsolate();
391 v8::HandleScope handle_scope(isolate); 430 v8::HandleScope handle_scope(isolate);
392 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); 431 v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
393 if (context.IsEmpty()) 432 if (context.IsEmpty())
(...skipping 24 matching lines...) Expand all
418 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) 457 &GpuBenchmarking::SetNeedsDisplayOnAllLayers)
419 .SetMethod("setRasterizeOnlyVisibleContent", 458 .SetMethod("setRasterizeOnlyVisibleContent",
420 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) 459 &GpuBenchmarking::SetRasterizeOnlyVisibleContent)
421 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) 460 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture)
422 .SetValue("DEFAULT_INPUT", 0) 461 .SetValue("DEFAULT_INPUT", 0)
423 .SetValue("TOUCH_INPUT", 1) 462 .SetValue("TOUCH_INPUT", 1)
424 .SetValue("MOUSE_INPUT", 2) 463 .SetValue("MOUSE_INPUT", 2)
425 .SetMethod("gestureSourceTypeSupported", 464 .SetMethod("gestureSourceTypeSupported",
426 &GpuBenchmarking::GestureSourceTypeSupported) 465 &GpuBenchmarking::GestureSourceTypeSupported)
427 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) 466 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy)
467 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag)
428 .SetMethod("swipe", &GpuBenchmarking::Swipe) 468 .SetMethod("swipe", &GpuBenchmarking::Swipe)
429 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) 469 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce)
430 // TODO(dominikg): Remove once JS interface changes have rolled into 470 // TODO(dominikg): Remove once JS interface changes have rolled into
431 // stable. 471 // stable.
432 .SetValue("newPinchInterface", true) 472 .SetValue("newPinchInterface", true)
433 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) 473 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy)
434 .SetMethod("tap", &GpuBenchmarking::Tap) 474 .SetMethod("tap", &GpuBenchmarking::Tap)
435 .SetMethod("beginWindowSnapshotPNG", 475 .SetMethod("beginWindowSnapshotPNG",
436 &GpuBenchmarking::BeginWindowSnapshotPNG) 476 &GpuBenchmarking::BeginWindowSnapshotPNG)
437 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) 477 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 pixels_to_scroll, 562 pixels_to_scroll,
523 callback, 563 callback,
524 gesture_source_type, 564 gesture_source_type,
525 direction, 565 direction,
526 speed_in_pixels_s, 566 speed_in_pixels_s,
527 true, 567 true,
528 start_x, 568 start_x,
529 start_y); 569 start_y);
530 } 570 }
531 571
572 bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) {
573 GpuBenchmarkingContext context;
574 if (!context.Init(true))
575 return false;
576
577 int start_x;
Sami 2015/02/18 12:01:53 Let's make these coordinates floats too.
ssid 2015/02/18 17:57:35 Done.
578 int start_y;
579 int end_x;
580 int end_y;
581 v8::Handle<v8::Function> callback;
582 int gesture_source_type = 0; // Default input
583 int speed_in_pixels_s = 800;
584
585 if (!GetArg(args, &start_x) ||
586 !GetArg(args, &start_y) ||
587 !GetArg(args, &end_x) ||
588 !GetArg(args, &end_y) ||
589 !GetOptionalArg(args, &callback) ||
590 !GetOptionalArg(args, &gesture_source_type) ||
591 !GetOptionalArg(args, &speed_in_pixels_s)) {
592 return false;
593 }
594
595 return BeginSmoothDrag(args->isolate(),
596 start_x,
597 start_y,
598 end_x,
599 end_y,
600 callback,
601 gesture_source_type,
602 speed_in_pixels_s);
603 }
604
532 bool GpuBenchmarking::Swipe(gin::Arguments* args) { 605 bool GpuBenchmarking::Swipe(gin::Arguments* args) {
533 GpuBenchmarkingContext context; 606 GpuBenchmarkingContext context;
534 if (!context.Init(true)) 607 if (!context.Init(true))
535 return false; 608 return false;
536 609
537 float page_scale_factor = context.web_view()->pageScaleFactor(); 610 float page_scale_factor = context.web_view()->pageScaleFactor();
538 blink::WebRect rect = context.render_view_impl()->windowRect(); 611 blink::WebRect rect = context.render_view_impl()->windowRect();
539 612
540 std::string direction = "up"; 613 std::string direction = "up";
541 int pixels_to_scroll = 0; 614 int pixels_to_scroll = 0;
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 880
808 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); 881 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass());
809 } 882 }
810 883
811 bool GpuBenchmarking::HasGpuProcess() { 884 bool GpuBenchmarking::HasGpuProcess() {
812 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); 885 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
813 return !!gpu_channel; 886 return !!gpu_channel;
814 } 887 }
815 888
816 } // namespace content 889 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698