Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(802)

Side by Side Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 83483007: Expose synthetic delays through the GPU benchmarking extension (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/debug/trace_event_synthetic_delay.h"
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "cc/layers/layer.h" 15 #include "cc/layers/layer.h"
15 #include "content/common/browser_rendering_stats.h" 16 #include "content/common/browser_rendering_stats.h"
16 #include "content/common/gpu/gpu_rendering_stats.h" 17 #include "content/common/gpu/gpu_rendering_stats.h"
17 #include "content/public/renderer/render_thread.h" 18 #include "content/public/renderer/render_thread.h"
18 #include "content/public/renderer/v8_value_converter.h" 19 #include "content/public/renderer/v8_value_converter.h"
19 #include "content/renderer/gpu/render_widget_compositor.h" 20 #include "content/renderer/gpu/render_widget_compositor.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 "};" 306 "};"
306 "chrome.gpuBenchmarking.runMicroBenchmark =" 307 "chrome.gpuBenchmarking.runMicroBenchmark ="
307 " function(name, callback, opt_arguments) {" 308 " function(name, callback, opt_arguments) {"
308 " arguments = opt_arguments || {};" 309 " arguments = opt_arguments || {};"
309 " native function RunMicroBenchmark();" 310 " native function RunMicroBenchmark();"
310 " return RunMicroBenchmark(name, callback, arguments);" 311 " return RunMicroBenchmark(name, callback, arguments);"
311 "};" 312 "};"
312 "chrome.gpuBenchmarking.hasGpuProcess = function() {" 313 "chrome.gpuBenchmarking.hasGpuProcess = function() {"
313 " native function HasGpuProcess();" 314 " native function HasGpuProcess();"
314 " return HasGpuProcess();" 315 " return HasGpuProcess();"
316 "};"
317 "chrome.gpuBenchmarking.configureSyntheticDelay = "
318 " function(name, target_duration, opt_mode, opt_callback) {"
319 " callback = opt_callback || function() { };"
320 " mode = opt_mode || 'static';"
321 " native function ConfigureSyntheticDelay();"
322 " return ConfigureSyntheticDelay(name, target_duration, mode,"
323 " callback);"
315 "};") {} 324 "};") {}
316 325
317 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 326 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
318 v8::Handle<v8::String> name) OVERRIDE { 327 v8::Handle<v8::String> name) OVERRIDE {
319 if (name->Equals(v8::String::New("SetNeedsDisplayOnAllLayers"))) 328 if (name->Equals(v8::String::New("SetNeedsDisplayOnAllLayers")))
320 return v8::FunctionTemplate::New(SetNeedsDisplayOnAllLayers); 329 return v8::FunctionTemplate::New(SetNeedsDisplayOnAllLayers);
321 if (name->Equals(v8::String::New("SetRasterizeOnlyVisibleContent"))) 330 if (name->Equals(v8::String::New("SetRasterizeOnlyVisibleContent")))
322 return v8::FunctionTemplate::New(SetRasterizeOnlyVisibleContent); 331 return v8::FunctionTemplate::New(SetRasterizeOnlyVisibleContent);
323 if (name->Equals(v8::String::New("GetRenderingStats"))) 332 if (name->Equals(v8::String::New("GetRenderingStats")))
324 return v8::FunctionTemplate::New(GetRenderingStats); 333 return v8::FunctionTemplate::New(GetRenderingStats);
325 if (name->Equals(v8::String::New("GetGpuRenderingStats"))) 334 if (name->Equals(v8::String::New("GetGpuRenderingStats")))
326 return v8::FunctionTemplate::New(GetGpuRenderingStats); 335 return v8::FunctionTemplate::New(GetGpuRenderingStats);
327 if (name->Equals(v8::String::New("PrintToSkPicture"))) 336 if (name->Equals(v8::String::New("PrintToSkPicture")))
328 return v8::FunctionTemplate::New(PrintToSkPicture); 337 return v8::FunctionTemplate::New(PrintToSkPicture);
329 if (name->Equals(v8::String::New("BeginSmoothScroll"))) 338 if (name->Equals(v8::String::New("BeginSmoothScroll")))
330 return v8::FunctionTemplate::New(BeginSmoothScroll); 339 return v8::FunctionTemplate::New(BeginSmoothScroll);
331 if (name->Equals(v8::String::New("SmoothScrollSendsTouch"))) 340 if (name->Equals(v8::String::New("SmoothScrollSendsTouch")))
332 return v8::FunctionTemplate::New(SmoothScrollSendsTouch); 341 return v8::FunctionTemplate::New(SmoothScrollSendsTouch);
333 if (name->Equals(v8::String::New("BeginPinch"))) 342 if (name->Equals(v8::String::New("BeginPinch")))
334 return v8::FunctionTemplate::New(BeginPinch); 343 return v8::FunctionTemplate::New(BeginPinch);
335 if (name->Equals(v8::String::New("BeginWindowSnapshotPNG"))) 344 if (name->Equals(v8::String::New("BeginWindowSnapshotPNG")))
336 return v8::FunctionTemplate::New(BeginWindowSnapshotPNG); 345 return v8::FunctionTemplate::New(BeginWindowSnapshotPNG);
337 if (name->Equals(v8::String::New("ClearImageCache"))) 346 if (name->Equals(v8::String::New("ClearImageCache")))
338 return v8::FunctionTemplate::New(ClearImageCache); 347 return v8::FunctionTemplate::New(ClearImageCache);
339 if (name->Equals(v8::String::New("RunMicroBenchmark"))) 348 if (name->Equals(v8::String::New("RunMicroBenchmark")))
340 return v8::FunctionTemplate::New(RunMicroBenchmark); 349 return v8::FunctionTemplate::New(RunMicroBenchmark);
341 if (name->Equals(v8::String::New("HasGpuProcess"))) 350 if (name->Equals(v8::String::New("HasGpuProcess")))
342 return v8::FunctionTemplate::New(HasGpuProcess); 351 return v8::FunctionTemplate::New(HasGpuProcess);
352 if (name->Equals(v8::String::New("ConfigureSyntheticDelay")))
353 return v8::FunctionTemplate::New(ConfigureSyntheticDelay);
343 354
344 return v8::Handle<v8::FunctionTemplate>(); 355 return v8::Handle<v8::FunctionTemplate>();
345 } 356 }
346 357
347 static void SetNeedsDisplayOnAllLayers( 358 static void SetNeedsDisplayOnAllLayers(
348 const v8::FunctionCallbackInfo<v8::Value>& args) { 359 const v8::FunctionCallbackInfo<v8::Value>& args) {
349 GpuBenchmarkingContext context; 360 GpuBenchmarkingContext context;
350 if (!context.Init(true)) 361 if (!context.Init(true))
351 return; 362 return;
352 363
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 v8::HandleScope scope(callback_and_context->isolate()); 451 v8::HandleScope scope(callback_and_context->isolate());
441 v8::Handle<v8::Context> context = callback_and_context->GetContext(); 452 v8::Handle<v8::Context> context = callback_and_context->GetContext();
442 v8::Context::Scope context_scope(context); 453 v8::Context::Scope context_scope(context);
443 WebFrame* frame = WebFrame::frameForContext(context); 454 WebFrame* frame = WebFrame::frameForContext(context);
444 if (frame) { 455 if (frame) {
445 frame->callFunctionEvenIfScriptDisabled( 456 frame->callFunctionEvenIfScriptDisabled(
446 callback_and_context->GetCallback(), v8::Object::New(), 0, NULL); 457 callback_and_context->GetCallback(), v8::Object::New(), 0, NULL);
447 } 458 }
448 } 459 }
449 460
461 static void OnConfigureSyntheticDelayCompleted(
462 CallbackAndContext* callback_and_context) {
463 v8::HandleScope scope(callback_and_context->isolate());
464 v8::Handle<v8::Context> context = callback_and_context->GetContext();
465 v8::Context::Scope context_scope(context);
466 WebFrame* frame = WebFrame::frameForContext(context);
467 if (frame) {
468 frame->callFunctionEvenIfScriptDisabled(
469 callback_and_context->GetCallback(), v8::Object::New(), 0, NULL);
470 }
471 }
472
450 static void SmoothScrollSendsTouch( 473 static void SmoothScrollSendsTouch(
451 const v8::FunctionCallbackInfo<v8::Value>& args) { 474 const v8::FunctionCallbackInfo<v8::Value>& args) {
452 // TODO(epenner): Should other platforms emulate touch events? 475 // TODO(epenner): Should other platforms emulate touch events?
453 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 476 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
454 args.GetReturnValue().Set(true); 477 args.GetReturnValue().Set(true);
455 #else 478 #else
456 args.GetReturnValue().Set(false); 479 args.GetReturnValue().Set(false);
457 #endif 480 #endif
458 } 481 }
459 482
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 args.GetReturnValue().Set(context.compositor()->ScheduleMicroBenchmark( 710 args.GetReturnValue().Set(context.compositor()->ScheduleMicroBenchmark(
688 std::string(*benchmark), 711 std::string(*benchmark),
689 value.Pass(), 712 value.Pass(),
690 base::Bind(&OnMicroBenchmarkCompleted, callback_and_context))); 713 base::Bind(&OnMicroBenchmarkCompleted, callback_and_context)));
691 } 714 }
692 715
693 static void HasGpuProcess(const v8::FunctionCallbackInfo<v8::Value>& args) { 716 static void HasGpuProcess(const v8::FunctionCallbackInfo<v8::Value>& args) {
694 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); 717 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
695 args.GetReturnValue().Set(!!gpu_channel); 718 args.GetReturnValue().Set(!!gpu_channel);
696 } 719 }
720
721 static void ConfigureSyntheticDelay(
722 const v8::FunctionCallbackInfo<v8::Value>& args) {
723 GpuBenchmarkingContext context;
724 if (!context.Init(false)) {
725 args.GetReturnValue().Set(false);
726 return;
727 }
728
729 if (args.Length() != 4 ||
730 !args[0]->IsString() ||
731 !args[1]->IsNumber() ||
732 !args[2]->IsString() ||
733 !args[3]->IsObject()) {
734 args.GetReturnValue().Set(false);
735 return;
736 }
737
738 v8::String::Utf8Value name(args[0]);
739 base::TimeDelta target_duration =
740 base::TimeDelta::FromMicroseconds(args[1]->NumberValue() * 1e6);
741 v8::String::Utf8Value mode_value(args[2]);
742 v8::Local<v8::Function> callback_local =
743 v8::Local<v8::Function>::Cast(args[3]);
744 DCHECK(*name);
745 DCHECK(*mode_value);
746
747 std::string mode(*mode_value);
748 base::debug::TraceEventSyntheticDelay::Mode delay_mode;
749 if (mode == "static") {
750 delay_mode = base::debug::TraceEventSyntheticDelay::STATIC;
751 } else if (mode == "oneshot") {
752 delay_mode = base::debug::TraceEventSyntheticDelay::ONE_SHOT;
753 } else if (mode == "alternating") {
754 delay_mode = base::debug::TraceEventSyntheticDelay::ALTERNATING;
755 } else {
756 args.GetReturnValue().Set(false);
757 return;
758 }
759
760 scoped_refptr<CallbackAndContext> callback_and_context =
761 new CallbackAndContext(args.GetIsolate(),
762 callback_local,
763 context.web_frame()->mainWorldScriptContext());
764 context.render_view_impl()->ConfigureSyntheticDelay(
765 *name,
766 target_duration,
767 delay_mode,
768 base::Bind(&OnConfigureSyntheticDelayCompleted,
769 callback_and_context));
770 args.GetReturnValue().Set(true);
771 }
697 }; 772 };
698 773
699 v8::Extension* GpuBenchmarkingExtension::Get() { 774 v8::Extension* GpuBenchmarkingExtension::Get() {
700 return new GpuBenchmarkingWrapper(); 775 return new GpuBenchmarkingWrapper();
701 } 776 }
702 777
703 } // namespace content 778 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698