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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 class GpuBenchmarkingWrapper : public v8::Extension { | 88 class GpuBenchmarkingWrapper : public v8::Extension { |
| 89 public: | 89 public: |
| 90 GpuBenchmarkingWrapper() : | 90 GpuBenchmarkingWrapper() : |
| 91 v8::Extension(kGpuBenchmarkingExtensionName, | 91 v8::Extension(kGpuBenchmarkingExtensionName, |
| 92 "if (typeof(chrome) == 'undefined') {" | 92 "if (typeof(chrome) == 'undefined') {" |
| 93 " chrome = {};" | 93 " chrome = {};" |
| 94 "};" | 94 "};" |
| 95 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" | 95 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" |
| 96 " chrome.gpuBenchmarking = {};" | 96 " chrome.gpuBenchmarking = {};" |
| 97 "};" | 97 "};" |
| 98 "chrome.gpuBenchmarking.startRecordingRenderingStats = function() {" | |
| 99 " native function StartRecordingRenderingStats();" | |
| 100 " StartRecordingRenderingStats();" | |
| 101 "};" | |
| 102 "chrome.gpuBenchmarking.stopRecordingRenderingStats = function() {" | |
| 103 " native function GetRenderingStats();" | |
| 104 " return GetRenderingStats(true);" | |
| 105 "};" | |
| 98 "chrome.gpuBenchmarking.renderingStats = function() {" | 106 "chrome.gpuBenchmarking.renderingStats = function() {" |
| 99 " native function GetRenderingStats();" | 107 " native function GetRenderingStats();" |
| 100 " return GetRenderingStats();" | 108 " return GetRenderingStats(false);" |
| 101 "};" | 109 "};" |
| 102 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {" | 110 "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {" |
| 103 " native function PrintToSkPicture();" | 111 " native function PrintToSkPicture();" |
| 104 " return PrintToSkPicture(dirname);" | 112 " return PrintToSkPicture(dirname);" |
| 105 "};" | 113 "};" |
| 106 "chrome.gpuBenchmarking.smoothScrollBy = " | 114 "chrome.gpuBenchmarking.smoothScrollBy = " |
| 107 " function(pixels_to_scroll, opt_callback, opt_mouse_event_x," | 115 " function(pixels_to_scroll, opt_callback, opt_mouse_event_x," |
| 108 " opt_mouse_event_y) {" | 116 " opt_mouse_event_y) {" |
| 109 " pixels_to_scroll = pixels_to_scroll || 0;" | 117 " pixels_to_scroll = pixels_to_scroll || 0;" |
| 110 " callback = opt_callback || function() { };" | 118 " callback = opt_callback || function() { };" |
| 111 " native function BeginSmoothScroll();" | 119 " native function BeginSmoothScroll();" |
| 112 " if (typeof opt_mouse_event_x !== 'undefined' &&" | 120 " if (typeof opt_mouse_event_x !== 'undefined' &&" |
| 113 " typeof opt_mouse_event_y !== 'undefined') {" | 121 " typeof opt_mouse_event_y !== 'undefined') {" |
| 114 " return BeginSmoothScroll(pixels_to_scroll >= 0, callback," | 122 " return BeginSmoothScroll(pixels_to_scroll >= 0, callback," |
| 115 " Math.abs(pixels_to_scroll)," | 123 " Math.abs(pixels_to_scroll)," |
| 116 " opt_mouse_event_x, opt_mouse_event_y);" | 124 " opt_mouse_event_x, opt_mouse_event_y);" |
| 117 " } else {" | 125 " } else {" |
| 118 " return BeginSmoothScroll(pixels_to_scroll >= 0, callback," | 126 " return BeginSmoothScroll(pixels_to_scroll >= 0, callback," |
| 119 " Math.abs(pixels_to_scroll));" | 127 " Math.abs(pixels_to_scroll));" |
| 120 " }" | 128 " }" |
| 121 "};" | 129 "};" |
| 122 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" | 130 "chrome.gpuBenchmarking.runRenderingBenchmarks = function(filter) {" |
| 123 " native function RunRenderingBenchmarks();" | 131 " native function RunRenderingBenchmarks();" |
| 124 " return RunRenderingBenchmarks(filter);" | 132 " return RunRenderingBenchmarks(filter);" |
| 125 "};") {} | 133 "};") {} |
| 126 | 134 |
| 127 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 135 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| 128 v8::Handle<v8::String> name) { | 136 v8::Handle<v8::String> name) { |
| 137 if (name->Equals(v8::String::New("StartRecordingRenderingStats"))) | |
| 138 return v8::FunctionTemplate::New(StartRecordingRenderingStats); | |
| 129 if (name->Equals(v8::String::New("GetRenderingStats"))) | 139 if (name->Equals(v8::String::New("GetRenderingStats"))) |
| 130 return v8::FunctionTemplate::New(GetRenderingStats); | 140 return v8::FunctionTemplate::New(GetRenderingStats); |
| 131 if (name->Equals(v8::String::New("PrintToSkPicture"))) | 141 if (name->Equals(v8::String::New("PrintToSkPicture"))) |
| 132 return v8::FunctionTemplate::New(PrintToSkPicture); | 142 return v8::FunctionTemplate::New(PrintToSkPicture); |
| 133 if (name->Equals(v8::String::New("BeginSmoothScroll"))) | 143 if (name->Equals(v8::String::New("BeginSmoothScroll"))) |
| 134 return v8::FunctionTemplate::New(BeginSmoothScroll); | 144 return v8::FunctionTemplate::New(BeginSmoothScroll); |
| 135 if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) | 145 if (name->Equals(v8::String::New("RunRenderingBenchmarks"))) |
| 136 return v8::FunctionTemplate::New(RunRenderingBenchmarks); | 146 return v8::FunctionTemplate::New(RunRenderingBenchmarks); |
| 137 | 147 |
| 138 return v8::Handle<v8::FunctionTemplate>(); | 148 return v8::Handle<v8::FunctionTemplate>(); |
| 139 } | 149 } |
| 140 | 150 |
| 151 static v8::Handle<v8::Value> StartRecordingRenderingStats( | |
| 152 const v8::Arguments& args) { | |
| 153 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | |
| 154 if (!web_frame) | |
| 155 return v8::Undefined(); | |
| 156 | |
| 157 WebView* web_view = web_frame->view(); | |
| 158 if (!web_view) | |
| 159 return v8::Undefined(); | |
| 160 | |
| 161 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | |
| 162 if (!render_view_impl) | |
| 163 return v8::Undefined(); | |
| 164 | |
| 165 render_view_impl->StartRecordingRenderingStats(); | |
| 166 return v8::Undefined(); | |
| 167 } | |
| 168 | |
| 141 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { | 169 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { |
| 142 | 170 |
| 171 if (args.Length() != 1 || | |
| 172 !args[0]->IsBoolean()) | |
|
apatrick_chromium
2012/11/05 20:33:18
nit: this condition expression would fit on one li
| |
| 173 return v8::Undefined(); | |
| 174 | |
| 175 bool use_rendering_stats_subscriber = args[0]->BooleanValue(); | |
| 176 | |
| 143 WebFrame* web_frame = WebFrame::frameForCurrentContext(); | 177 WebFrame* web_frame = WebFrame::frameForCurrentContext(); |
| 144 if (!web_frame) | 178 if (!web_frame) |
| 145 return v8::Undefined(); | 179 return v8::Undefined(); |
| 146 | 180 |
| 147 WebView* web_view = web_frame->view(); | 181 WebView* web_view = web_frame->view(); |
| 148 if (!web_view) | 182 if (!web_view) |
| 149 return v8::Undefined(); | 183 return v8::Undefined(); |
| 150 | 184 |
| 151 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | 185 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); |
| 152 if (!render_view_impl) | 186 if (!render_view_impl) |
| 153 return v8::Undefined(); | 187 return v8::Undefined(); |
| 154 | 188 |
| 155 WebRenderingStats stats; | 189 WebRenderingStats stats; |
| 156 render_view_impl->GetRenderingStats(stats); | 190 if (use_rendering_stats_subscriber) |
| 191 render_view_impl->StopRecordingRenderingStats(stats); | |
| 192 else | |
| 193 render_view_impl->GetRenderingStats(stats); | |
| 157 | 194 |
| 158 content::GpuRenderingStats gpu_stats; | 195 content::GpuRenderingStats gpu_stats; |
| 159 render_view_impl->GetGpuRenderingStats(&gpu_stats); | 196 render_view_impl->GetGpuRenderingStats(&gpu_stats); |
| 160 v8::Handle<v8::Object> stats_object = v8::Object::New(); | 197 v8::Handle<v8::Object> stats_object = v8::Object::New(); |
| 161 stats_object->Set(v8::String::New("numAnimationFrames"), | 198 stats_object->Set(v8::String::New("numAnimationFrames"), |
| 162 v8::Integer::New(stats.numAnimationFrames)); | 199 v8::Integer::New(stats.numAnimationFrames)); |
| 163 stats_object->Set(v8::String::New("numFramesSentToScreen"), | 200 stats_object->Set(v8::String::New("numFramesSentToScreen"), |
| 164 v8::Integer::New(stats.numFramesSentToScreen)); | 201 v8::Integer::New(stats.numFramesSentToScreen)); |
| 165 stats_object->Set(v8::String::New("droppedFrameCount"), | 202 stats_object->Set(v8::String::New("droppedFrameCount"), |
| 166 v8::Integer::New(stats.droppedFrameCount)); | 203 v8::Integer::New(stats.droppedFrameCount)); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 | 405 |
| 369 return results; | 406 return results; |
| 370 } | 407 } |
| 371 }; | 408 }; |
| 372 | 409 |
| 373 v8::Extension* GpuBenchmarkingExtension::Get() { | 410 v8::Extension* GpuBenchmarkingExtension::Get() { |
| 374 return new GpuBenchmarkingWrapper(); | 411 return new GpuBenchmarkingWrapper(); |
| 375 } | 412 } |
| 376 | 413 |
| 377 } // namespace content | 414 } // namespace content |
| OLD | NEW |