| Index: cc/playback/drawing_display_item.cc
|
| diff --git a/cc/playback/drawing_display_item.cc b/cc/playback/drawing_display_item.cc
|
| index a1f54b42d011859b6ba0112d26f9bcff9512e51a..5df5b12faf1e43cfee3a38460a18890068fd1c88 100644
|
| --- a/cc/playback/drawing_display_item.cc
|
| +++ b/cc/playback/drawing_display_item.cc
|
| @@ -9,9 +9,12 @@
|
| #include "base/strings/stringprintf.h"
|
| #include "base/trace_event/trace_event_argument.h"
|
| #include "cc/debug/picture_debug_util.h"
|
| +#include "cc/proto/display_item.pb.h"
|
| #include "third_party/skia/include/core/SkCanvas.h"
|
| +#include "third_party/skia/include/core/SkData.h"
|
| #include "third_party/skia/include/core/SkMatrix.h"
|
| #include "third_party/skia/include/core/SkPicture.h"
|
| +#include "third_party/skia/include/core/SkStream.h"
|
| #include "third_party/skia/include/utils/SkPictureUtils.h"
|
| #include "ui/gfx/skia_util.h"
|
|
|
| @@ -30,6 +33,40 @@ void DrawingDisplayItem::SetNew(skia::RefPtr<SkPicture> picture) {
|
| SkPictureUtils::ApproximateBytesUsed(picture_.get()));
|
| }
|
|
|
| +void DrawingDisplayItem::ToProtobuf(proto::DisplayItem* proto) {
|
| + proto->set_type(proto::DisplayItem::Type_Drawing);
|
| +
|
| + proto::DrawingDisplayItem* details = proto->mutable_details_drawing();
|
| +
|
| + // Just use skia's serialize() method for now.
|
| + if (picture_) {
|
| + SkDynamicMemoryWStream stream;
|
| +
|
| + // TODO(dtrainor, nyquist): Add an SkPixelSerializer to not serialize images
|
| + // more than once.
|
| + picture_->serialize(&stream, nullptr);
|
| + if (stream.bytesWritten() > 0) {
|
| + SkAutoDataUnref data(stream.copyToData());
|
| + details->set_picture(data->data(), data->size());
|
| + }
|
| + }
|
| +}
|
| +
|
| +void DrawingDisplayItem::FromProtobuf(const proto::DisplayItem& proto) {
|
| + DCHECK_EQ(proto::DisplayItem::Type_Drawing, proto.type());
|
| +
|
| + skia::RefPtr<SkPicture> picture;
|
| + const proto::DrawingDisplayItem& details = proto.details_drawing();
|
| + if (details.has_picture()) {
|
| + SkMemoryStream stream(details.picture().data(), details.picture().size());
|
| +
|
| + // TODO(dtrainor, nyquist): Add an image decoder.
|
| + picture = skia::AdoptRef(SkPicture::CreateFromStream(&stream, nullptr));
|
| + }
|
| +
|
| + SetNew(picture.Pass());
|
| +}
|
| +
|
| void DrawingDisplayItem::Raster(SkCanvas* canvas,
|
| const gfx::Rect& canvas_target_playback_rect,
|
| SkPicture::AbortCallback* callback) const {
|
|
|