Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
diff --git a/content/renderer/gpu/gpu_benchmarking_extension.cc b/content/renderer/gpu/gpu_benchmarking_extension.cc |
index e8d968e399bfe277861e8d0591df65e7c8ea121a..5a4a954fdb499e216f52f673469a9a730d27508b 100644 |
--- a/content/renderer/gpu/gpu_benchmarking_extension.cc |
+++ b/content/renderer/gpu/gpu_benchmarking_extension.cc |
@@ -20,6 +20,8 @@ |
#include "content/common/child_process_messages.h" |
#include "content/common/input/synthetic_gesture_params.h" |
#include "content/common/input/synthetic_pinch_gesture_params.h" |
+#include "content/common/input/synthetic_pointer_action_list_params.h" |
+#include "content/common/input/synthetic_pointer_action_params.h" |
#include "content/common/input/synthetic_smooth_drag_gesture_params.h" |
#include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
#include "content/common/input/synthetic_tap_gesture_params.h" |
@@ -509,6 +511,7 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder( |
.SetMethod("visualViewportHeight", &GpuBenchmarking::VisualViewportHeight) |
.SetMethod("visualViewportWidth", &GpuBenchmarking::VisualViewportWidth) |
.SetMethod("tap", &GpuBenchmarking::Tap) |
+ .SetMethod("touchActionSequence", &GpuBenchmarking::TouchActionSequence) |
.SetMethod("clearImageCache", &GpuBenchmarking::ClearImageCache) |
.SetMethod("runMicroBenchmark", &GpuBenchmarking::RunMicroBenchmark) |
.SetMethod("sendMessageToMicroBenchmark", |
@@ -929,6 +932,67 @@ bool GpuBenchmarking::Tap(gin::Arguments* args) { |
return true; |
} |
+bool GpuBenchmarking::TouchActionSequence(gin::Arguments* args) { |
+ GpuBenchmarkingContext context; |
+ if (!context.Init(false)) |
+ return false; |
+ |
+ v8::Local<v8::Function> callback; |
+ // pass a two-dimensional list of actions. |
+ int pointer_action_type_int; |
+ int index; |
+ float position_x; |
+ float position_y; |
+ int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT; |
+ SyntheticPointerActionParams::PointerActionType pointer_action_type; |
+ if (!GetArg(args, &pointer_action_type_int)) { |
lanwei
2016/09/15 20:26:50
This is a simple version of getting just one actio
samuong
2016/09/23 12:53:40
Since this is just sample code, maybe this should
|
+ return false; |
+ } |
+ pointer_action_type = |
+ static_cast<SyntheticPointerActionParams::PointerActionType>( |
+ pointer_action_type_int); |
+ SyntheticPointerActionParams gesture_params(pointer_action_type); |
+ |
+ if (pointer_action_type != |
+ SyntheticPointerActionParams::PointerActionType::PROCESS && |
+ pointer_action_type != |
+ SyntheticPointerActionParams::PointerActionType::FINISH) { |
+ if (!GetArg(args, &index)) { |
+ return false; |
+ } |
+ gesture_params.set_index(index); |
+ if (pointer_action_type == |
+ SyntheticPointerActionParams::PointerActionType::PRESS || |
+ pointer_action_type == |
+ SyntheticPointerActionParams::PointerActionType::MOVE) { |
+ if (!GetArg(args, &position_x) || !GetArg(args, &position_y)) { |
+ return false; |
+ } |
+ gesture_params.set_position(gfx::PointF(position_x, position_y)); |
+ } |
+ } |
+ |
+ if (!GetOptionalArg(args, &gesture_source_type)) { |
+ return false; |
+ } |
+ |
+ std::unique_ptr<SyntheticPointerActionListParams> gesture_params_list( |
+ new SyntheticPointerActionListParams(gesture_params)); |
+ |
+ // At the end, we will send a 'FINISH' action and need a callback. |
+ scoped_refptr<CallbackAndContext> callback_and_context = |
+ new CallbackAndContext(args->isolate(), callback, |
+ context.web_frame()->mainWorldScriptContext()); |
+ // TODO(nduca): If the render_view_impl is destroyed while the gesture is in |
+ // progress, we will leak the callback and context. This needs to be fixed, |
+ // somehow. |
+ context.render_view_impl()->GetWidget()->QueueSyntheticGesture( |
+ std::move(gesture_params_list), |
+ base::Bind(&OnSyntheticGestureCompleted, |
+ base::RetainedRef(callback_and_context))); |
+ return true; |
+} |
+ |
void GpuBenchmarking::ClearImageCache() { |
WebImageCache::clear(); |
} |