summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEPS2
-rw-r--r--cc/base/math_util.cc21
-rw-r--r--cc/base/math_util.h1
-rw-r--r--cc/debug/traced_picture.cc16
-rw-r--r--cc/resources/picture.cc86
-rw-r--r--cc/resources/picture.h11
-rw-r--r--cc/resources/picture_unittest.cc37
-rw-r--r--content/renderer/skia_benchmarking_extension.cc26
8 files changed, 107 insertions, 93 deletions
diff --git a/DEPS b/DEPS
index 1940a14..2613c3c 100644
--- a/DEPS
+++ b/DEPS
@@ -76,7 +76,7 @@ deps = {
(Var("googlecode_url") % "angleproject") + "/trunk@2245",
"src/third_party/trace-viewer":
- (Var("googlecode_url") % "trace-viewer") + "/trunk@493",
+ (Var("googlecode_url") % "trace-viewer") + "/trunk@514",
"src/third_party/WebKit":
Var("webkit_trunk") + "@" + Var("webkit_revision"),
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc
index 4123cf8..c3c7b1c 100644
--- a/cc/base/math_util.cc
+++ b/cc/base/math_util.cc
@@ -535,6 +535,27 @@ scoped_ptr<base::Value> MathUtil::AsValue(gfx::Rect r) {
return res.PassAs<base::Value>();
}
+bool MathUtil::FromValue(const base::Value* raw_value, gfx::Rect* out_rect) {
+ const ListValue* value = NULL;
+ if (!raw_value->GetAsList(&value))
+ return false;
+
+ if (value->GetSize() != 4)
+ return false;
+
+ int x, y, w, h;
+ bool ok = true;
+ ok &= value->GetInteger(0, &x);
+ ok &= value->GetInteger(1, &y);
+ ok &= value->GetInteger(2, &w);
+ ok &= value->GetInteger(3, &h);
+ if (!ok)
+ return false;
+
+ *out_rect = gfx::Rect(x, y, w, h);
+ return true;
+}
+
scoped_ptr<base::Value> MathUtil::AsValue(gfx::PointF pt) {
scoped_ptr<base::ListValue> res(new base::ListValue());
res->AppendDouble(pt.x());
diff --git a/cc/base/math_util.h b/cc/base/math_util.h
index 4f9c644..69dd8d8 100644
--- a/cc/base/math_util.h
+++ b/cc/base/math_util.h
@@ -146,6 +146,7 @@ class CC_EXPORT MathUtil {
// Conversion to value.
static scoped_ptr<base::Value> AsValue(gfx::Size s);
static scoped_ptr<base::Value> AsValue(gfx::Rect r);
+ static bool FromValue(const base::Value*, gfx::Rect* out_rect);
static scoped_ptr<base::Value> AsValue(gfx::PointF q);
static scoped_ptr<base::Value> AsValue(const gfx::QuadF& q);
static scoped_ptr<base::Value> AsValue(const gfx::RectF& rect);
diff --git a/cc/debug/traced_picture.cc b/cc/debug/traced_picture.cc
index 33ae7e1..698c2db 100644
--- a/cc/debug/traced_picture.cc
+++ b/cc/debug/traced_picture.cc
@@ -26,18 +26,10 @@ scoped_ptr<base::debug::ConvertableToTraceFormat>
}
void TracedPicture::AppendAsTraceFormat(std::string* out) const {
- std::string encoded_picture;
- picture_->AsBase64String(&encoded_picture);
- out->append("{");
- out->append("\"layer_rect\": [");
- base::StringAppendF(
- out, "%i,%i,%i,%i",
- picture_->LayerRect().x(), picture_->LayerRect().y(),
- picture_->LayerRect().width(), picture_->LayerRect().height());
- out->append("],");
- out->append("\"data_b64\": \"");
- out->append(encoded_picture);
- out->append("\"}");
+ scoped_ptr<base::Value> value = picture_->AsValue();
+ std::string tmp;
+ base::JSONWriter::Write(value.get(), &tmp);
+ out->append(tmp);
}
} // namespace cc
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 0c21e71..b0f3fa3 100644
--- a/cc/resources/picture.cc
+++ b/cc/resources/picture.cc
@@ -11,6 +11,7 @@
#include "base/base64.h"
#include "base/debug/trace_event.h"
#include "base/values.h"
+#include "cc/base/math_util.h"
#include "cc/base/util.h"
#include "cc/debug/rendering_stats.h"
#include "cc/debug/traced_picture.h"
@@ -32,13 +33,6 @@ namespace cc {
namespace {
-// Version ID; to be used in serialization.
-const int kPictureVersion = 1;
-
-// Minimum size of a decoded stream that we need.
-// 4 bytes for version, 4 * 4 for each of the 2 rects.
-const unsigned int kMinPictureSizeBytes = 36;
-
SkData* EncodeBitmap(size_t* offset, const SkBitmap& bm) {
const int kJpegQuality = 80;
std::vector<unsigned char> data;
@@ -135,11 +129,10 @@ scoped_refptr<Picture> Picture::Create(gfx::Rect layer_rect) {
return make_scoped_refptr(new Picture(layer_rect));
}
-scoped_refptr<Picture> Picture::CreateFromBase64String(
- const std::string& encoded_string) {
+scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* value) {
bool success;
scoped_refptr<Picture> picture =
- make_scoped_refptr(new Picture(encoded_string, &success));
+ make_scoped_refptr(new Picture(value, &success));
if (!success)
picture = NULL;
return picture;
@@ -151,40 +144,43 @@ Picture::Picture(gfx::Rect layer_rect)
// the picture to be recorded in Picture::Record.
}
-Picture::Picture(const std::string& encoded_string, bool* success) {
+Picture::Picture(const base::Value* raw_value, bool* success) {
+ const base::DictionaryValue* value = NULL;
+ if (!raw_value->GetAsDictionary(&value)) {
+ *success = false;
+ return;
+ }
+
// Decode the picture from base64.
+ std::string encoded;
+ if (!value->GetString("skp64", &encoded)) {
+ *success = false;
+ return;
+ }
+
std::string decoded;
- base::Base64Decode(encoded_string, &decoded);
+ base::Base64Decode(encoded, &decoded);
SkMemoryStream stream(decoded.data(), decoded.size());
- if (decoded.size() < kMinPictureSizeBytes) {
+ const base::Value* layer_rect = NULL;
+ if (!value->Get("params.layer_rect", &layer_rect)) {
*success = false;
return;
}
-
- int version = stream.readS32();
- if (version != kPictureVersion) {
+ if (!MathUtil::FromValue(layer_rect, &layer_rect_)) {
*success = false;
return;
}
- // First, read the layer and opaque rects.
- int layer_rect_x = stream.readS32();
- int layer_rect_y = stream.readS32();
- int layer_rect_width = stream.readS32();
- int layer_rect_height = stream.readS32();
- layer_rect_ = gfx::Rect(layer_rect_x,
- layer_rect_y,
- layer_rect_width,
- layer_rect_height);
- int opaque_rect_x = stream.readS32();
- int opaque_rect_y = stream.readS32();
- int opaque_rect_width = stream.readS32();
- int opaque_rect_height = stream.readS32();
- opaque_rect_ = gfx::Rect(opaque_rect_x,
- opaque_rect_y,
- opaque_rect_width,
- opaque_rect_height);
+ const base::Value* opaque_rect = NULL;
+ if (!value->Get("params.opaque_rect", &opaque_rect)) {
+ *success = false;
+ return;
+ }
+ if (!MathUtil::FromValue(opaque_rect, &opaque_rect_)) {
+ *success = false;
+ return;
+ }
// Read the picture. This creates an empty picture on failure.
picture_ = skia::AdoptRef(new SkPicture(&stream, success, &DecodeBitmap));
@@ -371,31 +367,25 @@ void Picture::Raster(
"num_pixels_rasterized", bounds.width() * bounds.height());
}
-void Picture::AsBase64String(std::string* output) const {
+scoped_ptr<Value> Picture::AsValue() const {
SkDynamicMemoryWStream stream;
- // First save the version, layer_rect_ and opaque_rect.
- stream.write32(kPictureVersion);
-
- stream.write32(layer_rect_.x());
- stream.write32(layer_rect_.y());
- stream.write32(layer_rect_.width());
- stream.write32(layer_rect_.height());
-
- stream.write32(opaque_rect_.x());
- stream.write32(opaque_rect_.y());
- stream.write32(opaque_rect_.width());
- stream.write32(opaque_rect_.height());
-
// Serialize the picture.
picture_->serialize(&stream, &EncodeBitmap);
// Encode the picture as base64.
+ scoped_ptr<base::DictionaryValue> res(new base::DictionaryValue());
+ res->Set("params.layer_rect", MathUtil::AsValue(layer_rect_).release());
+ res->Set("params.opaque_rect", MathUtil::AsValue(opaque_rect_).release());
+
size_t serialized_size = stream.bytesWritten();
scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
stream.copyTo(serialized_picture.get());
+ std::string b64_picture;
base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
- output);
+ &b64_picture);
+ res->SetString("skp64", b64_picture);
+ return res.PassAs<base::Value>();
}
base::LazyInstance<Picture::PixelRefs>
diff --git a/cc/resources/picture.h b/cc/resources/picture.h
index 1a24ade..5e4e5ca 100644
--- a/cc/resources/picture.h
+++ b/cc/resources/picture.h
@@ -24,6 +24,10 @@
#include "third_party/skia/include/core/SkTileGridPicture.h"
#include "ui/gfx/rect.h"
+namespace base {
+class Value;
+}
+
namespace skia {
class AnalysisCanvas;
}
@@ -41,8 +45,7 @@ class CC_EXPORT Picture
typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefMap;
static scoped_refptr<Picture> Create(gfx::Rect layer_rect);
- static scoped_refptr<Picture> CreateFromBase64String(
- const std::string& encoded_string);
+ static scoped_refptr<Picture> CreateFromValue(const base::Value* value);
gfx::Rect LayerRect() const { return layer_rect_; }
gfx::Rect OpaqueRect() const { return opaque_rect_; }
@@ -74,7 +77,7 @@ class CC_EXPORT Picture
float contents_scale,
bool enable_lcd_text);
- void AsBase64String(std::string* output) const;
+ scoped_ptr<base::Value> AsValue() const;
class CC_EXPORT PixelRefIterator {
public:
@@ -111,7 +114,7 @@ class CC_EXPORT Picture
private:
explicit Picture(gfx::Rect layer_rect);
- Picture(const std::string& encoded_string, bool* success);
+ Picture(const base::Value*, bool* success);
// This constructor assumes SkPicture is already ref'd and transfers
// ownership to this picture.
Picture(const skia::RefPtr<SkPicture>&,
diff --git a/cc/resources/picture_unittest.cc b/cc/resources/picture_unittest.cc
index 7d92582..e63da16 100644
--- a/cc/resources/picture_unittest.cc
+++ b/cc/resources/picture_unittest.cc
@@ -6,6 +6,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/skia_common.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,42 +33,29 @@ TEST(PictureTest, AsBase64String) {
FakeContentLayerClient content_layer_client;
+ 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 base64).
+ // Invalid picture (not a dict).
+ tmp.reset(new base::StringValue("abc!@#$%"));
scoped_refptr<Picture> invalid_picture =
- Picture::CreateFromBase64String("abc!@#$%");
+ Picture::CreateFromValue(tmp.get());
EXPECT_TRUE(!invalid_picture);
- // Invalid picture (empty string).
- scoped_refptr<Picture> second_invalid_picture =
- Picture::CreateFromBase64String("");
- EXPECT_TRUE(!second_invalid_picture);
-
- // Invalid picture (random base64 string).
- scoped_refptr<Picture> third_invalid_picture =
- Picture::CreateFromBase64String("ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD"
- "ABCDABCDABCDABCDABCDABCDABCDABCDABCD");
- EXPECT_TRUE(!third_invalid_picture);
-
// 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, NULL);
- std::string serialized_one_rect;
- one_rect_picture->AsBase64String(&serialized_one_rect);
+ scoped_ptr<base::Value> serialized_one_rect(
+ one_rect_picture->AsValue());
// Reconstruct the picture.
scoped_refptr<Picture> one_rect_picture_check =
- Picture::CreateFromBase64String(serialized_one_rect);
+ Picture::CreateFromValue(serialized_one_rect.get());
EXPECT_TRUE(!!one_rect_picture_check);
// Check for equivalence.
@@ -87,12 +75,13 @@ TEST(PictureTest, AsBase64String) {
content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint);
scoped_refptr<Picture> two_rect_picture = Picture::Create(layer_rect);
two_rect_picture->Record(&content_layer_client, tile_grid_info, NULL);
- std::string serialized_two_rect;
- two_rect_picture->AsBase64String(&serialized_two_rect);
+
+ scoped_ptr<base::Value> serialized_two_rect(
+ two_rect_picture->AsValue());
// Reconstruct the picture.
scoped_refptr<Picture> two_rect_picture_check =
- Picture::CreateFromBase64String(serialized_two_rect);
+ Picture::CreateFromValue(serialized_two_rect.get());
EXPECT_TRUE(!!two_rect_picture_check);
// Check for equivalence.
diff --git a/content/renderer/skia_benchmarking_extension.cc b/content/renderer/skia_benchmarking_extension.cc
index d45566e..c22f4a8 100644
--- a/content/renderer/skia_benchmarking_extension.cc
+++ b/content/renderer/skia_benchmarking_extension.cc
@@ -4,14 +4,19 @@
#include "content/renderer/skia_benchmarking_extension.h"
+#include "base/values.h"
#include "cc/resources/picture.h"
+#include "content/public/renderer/v8_value_converter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBuffer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#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 "ui/gfx/rect_conversions.h"
#include "v8/include/v8.h"
+using WebKit::WebFrame;
+
namespace {
const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking";
@@ -28,8 +33,8 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
"};"
"chrome.skiaBenchmarking.rasterize = function(picture, scale, rect) {"
" /* "
- " Rasterizes a base64-encoded Picture."
- " @param {String} picture Base64-encoded Picture."
+ " Rasterizes a Picture JSON-encoded by cc::Picture::AsValue()."
+ " @param {Object} picture A json-encoded cc::Picture."
" @param {Number} scale (optional) Rendering scale."
" @param [Number, Number, Number, Number] clip_rect (optional)."
" @returns { 'width': {Number}, 'height': {Number},"
@@ -54,9 +59,22 @@ class SkiaBenchmarkingWrapper : public v8::Extension {
if (args.Length() < 1)
return v8::Undefined();
- v8::String::AsciiValue base64_picture(args[0]);
+ 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::CreateFromBase64String(*base64_picture);
+ cc::Picture::CreateFromValue(picture_value.get());
if (!picture)
return v8::Undefined();