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 #include "content/renderer/render_view_impl.h" | 6 #include "content/renderer/render_view_impl.h" |
| 7 #include "third_party/skia/include/core/SkPicture.h" | |
| 8 #include "third_party/skia/include/core/SkStream.h" | |
| 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 7 #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h " | 10 #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" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSuppo rt.h" |
| 11 #include "v8/include/v8.h" | 13 #include "v8/include/v8.h" |
| 12 | 14 |
| 13 using WebKit::WebFrame; | 15 using WebKit::WebFrame; |
| 14 using WebKit::WebRenderingStats; | 16 using WebKit::WebRenderingStats; |
| 15 using WebKit::WebView; | 17 using WebKit::WebView; |
| 16 | 18 |
| 17 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 19 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
| 18 | 20 |
| 21 using WebKit::WebCanvas; | |
| 19 using WebKit::WebFrame; | 22 using WebKit::WebFrame; |
| 23 using WebKit::WebSize; | |
| 20 using WebKit::WebView; | 24 using WebKit::WebView; |
| 25 using WebKit::WebViewBenchmarkSupport; | |
| 26 | |
| 27 namespace { | |
| 28 class SkPictureRecordingController : | |
| 29 public WebViewBenchmarkSupport::PaintingController | |
| 30 { | |
| 31 public: | |
| 32 SkPictureRecordingController(SkPicture* picture) : picture_(picture) { } | |
| 33 | |
| 34 // WebViewBenchmarkSupport::PaintingController overrides. | |
| 35 virtual WebCanvas* createCanvas(const WebSize& size) { | |
| 36 return picture_->beginRecording(size.width, size.height); | |
| 37 } | |
| 38 virtual void paintingComplete(const WebCanvas&) { | |
| 39 picture_->endRecording(); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 SkPicture* picture_; | |
| 44 }; | |
| 45 } // namespace | |
| 21 | 46 |
| 22 namespace content { | 47 namespace content { |
| 23 | 48 |
| 24 class GpuBenchmarkingWrapper : public v8::Extension { | 49 class GpuBenchmarkingWrapper : public v8::Extension { |
| 25 public: | 50 public: |
| 26 GpuBenchmarkingWrapper() : | 51 GpuBenchmarkingWrapper() : |
| 27 v8::Extension(kGpuBenchmarkingExtensionName, | 52 v8::Extension(kGpuBenchmarkingExtensionName, |
| 28 "if (typeof(chrome) == 'undefined') {" | 53 "if (typeof(chrome) == 'undefined') {" |
| 29 " chrome = {};" | 54 " chrome = {};" |
| 30 "};" | 55 "};" |
| 31 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" | 56 "if (typeof(chrome.gpuBenchmarking) == 'undefined') {" |
| 32 " chrome.gpuBenchmarking = {};" | 57 " chrome.gpuBenchmarking = {};" |
| 33 "};" | 58 "};" |
| 34 "chrome.gpuBenchmarking.renderingStats = function() {" | 59 "chrome.gpuBenchmarking.renderingStats = function() {" |
| 35 " native function GetRenderingStats();" | 60 " native function GetRenderingStats();" |
| 36 " return GetRenderingStats();" | 61 " return GetRenderingStats();" |
| 37 "};" | 62 "};" |
| 63 "chrome.gpuBenchmarking.printToSkPicture = function(filename) {" | |
| 64 " native function PrintToSkPicture();" | |
| 65 " return PrintToSkPicture(filename);" | |
| 66 "};" | |
| 38 "chrome.gpuBenchmarking.beginSmoothScrollDown = " | 67 "chrome.gpuBenchmarking.beginSmoothScrollDown = " |
| 39 " function(scroll_far) {" | 68 " function(scroll_far) {" |
| 40 " scroll_far = scroll_far || false;" | 69 " scroll_far = scroll_far || false;" |
| 41 " native function BeginSmoothScroll();" | 70 " native function BeginSmoothScroll();" |
| 42 " return BeginSmoothScroll(true, scroll_far);" | 71 " return BeginSmoothScroll(true, scroll_far);" |
| 43 "};" | 72 "};" |
| 44 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" | 73 "chrome.gpuBenchmarking.beginSmoothScrollUp = function(scroll_far) {" |
| 45 " scroll_far = scroll_far || false;" | 74 " scroll_far = scroll_far || false;" |
| 46 " native function BeginSmoothScroll();" | 75 " native function BeginSmoothScroll();" |
| 47 " return BeginSmoothScroll(false, scroll_far);" | 76 " return BeginSmoothScroll(false, scroll_far);" |
| 48 "};") {} | 77 "};") {} |
| 49 | 78 |
| 50 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 79 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
| 51 v8::Handle<v8::String> name) { | 80 v8::Handle<v8::String> name) { |
| 52 if (name->Equals(v8::String::New("GetRenderingStats"))) | 81 if (name->Equals(v8::String::New("GetRenderingStats"))) |
| 53 return v8::FunctionTemplate::New(GetRenderingStats); | 82 return v8::FunctionTemplate::New(GetRenderingStats); |
| 83 if (name->Equals(v8::String::New("PrintToSkPicture"))) | |
| 84 return v8::FunctionTemplate::New(PrintToSkPicture); | |
| 54 if (name->Equals(v8::String::New("BeginSmoothScroll"))) | 85 if (name->Equals(v8::String::New("BeginSmoothScroll"))) |
| 55 return v8::FunctionTemplate::New(BeginSmoothScroll); | 86 return v8::FunctionTemplate::New(BeginSmoothScroll); |
| 56 | 87 |
| 57 return v8::Handle<v8::FunctionTemplate>(); | 88 return v8::Handle<v8::FunctionTemplate>(); |
| 58 } | 89 } |
| 59 | 90 |
| 60 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { | 91 static v8::Handle<v8::Value> GetRenderingStats(const v8::Arguments& args) { |
| 61 WebFrame* web_frame = WebFrame::frameForEnteredContext(); | 92 WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| 62 if (!web_frame) | 93 if (!web_frame) |
| 63 return v8::Undefined(); | 94 return v8::Undefined(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 74 stats_object->Set(v8::String::New("numAnimationFrames"), | 105 stats_object->Set(v8::String::New("numAnimationFrames"), |
| 75 v8::Integer::New(stats.numAnimationFrames), | 106 v8::Integer::New(stats.numAnimationFrames), |
| 76 v8::ReadOnly); | 107 v8::ReadOnly); |
| 77 if (stats.numFramesSentToScreen) | 108 if (stats.numFramesSentToScreen) |
| 78 stats_object->Set(v8::String::New("numFramesSentToScreen"), | 109 stats_object->Set(v8::String::New("numFramesSentToScreen"), |
| 79 v8::Integer::New(stats.numFramesSentToScreen), | 110 v8::Integer::New(stats.numFramesSentToScreen), |
| 80 v8::ReadOnly); | 111 v8::ReadOnly); |
| 81 return stats_object; | 112 return stats_object; |
| 82 } | 113 } |
| 83 | 114 |
| 115 static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) { | |
| 116 if (args.Length() != 1) | |
| 117 return v8::Undefined(); | |
| 118 | |
| 119 v8::String::AsciiValue filename(args[0]); | |
| 120 if (filename.length() == 0) | |
| 121 return v8::Undefined(); | |
| 122 | |
| 123 WebFrame* web_frame = WebFrame::frameForEnteredContext(); | |
| 124 if (!web_frame) | |
| 125 return v8::Undefined(); | |
| 126 | |
| 127 WebView* web_view = web_frame->view(); | |
| 128 if (!web_view) | |
| 129 return v8::Undefined(); | |
| 130 | |
| 131 WebViewBenchmarkSupport* benchmark_support = web_view->benchmarkSupport(); | |
| 132 if (!benchmark_support) | |
| 133 return v8::Undefined(); | |
| 134 | |
| 135 SkPicture picture; | |
| 136 SkPictureRecordingController controller(&picture); | |
| 137 double record_time = benchmark_support->paint( | |
| 138 controller, | |
| 139 WebViewBenchmarkSupport::PaintModeEverything); | |
| 140 | |
| 141 // Open the file into which recorded SkPicture will be dumped. | |
| 142 // Note that for this to work Chrome needs to be launched with | |
| 143 // --no-sandbox command-line flag. | |
| 144 SkFILEWStream file(*filename); | |
| 145 picture.serialize(&file); | |
| 146 return v8::Number::New(record_time); | |
| 147 } | |
| 148 | |
| 84 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { | 149 static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { |
| 85 WebFrame* web_frame = WebFrame::frameForEnteredContext(); | 150 WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| 86 if (!web_frame) | 151 if (!web_frame) |
| 87 return v8::Undefined(); | 152 return v8::Undefined(); |
| 88 | 153 |
| 89 WebView* web_view = web_frame->view(); | 154 WebView* web_view = web_frame->view(); |
| 90 if (!web_view) | 155 if (!web_view) |
| 91 return v8::Undefined(); | 156 return v8::Undefined(); |
| 92 | 157 |
| 93 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); | 158 RenderViewImpl* render_view_impl = RenderViewImpl::FromWebView(web_view); |
| 94 if (!render_view_impl) | 159 if (!render_view_impl) |
| 95 return v8::Undefined(); | 160 return v8::Undefined(); |
| 96 | 161 |
| 97 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) | 162 if (args.Length() != 2 || !args[0]->IsBoolean() || !args[1]->IsBoolean()) |
| 98 return v8::False(); | 163 return v8::False(); |
| 99 | 164 |
| 100 bool scroll_down = args[0]->BooleanValue(); | 165 bool scroll_down = args[0]->BooleanValue(); |
| 101 bool scroll_far = args[1]->BooleanValue(); | 166 bool scroll_far = args[1]->BooleanValue(); |
| 102 | 167 |
| 103 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); | 168 render_view_impl->BeginSmoothScroll(scroll_down, scroll_far); |
| 104 return v8::True(); | 169 return v8::True(); |
| 105 } | 170 } |
| 106 }; | 171 }; |
| 107 | 172 |
| 108 v8::Extension* GpuBenchmarkingExtension::Get() { | 173 v8::Extension* GpuBenchmarkingExtension::Get() { |
| 109 return new GpuBenchmarkingWrapper(); | 174 return new GpuBenchmarkingWrapper(); |
|
alokp
2012/07/17 17:06:56
does this get deleted somewhere?
| |
| 110 } | 175 } |
| 111 | 176 |
| 112 } // namespace content | 177 } // namespace content |
| OLD | NEW |