Commit 6cb732e8 authored by alokp@chromium.org's avatar alokp@chromium.org

Expose a gpu-benchmark-only printToSkPicture API to JS. This function records...

Expose a gpu-benchmark-only printToSkPicture API to JS. This function records the page to an SkPicture, and dumps the resulting picture to a local file.
BUG=130422

Review URL: https://chromiumcodereview.appspot.com/10787025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149287 0039d316-1c4b-4281-b951-d872f2087c98
parent 70f3bb33
......@@ -6,28 +6,68 @@
#include <string>
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/memory/scoped_vector.h"
#include "base/string_number_conversions.h"
#include "content/public/renderer/render_thread.h"
#include "content/renderer/all_rendering_benchmarks.h"
#include "content/renderer/render_view_impl.h"
#include "content/renderer/rendering_benchmark.h"
#include "content/renderer/rendering_benchmark_results.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/Platform/chromium/public/WebRenderingStats.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h"
#include "v8/include/v8.h"
using WebKit::WebCanvas;
using WebKit::WebFrame;
using WebKit::WebPrivatePtr;
using WebKit::WebViewBenchmarkSupport;
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 FilePath& dirpath)
: dirpath_(dirpath),
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.
// TODO(alokp): Note that for this to work Chrome needs to be launched with
// --no-sandbox command-line flag. Get rid of this limitation.
// CRBUG: 139640.
std::string filename = "layer_" + base::IntToString(layer_id_++) + ".skp";
std::string filepath = dirpath_.AppendASCII(filename).MaybeAsASCII();
DCHECK(!filepath.empty());
SkFILEWStream file(filepath.c_str());
DCHECK(file.isValid());
picture_.serialize(&file);
}
private:
FilePath dirpath_;
int layer_id_;
SkPicture picture_;
};
} // namespace
namespace content {
......@@ -76,6 +116,10 @@ class GpuBenchmarkingWrapper : public v8::Extension {
" 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;"
......@@ -96,6 +140,8 @@ class GpuBenchmarkingWrapper : public v8::Extension {
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);
if (name->Equals(v8::String::New("RunRenderingBenchmarks")))
......@@ -140,6 +186,42 @@ class GpuBenchmarkingWrapper : public v8::Extension {
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();
FilePath dirpath;
dirpath = dirpath.AppendASCII(*dirname);
if (!file_util::CreateDirectory(dirpath) ||
!file_util::PathIsWritable(dirpath)) {
std::string msg("Path is not writable: ");
msg.append(dirpath.MaybeAsASCII());
return v8::ThrowException(v8::Exception::Error(
v8::String::New(msg.c_str(), msg.length())));
}
SkPictureRecorder recorder(dirpath);
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment