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 <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 Loading... | |
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 float start_x, | |
387 float start_y, | |
388 float end_x, | |
389 float 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::PointF end_point(end_x * page_scale_factor, | |
409 end_y * page_scale_factor); | |
410 gfx::Vector2dF distance = gesture_params->start_point - end_point; | |
411 gesture_params->distances.push_back(distance); | |
412 gesture_params->speed_in_pixels_s = speed_in_pixels_s * page_scale_factor; | |
413 gesture_params->gesture_source_type = | |
414 static_cast<SyntheticGestureParams::GestureSourceType>( | |
415 gesture_source_type); | |
416 | |
417 // TODO(nduca): If the render_view_impl is destroyed while the gesture is in | |
418 // progress, we will leak the callback and context. This needs to be fixed, | |
419 // somehow. | |
dcheng
2015/02/26 17:56:51
Why do we leak this? It looks like RenderWidget ha
ssid
2015/02/26 20:02:34
I am not really sure about this, but this is the s
| |
420 context.render_view_impl()->QueueSyntheticGesture( | |
421 gesture_params.Pass(), | |
422 base::Bind(&OnSyntheticGestureCompleted, callback_and_context)); | |
423 | |
424 return true; | |
425 } | |
426 | |
384 } // namespace | 427 } // namespace |
385 | 428 |
386 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; | 429 gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin}; |
387 | 430 |
388 // static | 431 // static |
389 void GpuBenchmarking::Install(blink::WebFrame* frame) { | 432 void GpuBenchmarking::Install(blink::WebFrame* frame) { |
390 v8::Isolate* isolate = blink::mainThreadIsolate(); | 433 v8::Isolate* isolate = blink::mainThreadIsolate(); |
391 v8::HandleScope handle_scope(isolate); | 434 v8::HandleScope handle_scope(isolate); |
392 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 435 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
393 if (context.IsEmpty()) | 436 if (context.IsEmpty()) |
(...skipping 24 matching lines...) Expand all Loading... | |
418 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) | 461 &GpuBenchmarking::SetNeedsDisplayOnAllLayers) |
419 .SetMethod("setRasterizeOnlyVisibleContent", | 462 .SetMethod("setRasterizeOnlyVisibleContent", |
420 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) | 463 &GpuBenchmarking::SetRasterizeOnlyVisibleContent) |
421 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) | 464 .SetMethod("printToSkPicture", &GpuBenchmarking::PrintToSkPicture) |
422 .SetValue("DEFAULT_INPUT", 0) | 465 .SetValue("DEFAULT_INPUT", 0) |
423 .SetValue("TOUCH_INPUT", 1) | 466 .SetValue("TOUCH_INPUT", 1) |
424 .SetValue("MOUSE_INPUT", 2) | 467 .SetValue("MOUSE_INPUT", 2) |
425 .SetMethod("gestureSourceTypeSupported", | 468 .SetMethod("gestureSourceTypeSupported", |
426 &GpuBenchmarking::GestureSourceTypeSupported) | 469 &GpuBenchmarking::GestureSourceTypeSupported) |
427 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) | 470 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) |
471 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) | |
428 .SetMethod("swipe", &GpuBenchmarking::Swipe) | 472 .SetMethod("swipe", &GpuBenchmarking::Swipe) |
429 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) | 473 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) |
430 // TODO(dominikg): Remove once JS interface changes have rolled into | 474 // TODO(dominikg): Remove once JS interface changes have rolled into |
431 // stable. | 475 // stable. |
432 .SetValue("newPinchInterface", true) | 476 .SetValue("newPinchInterface", true) |
433 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) | 477 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) |
434 .SetMethod("tap", &GpuBenchmarking::Tap) | 478 .SetMethod("tap", &GpuBenchmarking::Tap) |
435 .SetMethod("beginWindowSnapshotPNG", | 479 .SetMethod("beginWindowSnapshotPNG", |
436 &GpuBenchmarking::BeginWindowSnapshotPNG) | 480 &GpuBenchmarking::BeginWindowSnapshotPNG) |
437 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) | 481 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 pixels_to_scroll, | 566 pixels_to_scroll, |
523 callback, | 567 callback, |
524 gesture_source_type, | 568 gesture_source_type, |
525 direction, | 569 direction, |
526 speed_in_pixels_s, | 570 speed_in_pixels_s, |
527 true, | 571 true, |
528 start_x, | 572 start_x, |
529 start_y); | 573 start_y); |
530 } | 574 } |
531 | 575 |
576 bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) { | |
577 GpuBenchmarkingContext context; | |
578 if (!context.Init(true)) | |
579 return false; | |
580 | |
581 float start_x; | |
582 float start_y; | |
583 float end_x; | |
584 float end_y; | |
585 v8::Handle<v8::Function> callback; | |
586 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | |
587 int speed_in_pixels_s = 800; | |
588 | |
589 if (!GetArg(args, &start_x) || | |
590 !GetArg(args, &start_y) || | |
591 !GetArg(args, &end_x) || | |
592 !GetArg(args, &end_y) || | |
593 !GetOptionalArg(args, &callback) || | |
594 !GetOptionalArg(args, &gesture_source_type) || | |
595 !GetOptionalArg(args, &speed_in_pixels_s)) { | |
596 return false; | |
597 } | |
598 | |
599 return BeginSmoothDrag(args->isolate(), | |
600 start_x, | |
601 start_y, | |
602 end_x, | |
603 end_y, | |
604 callback, | |
605 gesture_source_type, | |
606 speed_in_pixels_s); | |
607 } | |
608 | |
532 bool GpuBenchmarking::Swipe(gin::Arguments* args) { | 609 bool GpuBenchmarking::Swipe(gin::Arguments* args) { |
533 GpuBenchmarkingContext context; | 610 GpuBenchmarkingContext context; |
534 if (!context.Init(true)) | 611 if (!context.Init(true)) |
535 return false; | 612 return false; |
536 | 613 |
537 float page_scale_factor = context.web_view()->pageScaleFactor(); | 614 float page_scale_factor = context.web_view()->pageScaleFactor(); |
538 blink::WebRect rect = context.render_view_impl()->windowRect(); | 615 blink::WebRect rect = context.render_view_impl()->windowRect(); |
539 | 616 |
540 std::string direction = "up"; | 617 std::string direction = "up"; |
541 int pixels_to_scroll = 0; | 618 int pixels_to_scroll = 0; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 | 884 |
808 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); | 885 return context.compositor()->SendMessageToMicroBenchmark(id, value.Pass()); |
809 } | 886 } |
810 | 887 |
811 bool GpuBenchmarking::HasGpuProcess() { | 888 bool GpuBenchmarking::HasGpuProcess() { |
812 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); | 889 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
813 return !!gpu_channel; | 890 return !!gpu_channel; |
814 } | 891 } |
815 | 892 |
816 } // namespace content | 893 } // namespace content |
OLD | NEW |