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

Unified Diff: cc/resources/picture.cc

Issue 13884018: cc: Add base64 encoding to picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added check for picture validity Created 7 years, 8 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 | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture.cc
diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc
index 2b6eca8777fbc0c3d7d280170d3f7008ce85d990..845a6612a2999f643f10b66c5160614ff352f7ef 100644
--- a/cc/resources/picture.cc
+++ b/cc/resources/picture.cc
@@ -2,15 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "cc/resources/picture.h"
+
+#include "base/base64.h"
#include "base/debug/trace_event.h"
#include "cc/debug/rendering_stats.h"
#include "cc/layers/content_layer_client.h"
-#include "cc/resources/picture.h"
#include "skia/ext/analysis_canvas.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkDrawFilter.h"
#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/utils/SkPictureUtils.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/skia_util.h"
@@ -38,10 +41,48 @@ 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) {
+ bool success;
+ scoped_refptr<Picture> picture =
+ make_scoped_refptr(new Picture(encoded_string, &success));
+ if (!success)
+ picture = NULL;
+ return picture;
+}
+
Picture::Picture(gfx::Rect layer_rect)
: layer_rect_(layer_rect) {
}
+Picture::Picture(const std::string& encoded_string, bool* success) {
+ // Decode the picture from base64.
+ std::string decoded;
nduca 2013/04/18 21:33:04 put a cc picture number in this so that if we eve
+ base::Base64Decode(encoded_string, &decoded);
+ SkMemoryStream stream(decoded.data(), decoded.size());
+
+ // 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);
+
+ // Read the picture. This creates an empty picture on failure.
+ picture_ = skia::AdoptRef(new SkPicture(&stream, success, NULL));
+}
+
Picture::Picture(const skia::RefPtr<SkPicture>& picture,
gfx::Rect layer_rect,
gfx::Rect opaque_rect) :
@@ -178,4 +219,28 @@ void Picture::GatherPixelRefs(const gfx::Rect& layer_rect,
pixel_refs->unref();
}
+void Picture::AsBase64String(std::string* output) const {
+ SkDynamicMemoryWStream stream;
+
+ // First save layer_rect_ and opaque_rect.
+ 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);
+
+ // Encode the picture as base64.
+ size_t serialized_size = stream.bytesWritten();
+ scoped_ptr<char[]> serialized_picture(new char[serialized_size]);
+ stream.copyTo(serialized_picture.get());
+ base::Base64Encode(std::string(serialized_picture.get(), serialized_size),
+ output);
+}
+
} // namespace cc
« no previous file with comments | « cc/resources/picture.h ('k') | cc/resources/picture_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698