OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/blimp/picture_data_conversions.h" |
| 6 |
| 7 #include <memory> |
| 8 #include <set> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "cc/blimp/picture_data.h" |
| 13 #include "cc/proto/layer_tree_host.pb.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "third_party/skia/include/core/SkData.h" |
| 18 #include "third_party/skia/include/core/SkPicture.h" |
| 19 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 20 #include "third_party/skia/include/core/SkRefCnt.h" |
| 21 #include "third_party/skia/include/core/SkStream.h" |
| 22 |
| 23 namespace cc { |
| 24 namespace { |
| 25 sk_sp<const SkPicture> CreateSkPicture(SkColor color) { |
| 26 SkPictureRecorder recorder; |
| 27 sk_sp<SkCanvas> canvas = |
| 28 sk_ref_sp(recorder.beginRecording(SkRect::MakeWH(1, 1))); |
| 29 canvas->drawColor(color); |
| 30 return recorder.finishRecordingAsPicture(); |
| 31 } |
| 32 |
| 33 sk_sp<SkData> SerializePicture(sk_sp<const SkPicture> picture) { |
| 34 SkDynamicMemoryWStream stream; |
| 35 picture->serialize(&stream, nullptr); |
| 36 DCHECK(stream.bytesWritten()); |
| 37 return sk_sp<SkData>(stream.copyToData()); |
| 38 } |
| 39 |
| 40 bool SamePicture(sk_sp<const SkPicture> picture, |
| 41 const PictureData& picture_data) { |
| 42 if (picture->uniqueID() != picture_data.unique_id) |
| 43 return false; |
| 44 |
| 45 sk_sp<const SkData> serialized_picture = SerializePicture(picture); |
| 46 return picture_data.data->equals(serialized_picture); |
| 47 } |
| 48 |
| 49 PictureData CreatePictureData(sk_sp<const SkPicture> picture) { |
| 50 return PictureData(picture->uniqueID(), SerializePicture(picture)); |
| 51 } |
| 52 |
| 53 TEST(PictureCacheConversionsTest, SerializePictureCaheUpdate) { |
| 54 sk_sp<const SkPicture> picture1 = CreateSkPicture(SK_ColorRED); |
| 55 sk_sp<const SkPicture> picture2 = CreateSkPicture(SK_ColorBLUE); |
| 56 std::vector<PictureData> update; |
| 57 update.push_back(CreatePictureData(picture1)); |
| 58 update.push_back(CreatePictureData(picture2)); |
| 59 |
| 60 proto::SkPictures proto_pictures; |
| 61 PictureDataVectorToSkPicturesProto(update, &proto_pictures); |
| 62 ASSERT_EQ(2, proto_pictures.pictures_size()); |
| 63 |
| 64 std::vector<PictureData> deserialized = |
| 65 SkPicturesProtoToPictureDataVector(proto_pictures); |
| 66 |
| 67 ASSERT_EQ(2U, deserialized.size()); |
| 68 PictureData picture_data_1 = deserialized.at(0); |
| 69 PictureData picture_data_2 = deserialized.at(1); |
| 70 EXPECT_TRUE(SamePicture(picture1, picture_data_1)); |
| 71 EXPECT_TRUE(SamePicture(picture2, picture_data_2)); |
| 72 } |
| 73 |
| 74 } // namespace |
| 75 } // namespace cc |
OLD | NEW |