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,32 @@ |
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); |
+ } |
+ virtual void paintingComplete(const WebCanvas&) { |
+ picture_->endRecording(); |
+ } |
+ |
+private: |
+ SkPicture* picture_; |
+}; |
+} // namespace |
+ |
namespace content { |
class GpuBenchmarkingWrapper : public v8::Extension { |
@@ -35,6 +60,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 +80,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 +112,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); |
+ picture.serialize(&file); |
+ return v8::Number::New(record_time); |
+ } |
+ |
static v8::Handle<v8::Value> BeginSmoothScroll(const v8::Arguments& args) { |
WebFrame* web_frame = WebFrame::frameForEnteredContext(); |
if (!web_frame) |