Index: content/renderer/gpu/gpu_benchmarking_extension.cc |
=================================================================== |
--- content/renderer/gpu/gpu_benchmarking_extension.cc (revision 148755) |
+++ content/renderer/gpu/gpu_benchmarking_extension.cc (working copy) |
@@ -3,22 +3,59 @@ |
// found in the LICENSE file. |
#include "content/renderer/gpu/gpu_benchmarking_extension.h" |
+ |
+#include "base/string_number_conversions.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 { |
+class SkPictureRecorder : public WebViewBenchmarkSupport::PaintClient { |
+ public: |
+ explicit SkPictureRecorder(const std::string& dirname) |
+ : dirname_(dirname), |
+ layer_id_(0) { |
+ } |
+ |
+ virtual WebCanvas* willPaint(const WebSize& size) { |
+ return picture_.beginRecording(size.width, size.height); |
+ } |
+ |
+ virtual void didPaint(WebCanvas* canvas) { |
+ 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. |
+ std::string filepath = |
+ dirname_ + "/layer_" + base::IntToString(layer_id_++) + ".skp"; |
+ SkFILEWStream file(filepath.c_str()); |
+ picture_.serialize(&file); |
+ } |
+ |
+ private: |
+ std::string dirname_; |
+ int layer_id_; |
+ SkPicture picture_; |
+}; |
+ |
+} // namespace |
+ |
namespace content { |
class GpuBenchmarkingWrapper : public v8::Extension { |
@@ -35,6 +72,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 +92,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); |
@@ -93,6 +136,32 @@ |
return stats_object; |
} |
+ static v8::Handle<v8::Value> PrintToSkPicture(const v8::Arguments& args) { |
nduca
2012/07/30 17:24:21
We should check if we have been launched with --no
alokp
2012/07/30 20:24:37
DONE (in a slightly different way). I am throwing
|
+ 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) |