| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "cc/base/region.h" | 8 #include "cc/base/region.h" |
| 9 #include "cc/playback/raster_source.h" | 9 #include "cc/playback/raster_source.h" |
| 10 #include "cc/proto/recording_source.pb.h" | 10 #include "cc/proto/recording_source.pb.h" |
| 11 #include "cc/test/fake_client_picture_cache.h" |
| 11 #include "cc/test/fake_content_layer_client.h" | 12 #include "cc/test/fake_content_layer_client.h" |
| 13 #include "cc/test/fake_engine_picture_cache.h" |
| 12 #include "cc/test/fake_image_serialization_processor.h" | 14 #include "cc/test/fake_image_serialization_processor.h" |
| 13 #include "cc/test/fake_recording_source.h" | 15 #include "cc/test/fake_recording_source.h" |
| 14 #include "cc/test/skia_common.h" | 16 #include "cc/test/skia_common.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/skia/include/core/SkRefCnt.h" | 19 #include "third_party/skia/include/core/SkRefCnt.h" |
| 17 | 20 |
| 18 namespace cc { | 21 namespace cc { |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 std::unique_ptr<FakeRecordingSource> CreateRecordingSource( | 24 std::unique_ptr<FakeRecordingSource> CreateRecordingSource( |
| 22 const gfx::Rect& viewport) { | 25 const gfx::Rect& viewport) { |
| 23 gfx::Rect layer_rect(viewport.right(), viewport.bottom()); | 26 gfx::Rect layer_rect(viewport.right(), viewport.bottom()); |
| 24 std::unique_ptr<FakeRecordingSource> recording_source = | 27 std::unique_ptr<FakeRecordingSource> recording_source = |
| 25 FakeRecordingSource::CreateRecordingSource(viewport, layer_rect.size()); | 28 FakeRecordingSource::CreateRecordingSource(viewport, layer_rect.size()); |
| 26 return recording_source; | 29 return recording_source; |
| 27 } | 30 } |
| 28 | 31 |
| 29 scoped_refptr<RasterSource> CreateRasterSource( | 32 scoped_refptr<RasterSource> CreateRasterSource( |
| 30 FakeRecordingSource* recording_source) { | 33 FakeRecordingSource* recording_source) { |
| 31 bool can_use_lcd_text = true; | 34 bool can_use_lcd_text = true; |
| 32 return RasterSource::CreateFromRecordingSource(recording_source, | 35 return RasterSource::CreateFromRecordingSource(recording_source, |
| 33 can_use_lcd_text); | 36 can_use_lcd_text); |
| 34 } | 37 } |
| 35 | 38 |
| 36 void ValidateRecordingSourceSerialization(FakeRecordingSource* source) { | 39 void ValidateRecordingSourceSerialization(FakeRecordingSource* source) { |
| 37 std::unique_ptr<FakeImageSerializationProcessor> | 40 std::unique_ptr<FakeImageSerializationProcessor> |
| 38 fake_image_serialization_processor = | 41 fake_image_serialization_processor = |
| 39 base::WrapUnique(new FakeImageSerializationProcessor); | 42 base::WrapUnique(new FakeImageSerializationProcessor); |
| 43 std::unique_ptr<EnginePictureCache> fake_engine_picture_cache_uniq = |
| 44 fake_image_serialization_processor->CreateEnginePictureCache(); |
| 45 FakeEnginePictureCache* fake_engine_picture_cache = |
| 46 static_cast<FakeEnginePictureCache*>( |
| 47 fake_engine_picture_cache_uniq.get()); |
| 48 std::unique_ptr<ClientPictureCache> fake_client_picture_cache = |
| 49 fake_image_serialization_processor->CreateClientPictureCache(); |
| 50 |
| 51 fake_engine_picture_cache->MarkAllSkPicturesAsUsed( |
| 52 source->GetDisplayItemList().get()); |
| 40 | 53 |
| 41 proto::RecordingSource proto; | 54 proto::RecordingSource proto; |
| 42 source->ToProtobuf(&proto, fake_image_serialization_processor.get()); | 55 source->ToProtobuf(&proto); |
| 43 | 56 |
| 57 std::vector<uint32_t> actual_picture_ids; |
| 44 FakeRecordingSource new_source; | 58 FakeRecordingSource new_source; |
| 45 new_source.FromProtobuf(proto, fake_image_serialization_processor.get()); | 59 new_source.FromProtobuf(proto, fake_client_picture_cache.get(), |
| 60 &actual_picture_ids); |
| 61 |
| 62 EXPECT_THAT(actual_picture_ids, |
| 63 testing::UnorderedElementsAreArray( |
| 64 fake_engine_picture_cache->GetAllUsedPictureIds())); |
| 46 | 65 |
| 47 EXPECT_TRUE(source->EqualsTo(new_source)); | 66 EXPECT_TRUE(source->EqualsTo(new_source)); |
| 48 } | 67 } |
| 49 | 68 |
| 50 TEST(RecordingSourceTest, TestNullDisplayListSerialization) { | 69 TEST(RecordingSourceTest, TestNullDisplayListSerialization) { |
| 51 gfx::Rect recorded_viewport(0, 0, 256, 256); | 70 gfx::Rect recorded_viewport(0, 0, 256, 256); |
| 52 | 71 |
| 53 std::unique_ptr<FakeRecordingSource> recording_source = | 72 std::unique_ptr<FakeRecordingSource> recording_source = |
| 54 CreateRecordingSource(recorded_viewport); | 73 CreateRecordingSource(recorded_viewport); |
| 55 recording_source->SetDisplayListUsesCachedPicture(false); | 74 recording_source->SetDisplayListUsesCachedPicture(false); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 &images); | 445 &images); |
| 427 EXPECT_EQ(3u, images.size()); | 446 EXPECT_EQ(3u, images.size()); |
| 428 EXPECT_TRUE(images[0].image() == discardable_image[0][0]); | 447 EXPECT_TRUE(images[0].image() == discardable_image[0][0]); |
| 429 EXPECT_TRUE(images[1].image() == discardable_image[0][1]); | 448 EXPECT_TRUE(images[1].image() == discardable_image[0][1]); |
| 430 EXPECT_TRUE(images[2].image() == discardable_image[1][1]); | 449 EXPECT_TRUE(images[2].image() == discardable_image[1][1]); |
| 431 } | 450 } |
| 432 } | 451 } |
| 433 | 452 |
| 434 } // namespace | 453 } // namespace |
| 435 } // namespace cc | 454 } // namespace cc |
| OLD | NEW |