Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: content/renderer/gpu/gpu_benchmarking_extension.cc

Issue 10787025: Expose a gpu-benchmark-only measureRecordTime API to JS. This function measures the time it takes t… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/gpu/gpu_benchmarking_extension.cc
===================================================================
--- content/renderer/gpu/gpu_benchmarking_extension.cc (revision 149202)
+++ content/renderer/gpu/gpu_benchmarking_extension.cc (working copy)
@@ -6,29 +6,69 @@
#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/WebView.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewBenchmarkSupport.h"
-#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.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 {
// Benchmark results object that populates a v8 array.
@@ -76,6 +116,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;"
@@ -96,6 +140,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);
if (name->Equals(v8::String::New("RunRenderingBenchmarks")))
@@ -140,6 +186,42 @@
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)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698