Chromium Code Reviews| Index: cc/resources/picture.cc |
| diff --git a/cc/resources/picture.cc b/cc/resources/picture.cc |
| index 2b6eca8777fbc0c3d7d280170d3f7008ce85d990..d7ec0d9ecdd8da7294de294a30810db87642aa9d 100644 |
| --- a/cc/resources/picture.cc |
| +++ b/cc/resources/picture.cc |
| @@ -2,6 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/base64.h" |
| #include "base/debug/trace_event.h" |
| #include "cc/debug/rendering_stats.h" |
| #include "cc/layers/content_layer_client.h" |
| @@ -11,6 +12,7 @@ |
| #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" |
| @@ -150,6 +152,23 @@ void Picture::Raster( |
| canvas->restore(); |
| } |
| +void Picture::AsBase64String(std::string* output) const { |
|
tfarina
2013/04/13 00:49:01
the order of implementation should match with the
|
| + SkDynamicMemoryWStream stream; |
| + picture_->serialize(&stream); |
| + 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); |
| +} |
| + |
| +void Picture::SetPictureFromBase64String(const std::string & encoded) { |
| + std::string decoded; |
| + base::Base64Decode(encoded, &decoded); |
| + SkMemoryStream stream(decoded.data(), decoded.size()); |
| + picture_ = skia::AdoptRef(new SkPicture(&stream)); |
| +} |
| + |
| void Picture::GatherPixelRefs(const gfx::Rect& layer_rect, |
| std::list<skia::LazyPixelRef*>& pixel_ref_list) { |
| DCHECK(picture_); |