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 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
| 18 #include "content/common/child_process_messages.h" | 18 #include "content/common/child_process_messages.h" |
| 19 #include "content/common/input/synthetic_gesture_params.h" | 19 #include "content/common/input/synthetic_gesture_params.h" |
| 20 #include "content/common/input/synthetic_pinch_gesture_params.h" | 20 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 21 #include "content/common/input/synthetic_pointer_action_params.h" | |
| 21 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" | 22 #include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
| 22 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 23 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 23 #include "content/common/input/synthetic_tap_gesture_params.h" | 24 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 24 #include "content/public/child/v8_value_converter.h" | 25 #include "content/public/child/v8_value_converter.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/renderer/chrome_object_extensions_utils.h" | 27 #include "content/public/renderer/chrome_object_extensions_utils.h" |
| 27 #include "content/public/renderer/render_thread.h" | 28 #include "content/public/renderer/render_thread.h" |
| 28 #include "content/renderer/gpu/render_widget_compositor.h" | 29 #include "content/renderer/gpu/render_widget_compositor.h" |
| 29 #include "content/renderer/render_thread_impl.h" | 30 #include "content/renderer/render_thread_impl.h" |
| 30 #include "content/renderer/render_view_impl.h" | 31 #include "content/renderer/render_view_impl.h" |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 .SetMethod("gestureSourceTypeSupported", | 493 .SetMethod("gestureSourceTypeSupported", |
| 493 &GpuBenchmarking::GestureSourceTypeSupported) | 494 &GpuBenchmarking::GestureSourceTypeSupported) |
| 494 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) | 495 .SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy) |
| 495 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) | 496 .SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag) |
| 496 .SetMethod("swipe", &GpuBenchmarking::Swipe) | 497 .SetMethod("swipe", &GpuBenchmarking::Swipe) |
| 497 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) | 498 .SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce) |
| 498 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) | 499 .SetMethod("pinchBy", &GpuBenchmarking::PinchBy) |
| 499 .SetMethod("visualViewportHeight", &GpuBenchmarking::VisualViewportHeight) | 500 .SetMethod("visualViewportHeight", &GpuBenchmarking::VisualViewportHeight) |
| 500 .SetMethod("visualViewportWidth", &GpuBenchmarking::VisualViewportWidth) | 501 .SetMethod("visualViewportWidth", &GpuBenchmarking::VisualViewportWidth) |
| 501 .SetMethod("tap", &GpuBenchmarking::Tap) | 502 .SetMethod("tap", &GpuBenchmarking::Tap) |
| 503 .SetMethod("touchActionSequence", &GpuBenchmarking::TouchActionSequence) | |
| 502 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) | 504 .SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) |
| 503 .SetMethod("runMicroBenchmark", &GpuBenchmarking::RunMicroBenchmark) | 505 .SetMethod("runMicroBenchmark", &GpuBenchmarking::RunMicroBenchmark) |
| 504 .SetMethod("sendMessageToMicroBenchmark", | 506 .SetMethod("sendMessageToMicroBenchmark", |
| 505 &GpuBenchmarking::SendMessageToMicroBenchmark) | 507 &GpuBenchmarking::SendMessageToMicroBenchmark) |
| 506 .SetMethod("hasGpuChannel", &GpuBenchmarking::HasGpuChannel) | 508 .SetMethod("hasGpuChannel", &GpuBenchmarking::HasGpuChannel) |
| 507 .SetMethod("hasGpuProcess", &GpuBenchmarking::HasGpuProcess) | 509 .SetMethod("hasGpuProcess", &GpuBenchmarking::HasGpuProcess) |
| 508 .SetMethod("getGpuDriverBugWorkarounds", | 510 .SetMethod("getGpuDriverBugWorkarounds", |
| 509 &GpuBenchmarking::GetGpuDriverBugWorkarounds); | 511 &GpuBenchmarking::GetGpuDriverBugWorkarounds); |
| 510 } | 512 } |
| 511 | 513 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 799 } | 801 } |
| 800 | 802 |
| 801 float GpuBenchmarking::VisualViewportWidth() { | 803 float GpuBenchmarking::VisualViewportWidth() { |
| 802 GpuBenchmarkingContext context; | 804 GpuBenchmarkingContext context; |
| 803 if (!context.Init(false)) | 805 if (!context.Init(false)) |
| 804 return 0.0; | 806 return 0.0; |
| 805 return context.web_view()->visualViewportSize().width; | 807 return context.web_view()->visualViewportSize().width; |
| 806 } | 808 } |
| 807 | 809 |
| 808 bool GpuBenchmarking::Tap(gin::Arguments* args) { | 810 bool GpuBenchmarking::Tap(gin::Arguments* args) { |
| 811 LOG(ERROR) << "GpuBenchmarking::Tap"; | |
| 809 GpuBenchmarkingContext context; | 812 GpuBenchmarkingContext context; |
| 810 if (!context.Init(false)) | 813 if (!context.Init(false)) |
| 811 return false; | 814 return false; |
| 812 | 815 |
| 813 float position_x; | 816 float position_x; |
| 814 float position_y; | 817 float position_y; |
| 815 v8::Local<v8::Function> callback; | 818 v8::Local<v8::Function> callback; |
| 816 int duration_ms = 50; | 819 int duration_ms = 50; |
| 817 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | 820 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
| 818 | 821 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 851 // progress, we will leak the callback and context. This needs to be fixed, | 854 // progress, we will leak the callback and context. This needs to be fixed, |
| 852 // somehow. | 855 // somehow. |
| 853 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( | 856 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( |
| 854 std::move(gesture_params), | 857 std::move(gesture_params), |
| 855 base::Bind(&OnSyntheticGestureCompleted, | 858 base::Bind(&OnSyntheticGestureCompleted, |
| 856 base::RetainedRef(callback_and_context))); | 859 base::RetainedRef(callback_and_context))); |
| 857 | 860 |
| 858 return true; | 861 return true; |
| 859 } | 862 } |
| 860 | 863 |
| 864 bool GpuBenchmarking::TouchActionSequence(gin::Arguments* args) { | |
| 865 GpuBenchmarkingContext context; | |
| 866 if (!context.Init(false)) | |
| 867 return false; | |
| 868 | |
| 869 v8::Local<v8::Function> callback; | |
| 870 | |
| 871 // pass a two-dimensional list of actions. | |
|
tdresser
2016/04/18 15:24:39
pass -> Pass
Is this supposed to be currently pas
lanwei
2016/04/19 19:05:32
Yes, it should be 2D array. I am not sure how to c
| |
| 872 | |
| 873 int pointer_action_type_int; | |
| 874 int index; | |
| 875 float position_x; | |
| 876 float position_y; | |
| 877 int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; | |
| 878 SyntheticPointerActionParams::PointerActionType pointer_action_type; | |
| 879 if (!GetArg(args, &pointer_action_type_int)) { | |
| 880 return false; | |
| 881 } | |
| 882 pointer_action_type = | |
| 883 static_cast<SyntheticPointerActionParams::PointerActionType>( | |
| 884 pointer_action_type_int); | |
| 885 LOG(ERROR) << "GpuBenchmarking::TouchActionSequence " | |
| 886 << pointer_action_type_int; | |
| 887 scoped_ptr<SyntheticPointerActionParams> gesture_params( | |
| 888 new SyntheticPointerActionParams(pointer_action_type)); | |
| 889 | |
| 890 if (pointer_action_type != | |
| 891 SyntheticPointerActionParams::PointerActionType::PROCESS) { | |
| 892 if (!GetArg(args, &index)) { | |
| 893 return false; | |
| 894 } | |
| 895 gesture_params->set_index(index); | |
| 896 if (pointer_action_type == | |
| 897 SyntheticPointerActionParams::PointerActionType::PRESS || | |
| 898 pointer_action_type == | |
| 899 SyntheticPointerActionParams::PointerActionType::MOVE) { | |
| 900 if (!GetArg(args, &position_x) || !GetArg(args, &position_y)) { | |
| 901 return false; | |
| 902 } | |
| 903 gesture_params->set_position(gfx::PointF(position_x, position_y)); | |
| 904 } | |
| 905 } | |
| 906 | |
| 907 if (!GetOptionalArg(args, &gesture_source_type)) { | |
| 908 return false; | |
| 909 } | |
| 910 | |
| 911 // We do not need a callback everytime sending an action? | |
| 912 scoped_refptr<CallbackAndContext> callback_and_context = | |
| 913 new CallbackAndContext(args->isolate(), callback, | |
| 914 context.web_frame()->mainWorldScriptContext()); | |
| 915 | |
| 916 // TODO(nduca): If the render_view_impl is destroyed while the gesture is in | |
| 917 // progress, we will leak the callback and context. This needs to be fixed, | |
| 918 // somehow. | |
| 919 context.render_view_impl()->GetWidget()->QueueSyntheticGesture( | |
| 920 std::move(gesture_params)); | |
| 921 | |
| 922 // At the end, ask for call back? | |
| 923 // context.render_view_impl()->GetWidget()->QueueSyntheticGesture( | |
| 924 // std::move(gesture_params), | |
| 925 // base::Bind(&OnSyntheticGestureCompleted, | |
| 926 // base::RetainedRef(callback_and_context))); | |
| 927 | |
| 928 return true; | |
| 929 } | |
| 930 | |
| 861 void GpuBenchmarking::ClearImageCache() { | 931 void GpuBenchmarking::ClearImageCache() { |
| 862 WebImageCache::clear(); | 932 WebImageCache::clear(); |
| 863 } | 933 } |
| 864 | 934 |
| 865 int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { | 935 int GpuBenchmarking::RunMicroBenchmark(gin::Arguments* args) { |
| 866 GpuBenchmarkingContext context; | 936 GpuBenchmarkingContext context; |
| 867 if (!context.Init(true)) | 937 if (!context.Init(true)) |
| 868 return 0; | 938 return 0; |
| 869 | 939 |
| 870 std::string name; | 940 std::string name; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 934 &gpu_driver_bug_workarounds))) { | 1004 &gpu_driver_bug_workarounds))) { |
| 935 return; | 1005 return; |
| 936 } | 1006 } |
| 937 | 1007 |
| 938 v8::Local<v8::Value> result; | 1008 v8::Local<v8::Value> result; |
| 939 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) | 1009 if (gin::TryConvertToV8(args->isolate(), gpu_driver_bug_workarounds, &result)) |
| 940 args->Return(result); | 1010 args->Return(result); |
| 941 } | 1011 } |
| 942 | 1012 |
| 943 } // namespace content | 1013 } // namespace content |
| OLD | NEW |