Chromium Code Reviews| Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
| =================================================================== |
| --- content/renderer/gpu/gpu_benchmarking_extension.cc (revision 147858) |
| +++ content/renderer/gpu/gpu_benchmarking_extension.cc (working copy) |
| @@ -3,22 +3,56 @@ |
| // found in the LICENSE file. |
| #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
| + |
| #include "content/renderer/render_view_impl.h" |
| +#include "third_party/skia/include/core/SkPicture.h" |
| +#include "third_party/skia/include/core/SkStream.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| #include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| -#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h" |
| #include "v8/include/v8.h" |
| +using WebKit::WebCanvas; |
| using WebKit::WebFrame; |
| using WebKit::WebRenderingStats; |
| +using WebKit::WebSize; |
| using WebKit::WebView; |
| +using WebKit::WebViewBenchmarkSupport; |
| const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
| -using WebKit::WebFrame; |
| -using WebKit::WebView; |
| +namespace { |
|
piman
2012/07/27 17:55:58
nit: blank line below
alokp
2012/07/27 18:32:44
Done.
|
| +class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { |
| + public: |
| + explicit SkPictureRecorder(const std::string& dirname) : |
|
piman
2012/07/27 17:55:58
nit: style - ':' goes on next line
alokp
2012/07/27 18:32:44
Done.
|
| + dirname_(dirname), |
| + layer_id_(0) { |
| + } |
| + virtual WebCanvas* willPaint(const WebSize& size) OVERRIDE { |
|
jamesr
2012/07/27 17:54:36
If you are implementing something from the WebKit
alokp
2012/07/27 18:32:44
Done.
|
| + return picture_.beginRecording(size.width, size.height); |
| + } |
|
piman
2012/07/27 17:55:58
nit: blank line below
alokp
2012/07/27 18:32:44
Done.
|
| + virtual void didPaint(WebCanvas* canvas) OVERRIDE { |
|
jamesr
2012/07/27 17:54:36
newline before new function
jamesr
2012/07/27 17:54:36
No OVERRIDE
alokp
2012/07/27 18:32:44
Done.
alokp
2012/07/27 18:32:44
Done.
|
| + DCHECK(canvas == picture_.getRecordingCanvas()); |
| + picture_.endRecording(); |
| + // Serialize picture to file. |
| + // Note that for this to work Chrome needs to be launched with |
| + // --no-sandbox command-line flag. |
|
piman
2012/07/27 17:55:58
What could we do to remove that restriction?
alokp
2012/07/27 18:32:44
The benchmarks could also be run on a picture seri
piman
2012/07/27 20:59:31
For example, using the file picker.
I won't block
alokp
2012/07/30 18:05:12
May be I am missing something. The issue here is w
|
| + std::ostringstream stream; |
|
jamesr
2012/07/27 17:54:36
chromium style is to not use streams for things li
alokp
2012/07/27 18:32:44
Done.
|
| + stream << dirname_ << '/' << "layer_" << layer_id_++ << ".skp"; |
|
piman
2012/07/27 17:55:58
use FilePath instead of streams (prohibited) to co
alokp
2012/07/27 18:32:44
FilePath may be an overkill for this use-case. I s
piman
2012/07/27 20:59:31
http://www.chromium.org/developers/coding-style ex
alokp
2012/07/30 18:05:12
Done.
|
| + std::string filepath = stream.str(); |
| + SkFILEWStream file(filepath.c_str()); |
| + picture_.serialize(&file); |
| + } |
| + |
| + private: |
| + std::string dirname_; |
| + int layer_id_; |
| + SkPicture picture_; |
| +}; |
|
piman
2012/07/27 17:55:58
nit: blank line below
alokp
2012/07/27 18:32:44
Done.
|
| +} // namespace |
| + |
| namespace content { |
| class GpuBenchmarkingWrapper : public v8::Extension { |
| @@ -35,6 +69,10 @@ |
| " native function GetRenderingStats();" |
| " return GetRenderingStats();" |
| "};" |
| + "chrome.gpuBenchmarking.printToSkPicture = function(dirname) {" |
| + " native function PrintToSkPicture();" |
| + " return PrintToSkPicture(dirname);" |
| + "};" |
| "chrome.gpuBenchmarking.beginSmoothScrollDown = " |
| " function(scroll_far) {" |
| " scroll_far = scroll_far || false;" |
| @@ -51,6 +89,8 @@ |
| v8::Handle<v8::String> name) { |
| if (name->Equals(v8::String::New("GetRenderingStats"))) |
| return v8::FunctionTemplate::New(GetRenderingStats); |
| + if (name->Equals(v8::String::New("PrintToSkPicture"))) |
| + return v8::FunctionTemplate::New(PrintToSkPicture); |
| if (name->Equals(v8::String::New("BeginSmoothScroll"))) |
| return v8::FunctionTemplate::New(BeginSmoothScroll); |
| @@ -81,6 +121,32 @@ |
| return stats_object; |
| } |
| + static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) { |
| + if (args.Length() != 1) |
| + return v8::Undefined(); |
| + |
| + v8::String::AsciiValue dirname(args[0]); |
| + if (dirname.length() == 0) |
| + return v8::Undefined(); |
| + |
| + WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| + if (!web_frame) |
| + return v8::Undefined(); |
| + |
| + WebView* web_view = web_frame->view(); |
| + if (!web_view) |
| + return v8::Undefined(); |
| + |
| + WebViewBenchmarkSupport* benchmark_support = web_view->benchmarkSupport(); |
| + if (!benchmark_support) |
| + return v8::Undefined(); |
| + |
| + SkPictureRecorder recorder(*dirname); |
| + benchmark_support->paint(&recorder, |
| + WebViewBenchmarkSupport::PaintModeEverything); |
| + return v8::Undefined(); |
| + } |
| + |
| static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { |
| WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| if (!web_frame) |