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 "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h
" |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
7 #include "v8/include/v8.h" | 10 #include "v8/include/v8.h" |
8 | 11 |
| 12 using WebKit::WebFrame; |
| 13 using WebKit::WebRenderingStats; |
| 14 using WebKit::WebView; |
| 15 |
9 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 16 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
10 | 17 |
11 namespace content { | 18 namespace content { |
12 | 19 |
13 class GpuBenchmarkingWrapper : public v8::Extension { | 20 class GpuBenchmarkingWrapper : public v8::Extension { |
14 public: | 21 public: |
15 GpuBenchmarkingWrapper() : | 22 GpuBenchmarkingWrapper() : |
16 v8::Extension(kGpuBenchmarkingExtensionName, | 23 v8::Extension(kGpuBenchmarkingExtensionName, |
17 "if (typeof(chrome) == 'undefined') {" | 24 "if (typeof(chrome) == 'undefined') {" |
18 " chrome = {};" | 25 " chrome = {};" |
19 "};" | 26 "};" |
20 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" | 27 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" |
21 " chrome.gpuBenchmarking = {};" | 28 " chrome.gpuBenchmarking = {};" |
| 29 "};" |
| 30 "chrome.gpuBenchmarking.renderingStats = function() {" |
| 31 " native function GetRenderingStats();" |
| 32 " return GetRenderingStats();" |
22 "};") {} | 33 "};") {} |
23 | 34 |
24 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 35 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
25 v8::Handle<v8::String> name) { | 36 v8::Handle<v8::String> name) { |
| 37 if (name->Equals(v8::String::New("GetRenderingStats"))) |
| 38 return v8::FunctionTemplate::New(GetRenderingStats); |
| 39 |
26 return v8::Handle<v8::FunctionTemplate>(); | 40 return v8::Handle<v8::FunctionTemplate>(); |
27 } | 41 } |
| 42 |
| 43 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { |
| 44 WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| 45 if (!web_frame) |
| 46 return v8::Undefined(); |
| 47 |
| 48 WebView* web_view = web_frame->view(); |
| 49 if (!web_view) |
| 50 return v8::Undefined(); |
| 51 |
| 52 WebRenderingStats stats; |
| 53 web_view->renderingStats(stats); |
| 54 |
| 55 v8::Handle<v8::Object> stats_object = v8::Object::New(); |
| 56 if (stats.numAnimationFrames) |
| 57 stats_object->Set(v8::String::New("numAnimationFrames"), |
| 58 v8::Integer::New(stats.numAnimationFrames), |
| 59 v8::ReadOnly); |
| 60 if (stats.numFramesSentToScreen) |
| 61 stats_object->Set(v8::String::New("numFramesSentToScreen"), |
| 62 v8::Integer::New(stats.numFramesSentToScreen), |
| 63 v8::ReadOnly); |
| 64 return stats_object; |
| 65 } |
28 }; | 66 }; |
29 | 67 |
30 v8::Extension* GpuBenchmarkingExtension::Get() { | 68 v8::Extension* GpuBenchmarkingExtension::Get() { |
31 return new GpuBenchmarkingWrapper(); | 69 return new GpuBenchmarkingWrapper(); |
32 } | 70 } |
33 | 71 |
34 } // namespace content | 72 } // namespace content |
OLD | NEW |