| 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 f8365dceb4ecfb822db9012b52ea55dbd28b4e6e..68cae773989ceeb0224d1bcaecf28af5dbc1cf88 100644
|
| --- a/content/renderer/gpu/gpu_benchmarking_extension.cc
|
| +++ b/content/renderer/gpu/gpu_benchmarking_extension.cc
|
| @@ -7,6 +7,7 @@
|
| #include <string>
|
|
|
| #include "base/base64.h"
|
| +#include "base/debug/trace_event_synthetic_delay.h"
|
| #include "base/file_util.h"
|
| #include "base/files/file_path.h"
|
| #include "base/memory/scoped_vector.h"
|
| @@ -312,6 +313,14 @@ class GpuBenchmarkingWrapper : public v8::Extension {
|
| "chrome.gpuBenchmarking.hasGpuProcess = function() {"
|
| " native function HasGpuProcess();"
|
| " return HasGpuProcess();"
|
| + "};"
|
| + "chrome.gpuBenchmarking.configureSyntheticDelay = "
|
| + " function(name, target_duration, opt_mode, opt_callback) {"
|
| + " callback = opt_callback || function() { };"
|
| + " mode = opt_mode || 'static';"
|
| + " native function ConfigureSyntheticDelay();"
|
| + " return ConfigureSyntheticDelay(name, target_duration, mode,"
|
| + " callback);"
|
| "};") {}
|
|
|
| virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
|
| @@ -340,6 +349,8 @@ class GpuBenchmarkingWrapper : public v8::Extension {
|
| return v8::FunctionTemplate::New(RunMicroBenchmark);
|
| if (name->Equals(v8::String::New("HasGpuProcess")))
|
| return v8::FunctionTemplate::New(HasGpuProcess);
|
| + if (name->Equals(v8::String::New("ConfigureSyntheticDelay")))
|
| + return v8::FunctionTemplate::New(ConfigureSyntheticDelay);
|
|
|
| return v8::Handle<v8::FunctionTemplate>();
|
| }
|
| @@ -447,6 +458,18 @@ class GpuBenchmarkingWrapper : public v8::Extension {
|
| }
|
| }
|
|
|
| + static void OnConfigureSyntheticDelayCompleted(
|
| + CallbackAndContext* callback_and_context) {
|
| + v8::HandleScope scope(callback_and_context->isolate());
|
| + v8::Handle<v8::Context> context = callback_and_context->GetContext();
|
| + v8::Context::Scope context_scope(context);
|
| + WebFrame* frame = WebFrame::frameForContext(context);
|
| + if (frame) {
|
| + frame->callFunctionEvenIfScriptDisabled(
|
| + callback_and_context->GetCallback(), v8::Object::New(), 0, NULL);
|
| + }
|
| + }
|
| +
|
| static void SmoothScrollSendsTouch(
|
| const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| // TODO(epenner): Should other platforms emulate touch events?
|
| @@ -694,6 +717,58 @@ class GpuBenchmarkingWrapper : public v8::Extension {
|
| GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
|
| args.GetReturnValue().Set(!!gpu_channel);
|
| }
|
| +
|
| + static void ConfigureSyntheticDelay(
|
| + const v8::FunctionCallbackInfo<v8::Value>& args) {
|
| + GpuBenchmarkingContext context;
|
| + if (!context.Init(false)) {
|
| + args.GetReturnValue().Set(false);
|
| + return;
|
| + }
|
| +
|
| + if (args.Length() != 4 ||
|
| + !args[0]->IsString() ||
|
| + !args[1]->IsNumber() ||
|
| + !args[2]->IsString() ||
|
| + !args[3]->IsObject()) {
|
| + args.GetReturnValue().Set(false);
|
| + return;
|
| + }
|
| +
|
| + v8::String::Utf8Value name(args[0]);
|
| + base::TimeDelta target_duration =
|
| + base::TimeDelta::FromMicroseconds(args[1]->NumberValue() * 1e6);
|
| + v8::String::Utf8Value mode_value(args[2]);
|
| + v8::Local<v8::Function> callback_local =
|
| + v8::Local<v8::Function>::Cast(args[3]);
|
| + DCHECK(*name);
|
| + DCHECK(*mode_value);
|
| +
|
| + std::string mode(*mode_value);
|
| + base::debug::TraceEventSyntheticDelay::Mode delay_mode;
|
| + if (mode == "static") {
|
| + delay_mode = base::debug::TraceEventSyntheticDelay::STATIC;
|
| + } else if (mode == "oneshot") {
|
| + delay_mode = base::debug::TraceEventSyntheticDelay::ONE_SHOT;
|
| + } else if (mode == "alternating") {
|
| + delay_mode = base::debug::TraceEventSyntheticDelay::ALTERNATING;
|
| + } else {
|
| + args.GetReturnValue().Set(false);
|
| + return;
|
| + }
|
| +
|
| + scoped_refptr<CallbackAndContext> callback_and_context =
|
| + new CallbackAndContext(args.GetIsolate(),
|
| + callback_local,
|
| + context.web_frame()->mainWorldScriptContext());
|
| + context.render_view_impl()->ConfigureSyntheticDelay(
|
| + *name,
|
| + target_duration,
|
| + delay_mode,
|
| + base::Bind(&OnConfigureSyntheticDelayCompleted,
|
| + callback_and_context));
|
| + args.GetReturnValue().Set(true);
|
| + }
|
| };
|
|
|
| v8::Extension* GpuBenchmarkingExtension::Get() {
|
|
|