summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 23:36:31 +0000
committerdsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-01 23:36:31 +0000
commitc883e8bd8ca75d36f2574f5772f3f09fc733711e (patch)
tree5dfd90f899a409b5128f319a9b51e8d5187a1beb
parent82d55f49ccb3d9b61834c2ad2640307b2824060b (diff)
downloadchromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.zip
chromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.tar.gz
chromium_src-c883e8bd8ca75d36f2574f5772f3f09fc733711e.tar.bz2
Add ability to retrieve the width and height from a SKP file.
In trace-viewer we want to allow users to load up .skp files in the skia_debugger.html. In order to do that we need access to the width and height of the skp in order to get the op timings. To that end, this CL adds a getInfo method to chrome.skiaBenchmarking to return the width and height. BUG= Review URL: https://chromiumcodereview.appspot.com/23572018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220765 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--cc/resources/picture.cc21
-rw-r--r--cc/resources/picture.h1
-rw-r--r--cc/resources/picture_unittest.cc53
-rw-r--r--content/renderer/skia_benchmarking_extension.cc53
4 files changed, 121 insertions, 7 deletions
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 8c5d851..4927623 100644
--- a/cc/resources/picture.cc
+++ b/cc/resources/picture.cc
@@ -93,6 +93,27 @@ Picture::Picture(gfx::Rect layer_rect)
// the picture to be recorded in Picture::Record.
}
+scoped_refptr<Picture> Picture::CreateFromSkpValue(const base::Value* value) {
+ // Decode the picture from base64.
+ std::string encoded;
+ if (!value->GetAsString(&encoded))
+ return NULL;
+
+ std::string decoded;
+ base::Base64Decode(encoded, &decoded);
+ SkMemoryStream stream(decoded.data(), decoded.size());
+
+ // Read the picture. This creates an empty picture on failure.
+ SkPicture* skpicture = SkPicture::CreateFromStream(&stream, &DecodeBitmap);
+ if (skpicture == NULL)
+ return NULL;
+
+ gfx::Rect layer_rect(skpicture->width(), skpicture->height());
+ gfx::Rect opaque_rect(skpicture->width(), skpicture->height());
+
+ return make_scoped_refptr(new Picture(skpicture, layer_rect, opaque_rect));
+}
+
scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) {
const base::DictionaryValue* value = NULL;
if (!raw_value->GetAsDictionary(&value))
diff --git a/cc/resources/picture.h b/cc/resources/picture.h
index 15a6c9d..90df190 100644
--- a/cc/resources/picture.h
+++ b/cc/resources/picture.h
@@ -45,6 +45,7 @@ class CC_EXPORT Picture
static scoped_refptr<Picture> Create(gfx::Rect layer_rect);
static scoped_refptr<Picture> CreateFromValue(const base::Value* value);
+ static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value);
gfx::Rect LayerRect() const { return layer_rect_; }
gfx::Rect OpaqueRect() const { return opaque_rect_; }
diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc
index ee5e07d..aa20ebb 100644
--- a/cc/resources/picture_unittest.cc
+++ b/cc/resources/picture_unittest.cc
@@ -377,5 +377,58 @@ TEST(PictureTest, PixelRefIteratorOnePixelQuery) {
}
}
}
+
+TEST(PictureTest, CreateFromSkpValue) {
+ SkGraphics::Init();
+
+ gfx::Rect layer_rect(100, 200);
+
+ SkTileGridPicture::TileGridInfo tile_grid_info;
+ tile_grid_info.fTileInterval = SkISize::Make(100, 200);
+ tile_grid_info.fMargin.setEmpty();
+ tile_grid_info.fOffset.setZero();
+
+ FakeContentLayerClient content_layer_client;
+ FakeRenderingStatsInstrumentation stats_instrumentation;
+
+ scoped_ptr<base::Value> tmp;
+
+ SkPaint red_paint;
+ red_paint.setColor(SkColorSetARGB(255, 255, 0, 0));
+ SkPaint green_paint;
+ green_paint.setColor(SkColorSetARGB(255, 0, 255, 0));
+
+ // Invalid picture (not a dict).
+ tmp.reset(new base::StringValue("abc!@#$%"));
+ scoped_refptr<Picture> invalid_picture =
+ Picture::CreateFromSkpValue(tmp.get());
+ EXPECT_TRUE(!invalid_picture.get());
+
+ // Single full-size rect picture.
+ content_layer_client.add_draw_rect(layer_rect, red_paint);
+ scoped_refptr<Picture> one_rect_picture = Picture::Create(layer_rect);
+ one_rect_picture->Record(&content_layer_client,
+ tile_grid_info,
+ &stats_instrumentation);
+ scoped_ptr<base::Value> serialized_one_rect(
+ one_rect_picture->AsValue());
+
+ const base::DictionaryValue* value = NULL;
+ EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value));
+
+ // Decode the picture from base64.
+ const base::Value* skp_value;
+ EXPECT_TRUE(value->Get("skp64", &skp_value));
+
+ // Reconstruct the picture.
+ scoped_refptr<Picture> one_rect_picture_check =
+ Picture::CreateFromSkpValue(skp_value);
+ EXPECT_TRUE(!!one_rect_picture_check.get());
+
+ EXPECT_EQ(100, one_rect_picture_check->LayerRect().width());
+ EXPECT_EQ(200, one_rect_picture_check->LayerRect().height());
+ EXPECT_EQ(100, one_rect_picture_check->OpaqueRect().width());
+ EXPECT_EQ(200, one_rect_picture_check->OpaqueRect().height());
+}
} // namespace
} // namespace cc
diff --git a/content/renderer/skia_benchmarking_extension.cc b/content/renderer/skia_benchmarking_extension.cc
index 95e2698..3890e98 100644
--- a/content/renderer/skia_benchmarking_extension.cc
+++ b/content/renderer/skia_benchmarking_extension.cc
@@ -4,6 +4,7 @@
#include "content/renderer/skia_benchmarking_extension.h"
+#include "base/base64.h"
#include "base/time/time.h"
#include "base/values.h"
#include "cc/base/math_util.h"
@@ -16,6 +17,7 @@
#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/include/core/SkStream.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"
@@ -28,16 +30,24 @@ namespace {
const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking";
-static scoped_refptr<cc::Picture> ParsePictureArg(v8::Handle<v8::Value> arg) {
+static scoped_ptr<base::Value> 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(
+ return scoped_ptr<base::Value>(
converter->FromV8Value(arg, v8::Context::GetCurrent()));
+}
+
+static scoped_refptr<cc::Picture> ParsePictureStr(v8::Handle<v8::Value> arg) {
+ scoped_ptr<base::Value> picture_value = ParsePictureArg(arg);
if (!picture_value)
return NULL;
+ return cc::Picture::CreateFromSkpValue(picture_value.get());
+}
+static scoped_refptr<cc::Picture> ParsePictureHash(v8::Handle<v8::Value> arg) {
+ scoped_ptr<base::Value> picture_value = ParsePictureArg(arg);
+ if (!picture_value)
+ return NULL;
return cc::Picture::CreateFromValue(picture_value.get());
}
@@ -94,6 +104,16 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
" native function GetOpTimings();"
" return GetOpTimings(picture);"
"};"
+ "chrome.skiaBenchmarking.getInfo = function(picture) {"
+ " /* "
+ " Returns meta information for the given picture."
+ " @param {Object} picture A base64 encoded SKP."
+ " @returns { 'width': {Number}, 'height': {Number} }"
+ " @returns undefined if the picture version is not supported."
+ " */"
+ " native function GetInfo();"
+ " return GetInfo(picture);"
+ "};"
) {
content::SkiaBenchmarkingExtension::InitSkGraphics();
}
@@ -106,6 +126,8 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
return v8::FunctionTemplate::New(GetOps);
if (name->Equals(v8::String::New("GetOpTimings")))
return v8::FunctionTemplate::New(GetOpTimings);
+ if (name->Equals(v8::String::New("GetInfo")))
+ return v8::FunctionTemplate::New(GetInfo);
return v8::Handle<v8::FunctionTemplate>();
}
@@ -114,7 +136,7 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
if (args.Length() < 1)
return;
- scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
+ scoped_refptr<cc::Picture> picture = ParsePictureHash(args[0]);
if (!picture.get())
return;
@@ -205,7 +227,7 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
if (args.Length() != 1)
return;
- scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
+ scoped_refptr<cc::Picture> picture = ParsePictureHash(args[0]);
if (!picture.get())
return;
@@ -243,7 +265,7 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
if (args.Length() != 1)
return;
- scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
+ scoped_refptr<cc::Picture> picture = ParsePictureHash(args[0]);
if (!picture.get())
return;
@@ -276,6 +298,23 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
args.GetReturnValue().Set(result);
}
+
+ static void GetInfo(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ if (args.Length() != 1)
+ return;
+
+ scoped_refptr<cc::Picture> picture = ParsePictureStr(args[0]);
+ if (!picture.get())
+ return;
+
+ v8::Handle<v8::Object> result = v8::Object::New();
+ result->Set(v8::String::New("width"),
+ v8::Number::New(picture->LayerRect().width()));
+ result->Set(v8::String::New("height"),
+ v8::Number::New(picture->LayerRect().height()));
+
+ args.GetReturnValue().Set(result);
+ }
};
} // namespace