Commit f18aa928 authored by ssid's avatar ssid Committed by Commit bot

Adding synthetic touch/mouse drag [Part2]

This CL adds GPU benchmarking API for drag function as next step in
adding synthetic drag feature for telemetry tests.

The part 1 of the CL can be found at crrev.com/929333002

BUG=457148

Review URL: https://codereview.chromium.org/942133002

Cr-Commit-Position: refs/heads/master@{#318687}
parent 4cc9b820
......@@ -6,6 +6,7 @@
#include "content/common/content_param_traits.h"
#include "content/common/input/synthetic_pinch_gesture_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/web_input_event_traits.h"
#include "content/common/input_messages.h"
......@@ -62,6 +63,10 @@ void ParamTraits<content::SyntheticGesturePacket>::Write(Message* m,
WriteParam(m, *content::SyntheticSmoothScrollGestureParams::Cast(
p.gesture_params()));
break;
case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
WriteParam(m, *content::SyntheticSmoothDragGestureParams::Cast(
p.gesture_params()));
break;
case content::SyntheticGestureParams::PINCH_GESTURE:
WriteParam(m, *content::SyntheticPinchGestureParams::Cast(
p.gesture_params()));
......@@ -70,10 +75,6 @@ void ParamTraits<content::SyntheticGesturePacket>::Write(Message* m,
WriteParam(m, *content::SyntheticTapGestureParams::Cast(
p.gesture_params()));
break;
// TODO(ssid): When API and IPC messages are set up, implement this.
case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
NOTIMPLEMENTED();
break;
}
}
......@@ -90,6 +91,10 @@ bool ParamTraits<content::SyntheticGesturePacket>::Read(const Message* m,
ReadGestureParams<content::SyntheticSmoothScrollGestureParams>(m,
iter);
break;
case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
gesture_params =
ReadGestureParams<content::SyntheticSmoothDragGestureParams>(m, iter);
break;
case content::SyntheticGestureParams::PINCH_GESTURE:
gesture_params =
ReadGestureParams<content::SyntheticPinchGestureParams>(m, iter);
......@@ -116,6 +121,11 @@ void ParamTraits<content::SyntheticGesturePacket>::Log(const param_type& p,
p.gesture_params()),
l);
break;
case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
LogParam(
*content::SyntheticSmoothDragGestureParams::Cast(p.gesture_params()),
l);
break;
case content::SyntheticGestureParams::PINCH_GESTURE:
LogParam(
*content::SyntheticPinchGestureParams::Cast(p.gesture_params()),
......@@ -126,10 +136,6 @@ void ParamTraits<content::SyntheticGesturePacket>::Log(const param_type& p,
*content::SyntheticTapGestureParams::Cast(p.gesture_params()),
l);
break;
// TODO(ssid): When API and IPC messages are set up, implement this.
case content::SyntheticGestureParams::SMOOTH_DRAG_GESTURE:
NOTIMPLEMENTED();
break;
}
}
......
......@@ -17,6 +17,7 @@
#include "content/common/input/synthetic_gesture_packet.h"
#include "content/common/input/synthetic_gesture_params.h"
#include "content/common/input/synthetic_pinch_gesture_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"
#include "content/common/input/touch_action.h"
......@@ -77,6 +78,13 @@ IPC_STRUCT_TRAITS_BEGIN(content::SyntheticGestureParams)
IPC_STRUCT_TRAITS_MEMBER(gesture_source_type)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::SyntheticSmoothDragGestureParams)
IPC_STRUCT_TRAITS_PARENT(content::SyntheticGestureParams)
IPC_STRUCT_TRAITS_MEMBER(start_point)
IPC_STRUCT_TRAITS_MEMBER(distances)
IPC_STRUCT_TRAITS_MEMBER(speed_in_pixels_s)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(content::SyntheticSmoothScrollGestureParams)
IPC_STRUCT_TRAITS_PARENT(content::SyntheticGestureParams)
IPC_STRUCT_TRAITS_MEMBER(anchor)
......
......@@ -14,6 +14,7 @@
#include "cc/layers/layer.h"
#include "content/common/input/synthetic_gesture_params.h"
#include "content/common/input/synthetic_pinch_gesture_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"
#include "content/public/child/v8_value_converter.h"
......@@ -381,6 +382,48 @@ bool BeginSmoothScroll(v8::Isolate* isolate,
return true;
}
bool BeginSmoothDrag(v8::Isolate* isolate,
float start_x,
float start_y,
float end_x,
float end_y,
v8::Handle<v8::Function> callback,
int gesture_source_type,
int speed_in_pixels_s) {
GpuBenchmarkingContext context;
if (!context.Init(false))
return false;
scoped_refptr<CallbackAndContext> callback_and_context =
new CallbackAndContext(isolate, callback,
context.web_frame()->mainWorldScriptContext());
scoped_ptr<SyntheticSmoothDragGestureParams> gesture_params(
new SyntheticSmoothDragGestureParams);
// Convert coordinates from CSS pixels to density independent pixels (DIPs).
float page_scale_factor = context.web_view()->pageScaleFactor();
gesture_params->start_point.SetPoint(start_x * page_scale_factor,
start_y * page_scale_factor);
gfx::PointF end_point(end_x * page_scale_factor,
end_y * page_scale_factor);
gfx::Vector2dF distance = gesture_params->start_point - end_point;
gesture_params->distances.push_back(distance);
gesture_params->speed_in_pixels_s = speed_in_pixels_s * page_scale_factor;
gesture_params->gesture_source_type =
static_cast<SyntheticGestureParams::GestureSourceType>(
gesture_source_type);
// 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()->QueueSyntheticGesture(
gesture_params.Pass(),
base::Bind(&OnSyntheticGestureCompleted, callback_and_context));
return true;
}
} // namespace
gin::WrapperInfo GpuBenchmarking::kWrapperInfo = {gin::kEmbedderNativeGin};
......@@ -425,6 +468,7 @@ gin::ObjectTemplateBuilder GpuBenchmarking::GetObjectTemplateBuilder(
.SetMethod("gestureSourceTypeSupported",
&GpuBenchmarking::GestureSourceTypeSupported)
.SetMethod("smoothScrollBy", &GpuBenchmarking::SmoothScrollBy)
.SetMethod("smoothDrag", &GpuBenchmarking::SmoothDrag)
.SetMethod("swipe", &GpuBenchmarking::Swipe)
.SetMethod("scrollBounce", &GpuBenchmarking::ScrollBounce)
// TODO(dominikg): Remove once JS interface changes have rolled into
......@@ -529,6 +573,39 @@ bool GpuBenchmarking::SmoothScrollBy(gin::Arguments* args) {
start_y);
}
bool GpuBenchmarking::SmoothDrag(gin::Arguments* args) {
GpuBenchmarkingContext context;
if (!context.Init(true))
return false;
float start_x;
float start_y;
float end_x;
float end_y;
v8::Handle<v8::Function> callback;
int gesture_source_type = SyntheticGestureParams::DEFAULT_INPUT;
int speed_in_pixels_s = 800;
if (!GetArg(args, &start_x) ||
!GetArg(args, &start_y) ||
!GetArg(args, &end_x) ||
!GetArg(args, &end_y) ||
!GetOptionalArg(args, &callback) ||
!GetOptionalArg(args, &gesture_source_type) ||
!GetOptionalArg(args, &speed_in_pixels_s)) {
return false;
}
return BeginSmoothDrag(args->isolate(),
start_x,
start_y,
end_x,
end_y,
callback,
gesture_source_type,
speed_in_pixels_s);
}
bool GpuBenchmarking::Swipe(gin::Arguments* args) {
GpuBenchmarkingContext context;
if (!context.Init(true))
......
......@@ -45,6 +45,7 @@ class GpuBenchmarking : public gin::Wrappable<GpuBenchmarking> {
void PrintToSkPicture(v8::Isolate* isolate, const std::string& dirname);
bool GestureSourceTypeSupported(int gesture_source_type);
bool SmoothScrollBy(gin::Arguments* args);
bool SmoothDrag(gin::Arguments* args);
bool Swipe(gin::Arguments* args);
bool ScrollBounce(gin::Arguments* args);
bool PinchBy(gin::Arguments* args);
......
......@@ -992,7 +992,8 @@ struct GenerateTraits<content::SyntheticGesturePacket> {
static bool Generate(content::SyntheticGesturePacket* p,
Generator* generator) {
scoped_ptr<content::SyntheticGestureParams> gesture_params;
switch (RandInRange(3)) {
switch (RandInRange(
content::SyntheticGestureParams::SYNTHETIC_GESTURE_TYPE_MAX + 1)) {
case content::SyntheticGestureParams::GestureType::
SMOOTH_SCROLL_GESTURE: {
content::SyntheticSmoothScrollGestureParams* params =
......@@ -1008,6 +1009,19 @@ struct GenerateTraits<content::SyntheticGesturePacket> {
gesture_params.reset(params);
break;
}
case content::SyntheticGestureParams::GestureType::
SMOOTH_MOUSE_DRAG_GESTURE: {
content::SyntheticSmoothMouseDragGestureParams* params =
new content::SyntheticSmoothMouseDragGestureParams();
if (!GenerateParam(&params->start_point, generator))
return false;
if (!GenerateParam(&params->distances, generator))
return false;
if (!GenerateParam(&params->speed_in_pixels_s, generator))
return false;
gesture_params.reset(params);
break;
}
case content::SyntheticGestureParams::GestureType::PINCH_GESTURE: {
content::SyntheticPinchGestureParams* params =
new content::SyntheticPinchGestureParams();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment