Chromium Code Reviews| Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
| =================================================================== |
| --- content/renderer/gpu/gpu_benchmarking_extension.cc (revision 146858) |
| +++ content/renderer/gpu/gpu_benchmarking_extension.cc (working copy) |
| @@ -4,10 +4,12 @@ |
| #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::WebFrame; |
| @@ -16,9 +18,31 @@ |
| const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
| +using WebKit::WebCanvas; |
| using WebKit::WebFrame; |
| +using WebKit::WebSize; |
| using WebKit::WebView; |
| +using WebKit::WebViewBenchmarkSupport; |
| +namespace { |
| +class SkPictureRecordingController |
| + : public WebViewBenchmarkSupport::PaintingController { |
| + public: |
| + SkPictureRecordingController(SkPicture* picture) : picture_(picture) { } |
| + |
| + // WebViewBenchmarkSupport::PaintingController overrides. |
| + virtual WebCanvas* createCanvas(const WebSize& size) { |
| + return picture_->beginRecording(size.width, size.height); |
| + } |
|
nduca
2012/07/18 06:17:47
do we use the OVERRIDE convention yet in chromium?
alokp
2012/07/18 16:00:49
Will check.
|
| + virtual void paintingComplete(const WebCanvas&) { |
| + picture_->endRecording(); |
| + } |
| + |
| + private: |
| + SkPicture* picture_; |
| +}; |
|
nduca
2012/07/18 06:17:47
Is this the right way to handle layers? You're goi
alokp
2012/07/18 16:00:49
We can do it in any number of ways:
1. multiple la
|
| +} // namespace |
| + |
| namespace content { |
| class GpuBenchmarkingWrapper : public v8::Extension { |
| @@ -35,6 +59,10 @@ |
| " native function GetRenderingStats();" |
| " return GetRenderingStats();" |
| "};" |
| + "chrome.gpuBenchmarking.printToSkPicture = function(filename) {" |
| + " native function PrintToSkPicture();" |
| + " return PrintToSkPicture(filename);" |
| + "};" |
| "chrome.gpuBenchmarking.beginSmoothScrollDown = " |
| " function(scroll_far) {" |
| " scroll_far = scroll_far || false;" |
| @@ -51,6 +79,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 +111,40 @@ |
| return stats_object; |
| } |
| + static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) { |
| + if (args.Length() != 1) |
| + return v8::Undefined(); |
| + |
| + v8::String::AsciiValue filename(args[0]); |
| + if (filename.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(); |
| + |
| + SkPicture picture; |
| + SkPictureRecordingController controller(&picture); |
| + double record_time = benchmark_support->paint( |
| + controller, |
| + WebViewBenchmarkSupport::PaintModeEverything); |
| + |
| + // Open the file into which recorded SkPicture will be dumped. |
| + // Note that for this to work Chrome needs to be launched with |
| + // --no-sandbox command-line flag. |
| + SkFILEWStream file(*filename); |
|
nduca
2012/07/18 06:17:47
We definitely want to file a bug with skia to allo
alokp
2012/07/18 16:00:49
They already have this feature. We should sync up
|
| + picture.serialize(&file); |
| + return v8::Number::New(record_time); |
|
nduca
2012/07/18 06:17:47
Any reason we need to even return this variable? S
alokp
2012/07/18 16:00:49
The same reason WebViewBenchmarkSupport::paint() r
|
| + } |
| + |
| static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { |
| WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
| if (!web_frame) |