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 "blimp/engine/renderer/blimp_engine_picture_cache.h" |
| 6 |
| 7 #include "blimp/test/support/compositor/picture_cache_test_support.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "third_party/skia/include/core/SkPicture.h" |
| 11 #include "third_party/skia/include/core/SkRefCnt.h" |
| 12 |
| 13 namespace blimp { |
| 14 namespace engine { |
| 15 |
| 16 namespace { |
| 17 class BlimpEnginePictureCacheTest : public testing::Test { |
| 18 public: |
| 19 BlimpEnginePictureCacheTest() : cache_(nullptr) {} |
| 20 |
| 21 protected: |
| 22 BlimpEnginePictureCache cache_; |
| 23 }; |
| 24 |
| 25 TEST_F(BlimpEnginePictureCacheTest, TwoCachedPicturesCanBeRetrieved) { |
| 26 EXPECT_EQ(0U, cache_.CalculateCacheUpdateAndFlush().size()); |
| 27 |
| 28 sk_sp<const SkPicture> picture1 = CreateSkPicture(SK_ColorBLUE); |
| 29 cache_.MarkPictureForRegistration(picture1.get()); |
| 30 sk_sp<const SkPicture> picture2 = CreateSkPicture(SK_ColorRED); |
| 31 cache_.MarkPictureForRegistration(picture2.get()); |
| 32 |
| 33 cc::PictureCacheUpdate update = cache_.CalculateCacheUpdateAndFlush(); |
| 34 ASSERT_EQ(2U, update.size()); |
| 35 cc::PictureData picture_data_a = update.at(0); |
| 36 cc::PictureData picture_data_b = update.at(1); |
| 37 |
| 38 // Order is unknown, but pictures should be the same. |
| 39 EXPECT_TRUE((SamePicture(picture1, picture_data_a) && |
| 40 SamePicture(picture2, picture_data_b)) || |
| 41 (SamePicture(picture2, picture_data_a) && |
| 42 SamePicture(picture1, picture_data_b))); |
| 43 |
| 44 EXPECT_EQ(0U, cache_.CalculateCacheUpdateAndFlush().size()); |
| 45 } |
| 46 |
| 47 TEST_F(BlimpEnginePictureCacheTest, SamePictureOnlyReturnedOnce) { |
| 48 EXPECT_EQ(0U, cache_.CalculateCacheUpdateAndFlush().size()); |
| 49 |
| 50 sk_sp<const SkPicture> picture = CreateSkPicture(SK_ColorBLUE); |
| 51 cache_.MarkPictureForRegistration(picture.get()); |
| 52 cache_.MarkPictureForRegistration(picture.get()); |
| 53 |
| 54 cc::PictureCacheUpdate update = cache_.CalculateCacheUpdateAndFlush(); |
| 55 ASSERT_EQ(1U, update.size()); |
| 56 cc::PictureData picture_data = update.at(0); |
| 57 EXPECT_TRUE(SamePicture(picture, picture_data)); |
| 58 } |
| 59 |
| 60 } // namespace |
| 61 |
| 62 } // namespace engine |
| 63 } // namespace blimp |
OLD | NEW |