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

Unified Diff: content/renderer/skia_benchmarking_extension.cc

Issue 15967010: Add skiaBenchmarking.getOps() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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 | skia/skia.gyp » ('j') | skia/skia.gyp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/skia_benchmarking_extension.cc
diff --git a/content/renderer/skia_benchmarking_extension.cc b/content/renderer/skia_benchmarking_extension.cc
index 7d9b74f519f3c3684f1fc007adb2344151921568..bcd445962038107aa3aac516757406720e0742e1 100644
--- a/content/renderer/skia_benchmarking_extension.cc
+++ b/content/renderer/skia_benchmarking_extension.cc
@@ -12,6 +12,8 @@
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColorPriv.h"
#include "third_party/skia/include/core/SkGraphics.h"
+#include "third_party/skia/src/utils/debugger/SkDebugCanvas.h"
+#include "third_party/skia/src/utils/debugger/SkDrawCommand.h"
#include "ui/gfx/rect_conversions.h"
#include "v8/include/v8.h"
@@ -21,6 +23,19 @@ namespace {
const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking";
+static scoped_refptr<cc::Picture> ParsePictureArg(v8::Handle<v8::Value> arg) {
+ scoped_ptr<content::V8ValueConverter> converter(
+ content::V8ValueConverter::create());
+
+ v8::String::Value v8_picture(arg);
+ scoped_ptr<base::Value> picture_value(
+ converter->FromV8Value(arg, v8::Context::GetCurrent()));
+ if (!picture_value)
+ return NULL;
+
+ return cc::Picture::CreateFromValue(picture_value.get());
+}
+
class SkiaBenchmarkingWrapper : public v8::Extension {
public:
SkiaBenchmarkingWrapper() :
@@ -43,6 +58,15 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
" native function Rasterize();"
" return Rasterize(picture, scale, rect);"
"};"
+ "chrome.skiaBenchmarking.getOps = function(picture) {"
+ " /* "
+ " Extracts the Skia draw commands from a JSON-encoded cc::Picture"
+ " @param {Object} picture A json-encoded cc::Picture."
+ " @returns [{ 'cmd': {String}, 'info': [String, ...] }, ...]"
nduca 2013/06/11 23:52:13 define in the docs that undefined is returned when
f(malita) 2013/06/12 13:32:37 Ok.
+ " */"
+ " native function GetOps();"
+ " return GetOps(picture);"
+ "};"
) {
content::SkiaBenchmarkingExtension::InitSkGraphics();
}
@@ -51,6 +75,8 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
v8::Handle<v8::String> name) OVERRIDE {
if (name->Equals(v8::String::New("Rasterize")))
return v8::FunctionTemplate::New(Rasterize);
+ if (name->Equals(v8::String::New("GetOps")))
+ return v8::FunctionTemplate::New(GetOps);
return v8::Handle<v8::FunctionTemplate>();
}
@@ -59,22 +85,7 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
if (args.Length() < 1)
return v8::Undefined();
- WebFrame* web_frame = WebFrame::frameForCurrentContext();
- if (!web_frame)
- return v8::Undefined();
-
- scoped_ptr<content::V8ValueConverter> converter(
- content::V8ValueConverter::create());
-
- v8::String::Value v8_picture(args[0]);
- scoped_ptr<base::Value> picture_value(
- converter->FromV8Value(
- args[0], v8::Context::GetCurrent()));
- if (!picture_value)
- return v8::Undefined();
-
- scoped_refptr<cc::Picture> picture =
- cc::Picture::CreateFromValue(picture_value.get());
+ scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
if (!picture.get())
return v8::Undefined();
@@ -140,6 +151,41 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
return result;
}
+
+ static v8::Handle<v8::Value> GetOps(const v8::Arguments& args) {
+ if (args.Length() != 1)
+ return v8::Undefined();
+
+ scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
+ if (!picture.get())
+ return v8::Undefined();
+
+ gfx::Rect bounds = picture->LayerRect();
+ SkDebugCanvas canvas(bounds.width(), bounds.height());
+ canvas.setBounds(bounds.width(), bounds.height());
+ picture->Raster(&canvas, NULL, bounds, 1.0f);
+
+ v8::Local<v8::Array> result = v8::Array::New(canvas.getSize());
+ for (int i = 0; i < canvas.getSize(); ++i) {
+ v8::Handle<v8::Object> cmd = v8::Object::New();
+ cmd->Set(v8::String::New("cmd"), v8::String::New(
+ SkDrawCommand::GetCommandString(
+ canvas.getDrawCommandAt(i)->getType())));
+
+ SkTDArray<SkString*>* info = canvas.getCommandInfo(i);
nduca 2013/06/11 23:52:13 what is in the info? what is mandatory and what is
f(malita) 2013/06/12 13:32:37 This is based on the current Skia debugger backend
+ if (info) {
nduca 2013/06/11 23:52:13 why would info not be returned? It seems odd that
f(malita) 2013/06/12 13:32:37 Was following Skia use here, but you're right - it
+ v8::Local<v8::Array> v8_info = v8::Array::New(info->count());
+ for (int j = 0; j < info->count(); ++j)
+ v8_info->Set(j, v8::String::New(info->getAt(j)->c_str()));
+
+ cmd->Set(v8::String::New("info"), v8_info);
+ }
+
+ result->Set(i, cmd);
+ }
+
+ return result;
+ }
};
} // namespace
« no previous file with comments | « no previous file | skia/skia.gyp » ('j') | skia/skia.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698