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

Unified Diff: cc/blimp/picture_data_conversions_unittest.cc

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from vmpstr, including adding //cc/blimp Created 4 years, 6 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/blimp/picture_data_conversions.cc ('k') | cc/cc.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/blimp/picture_data_conversions_unittest.cc
diff --git a/cc/blimp/picture_data_conversions_unittest.cc b/cc/blimp/picture_data_conversions_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8c298cfe317b08a55ec7fd5c1a2726f87e5ebf07
--- /dev/null
+++ b/cc/blimp/picture_data_conversions_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/blimp/picture_data_conversions.h"
+
+#include <memory>
+#include <set>
+
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "cc/blimp/picture_data.h"
+#include "cc/proto/layer_tree_host.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "third_party/skia/include/core/SkData.h"
+#include "third_party/skia/include/core/SkPicture.h"
+#include "third_party/skia/include/core/SkPictureRecorder.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkStream.h"
+
+namespace cc {
+namespace {
+sk_sp<const SkPicture> CreateSkPicture(SkColor color) {
+ SkPictureRecorder recorder;
+ sk_sp<SkCanvas> canvas =
+ sk_ref_sp(recorder.beginRecording(SkRect::MakeWH(1, 1)));
+ canvas->drawColor(color);
+ return recorder.finishRecordingAsPicture();
+}
+
+sk_sp<SkData> SerializePicture(sk_sp<const SkPicture> picture) {
+ SkDynamicMemoryWStream stream;
+ picture->serialize(&stream, nullptr);
+ DCHECK(stream.bytesWritten());
+ return sk_sp<SkData>(stream.copyToData());
+}
+
+bool SamePicture(sk_sp<const SkPicture> picture,
+ const PictureData& picture_data) {
+ if (picture->uniqueID() != picture_data.unique_id)
+ return false;
+
+ sk_sp<const SkData> serialized_picture = SerializePicture(picture);
+ return picture_data.data->equals(serialized_picture);
+}
+
+PictureData CreatePictureData(sk_sp<const SkPicture> picture) {
+ return PictureData(picture->uniqueID(), SerializePicture(picture));
+}
+
+TEST(PictureCacheConversionsTest, SerializePictureCaheUpdate) {
+ sk_sp<const SkPicture> picture1 = CreateSkPicture(SK_ColorRED);
+ sk_sp<const SkPicture> picture2 = CreateSkPicture(SK_ColorBLUE);
+ std::vector<PictureData> update;
+ update.push_back(CreatePictureData(picture1));
+ update.push_back(CreatePictureData(picture2));
+
+ proto::SkPictures proto_pictures;
+ PictureDataVectorToSkPicturesProto(update, &proto_pictures);
+ ASSERT_EQ(2, proto_pictures.pictures_size());
+
+ std::vector<PictureData> deserialized =
+ SkPicturesProtoToPictureDataVector(proto_pictures);
+
+ ASSERT_EQ(2U, deserialized.size());
+ PictureData picture_data_1 = deserialized.at(0);
+ PictureData picture_data_2 = deserialized.at(1);
+ EXPECT_TRUE(SamePicture(picture1, picture_data_1));
+ EXPECT_TRUE(SamePicture(picture2, picture_data_2));
+}
+
+} // namespace
+} // namespace cc
« no previous file with comments | « cc/blimp/picture_data_conversions.cc ('k') | cc/cc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698