OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/layers/picture_layer.h" | 5 #include "cc/layers/picture_layer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
11 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
13 #include "cc/layers/content_layer_client.h" | 13 #include "cc/layers/content_layer_client.h" |
14 #include "cc/layers/empty_content_layer_client.h" | 14 #include "cc/layers/empty_content_layer_client.h" |
15 #include "cc/layers/picture_layer_impl.h" | 15 #include "cc/layers/picture_layer_impl.h" |
16 #include "cc/playback/display_item_list_settings.h" | 16 #include "cc/playback/display_item_list_settings.h" |
17 #include "cc/proto/layer.pb.h" | 17 #include "cc/proto/layer.pb.h" |
18 #include "cc/test/fake_client_picture_cache.h" | |
19 #include "cc/test/fake_engine_picture_cache.h" | |
18 #include "cc/test/fake_image_serialization_processor.h" | 20 #include "cc/test/fake_image_serialization_processor.h" |
19 #include "cc/test/fake_layer_tree_host.h" | 21 #include "cc/test/fake_layer_tree_host.h" |
20 #include "cc/test/fake_output_surface.h" | 22 #include "cc/test/fake_output_surface.h" |
21 #include "cc/test/fake_picture_layer.h" | 23 #include "cc/test/fake_picture_layer.h" |
22 #include "cc/test/fake_picture_layer_impl.h" | 24 #include "cc/test/fake_picture_layer_impl.h" |
23 #include "cc/test/fake_proxy.h" | 25 #include "cc/test/fake_proxy.h" |
24 #include "cc/test/fake_recording_source.h" | 26 #include "cc/test/fake_recording_source.h" |
25 #include "cc/test/layer_tree_settings_for_testing.h" | 27 #include "cc/test/layer_tree_settings_for_testing.h" |
26 #include "cc/test/skia_common.h" | 28 #include "cc/test/skia_common.h" |
27 #include "cc/test/test_shared_bitmap_manager.h" | 29 #include "cc/test/test_shared_bitmap_manager.h" |
28 #include "cc/test/test_task_graph_runner.h" | 30 #include "cc/test/test_task_graph_runner.h" |
29 #include "cc/trees/single_thread_proxy.h" | 31 #include "cc/trees/single_thread_proxy.h" |
32 #include "testing/gmock/include/gmock/gmock.h" | |
30 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "third_party/skia/include/core/SkRefCnt.h" | 34 #include "third_party/skia/include/core/SkRefCnt.h" |
32 | 35 |
33 namespace cc { | 36 namespace cc { |
34 | 37 |
35 class TestSerializationPictureLayer : public PictureLayer { | 38 class TestSerializationPictureLayer : public PictureLayer { |
36 public: | 39 public: |
37 static scoped_refptr<TestSerializationPictureLayer> Create( | 40 static scoped_refptr<TestSerializationPictureLayer> Create( |
38 const gfx::Size& recording_source_viewport) { | 41 const gfx::Size& recording_source_viewport) { |
39 return make_scoped_refptr(new TestSerializationPictureLayer( | 42 return make_scoped_refptr(new TestSerializationPictureLayer( |
(...skipping 14 matching lines...) Expand all Loading... | |
54 void set_update_source_frame_number(int number) { | 57 void set_update_source_frame_number(int number) { |
55 update_source_frame_number_ = number; | 58 update_source_frame_number_ = number; |
56 } | 59 } |
57 | 60 |
58 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } | 61 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } |
59 | 62 |
60 void set_nearest_neighbor(bool nearest_neighbor) { | 63 void set_nearest_neighbor(bool nearest_neighbor) { |
61 nearest_neighbor_ = nearest_neighbor; | 64 nearest_neighbor_ = nearest_neighbor; |
62 } | 65 } |
63 | 66 |
64 void ValidateSerialization() { | 67 void ValidateSerialization( |
68 ImageSerializationProcessor* image_serialization_processor, | |
69 LayerTreeHost* host) { | |
70 std::vector<uint32_t> engine_picture_ids = GetPictureIds(); | |
65 proto::LayerProperties proto; | 71 proto::LayerProperties proto; |
66 LayerSpecificPropertiesToProto(&proto); | 72 LayerSpecificPropertiesToProto(&proto); |
67 | 73 |
68 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 74 FakeEnginePictureCache* engine_picture_cache = |
69 TestTaskGraphRunner task_graph_runner; | 75 static_cast<FakeEnginePictureCache*>(host->engine_picture_cache()); |
70 LayerTreeSettings settings; | 76 EXPECT_THAT(engine_picture_ids, |
71 std::unique_ptr<FakeImageSerializationProcessor> | 77 testing::UnorderedElementsAreArray( |
72 fake_image_serialization_processor = | 78 engine_picture_cache->GetAllUsedPictureIds())); |
73 base::WrapUnique(new FakeImageSerializationProcessor); | 79 |
74 std::unique_ptr<FakeLayerTreeHost> host = | |
75 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | |
76 CompositorMode::SINGLE_THREADED, | |
77 fake_image_serialization_processor.get()); | |
78 scoped_refptr<TestSerializationPictureLayer> layer = | 80 scoped_refptr<TestSerializationPictureLayer> layer = |
79 TestSerializationPictureLayer::Create(recording_source_viewport_); | 81 TestSerializationPictureLayer::Create(recording_source_viewport_); |
80 host->SetRootLayer(layer); | 82 host->SetRootLayer(layer); |
83 | |
81 layer->FromLayerSpecificPropertiesProto(proto); | 84 layer->FromLayerSpecificPropertiesProto(proto); |
82 | 85 |
86 FakeClientPictureCache* client_picture_cache = | |
87 static_cast<FakeClientPictureCache*>(host->client_picture_cache()); | |
88 EXPECT_THAT(engine_picture_ids, | |
89 testing::UnorderedElementsAreArray( | |
90 client_picture_cache->GetAllUsedPictureIds())); | |
91 | |
83 // Validate that the PictureLayer specific fields are properly set. | 92 // Validate that the PictureLayer specific fields are properly set. |
84 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); | 93 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); |
85 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); | 94 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); |
86 EXPECT_EQ(is_mask_, layer->is_mask_); | 95 EXPECT_EQ(is_mask_, layer->is_mask_); |
87 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); | 96 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); |
88 } | 97 } |
89 | 98 |
99 std::vector<uint32_t> GetPictureIds() { | |
100 scoped_refptr<const DisplayItemList> display_list = | |
101 recording_source()->GetDisplayItemList(); | |
102 if (!display_list) | |
103 return std::vector<uint32_t>(); | |
vmpstr
2016/06/24 18:58:32
super nit: I wonder if you're ruining rvo by havin
nyquist
2016/06/24 20:31:23
Done.
| |
104 | |
105 std::vector<uint32_t> ids; | |
106 for (auto it = display_list->begin(); it != display_list->end(); ++it) { | |
107 sk_sp<const SkPicture> picture = it->GetPicture(); | |
108 if (!picture) | |
109 continue; | |
110 | |
111 ids.push_back(picture->uniqueID()); | |
112 } | |
113 return ids; | |
114 } | |
115 | |
90 private: | 116 private: |
91 TestSerializationPictureLayer(ContentLayerClient* client, | 117 TestSerializationPictureLayer(ContentLayerClient* client, |
92 std::unique_ptr<RecordingSource> source, | 118 std::unique_ptr<RecordingSource> source, |
93 const gfx::Size& recording_source_viewport) | 119 const gfx::Size& recording_source_viewport) |
94 : PictureLayer(client, std::move(source)), | 120 : PictureLayer(client, std::move(source)), |
95 recording_source_viewport_(recording_source_viewport) {} | 121 recording_source_viewport_(recording_source_viewport) {} |
96 ~TestSerializationPictureLayer() override {} | 122 ~TestSerializationPictureLayer() override {} |
97 | 123 |
98 gfx::Size recording_source_viewport_; | 124 gfx::Size recording_source_viewport_; |
99 | 125 |
100 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); | 126 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); |
101 }; | 127 }; |
102 | 128 |
103 namespace { | 129 namespace { |
104 | 130 |
105 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { | 131 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { |
106 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 132 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
107 TestTaskGraphRunner task_graph_runner; | 133 TestTaskGraphRunner task_graph_runner; |
108 LayerTreeSettings settings; | 134 LayerTreeSettings settings; |
109 std::unique_ptr<FakeImageSerializationProcessor> | 135 std::unique_ptr<FakeImageSerializationProcessor> |
110 fake_image_serialization_processor = | 136 fake_image_serialization_processor = |
111 base::WrapUnique(new FakeImageSerializationProcessor); | 137 base::WrapUnique(new FakeImageSerializationProcessor); |
112 std::unique_ptr<FakeLayerTreeHost> host = | 138 std::unique_ptr<FakeLayerTreeHost> host = |
113 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, | 139 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings, |
114 CompositorMode::SINGLE_THREADED, | 140 CompositorMode::SINGLE_THREADED, |
115 fake_image_serialization_processor.get()); | 141 fake_image_serialization_processor.get()); |
142 host->InitializePictureCacheForTesting(); | |
116 | 143 |
117 gfx::Size recording_source_viewport(256, 256); | 144 gfx::Size recording_source_viewport(256, 256); |
118 scoped_refptr<TestSerializationPictureLayer> layer = | 145 scoped_refptr<TestSerializationPictureLayer> layer = |
119 TestSerializationPictureLayer::Create(recording_source_viewport); | 146 TestSerializationPictureLayer::Create(recording_source_viewport); |
120 host->SetRootLayer(layer); | 147 host->SetRootLayer(layer); |
121 | 148 |
122 Region region(gfx::Rect(14, 15, 16, 17)); | 149 Region region(gfx::Rect(14, 15, 16, 17)); |
123 layer->set_invalidation(region); | 150 layer->set_invalidation(region); |
124 layer->set_is_mask(true); | 151 layer->set_is_mask(true); |
125 layer->set_nearest_neighbor(true); | 152 layer->set_nearest_neighbor(true); |
126 | 153 |
127 layer->SetBounds(recording_source_viewport); | 154 layer->SetBounds(recording_source_viewport); |
128 layer->set_update_source_frame_number(0); | 155 layer->set_update_source_frame_number(0); |
129 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 156 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
130 layer->recording_source()->add_draw_rect( | 157 layer->recording_source()->add_draw_rect( |
131 gfx::Rect(recording_source_viewport)); | 158 gfx::Rect(recording_source_viewport)); |
132 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 159 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
133 layer->recording_source()->Rerecord(); | 160 layer->recording_source()->Rerecord(); |
134 layer->ValidateSerialization(); | 161 layer->ValidateSerialization(fake_image_serialization_processor.get(), |
162 host.get()); | |
135 } | 163 } |
136 | 164 |
137 TEST(PictureLayerTest, TestSerializationDeserialization) { | 165 TEST(PictureLayerTest, TestSerializationDeserialization) { |
138 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 166 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
139 TestTaskGraphRunner task_graph_runner; | 167 TestTaskGraphRunner task_graph_runner; |
140 std::unique_ptr<FakeImageSerializationProcessor> | 168 std::unique_ptr<FakeImageSerializationProcessor> |
141 fake_image_serialization_processor = | 169 fake_image_serialization_processor = |
142 base::WrapUnique(new FakeImageSerializationProcessor); | 170 base::WrapUnique(new FakeImageSerializationProcessor); |
143 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 171 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
144 &host_client, &task_graph_runner, LayerTreeSettings(), | 172 &host_client, &task_graph_runner, LayerTreeSettings(), |
145 CompositorMode::SINGLE_THREADED, | 173 CompositorMode::SINGLE_THREADED, |
146 fake_image_serialization_processor.get()); | 174 fake_image_serialization_processor.get()); |
175 host->InitializePictureCacheForTesting(); | |
176 | |
147 gfx::Size recording_source_viewport(256, 256); | 177 gfx::Size recording_source_viewport(256, 256); |
148 scoped_refptr<TestSerializationPictureLayer> layer = | 178 scoped_refptr<TestSerializationPictureLayer> layer = |
149 TestSerializationPictureLayer::Create(recording_source_viewport); | 179 TestSerializationPictureLayer::Create(recording_source_viewport); |
150 host->SetRootLayer(layer); | 180 host->SetRootLayer(layer); |
151 | 181 |
152 layer->SetBounds(recording_source_viewport); | 182 layer->SetBounds(recording_source_viewport); |
153 layer->set_update_source_frame_number(0); | 183 layer->set_update_source_frame_number(0); |
154 layer->recording_source()->SetDisplayListUsesCachedPicture(false); | 184 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
155 layer->recording_source()->add_draw_rect( | 185 layer->recording_source()->add_draw_rect( |
156 gfx::Rect(recording_source_viewport)); | 186 gfx::Rect(recording_source_viewport)); |
157 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); | 187 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
158 layer->recording_source()->Rerecord(); | 188 layer->recording_source()->Rerecord(); |
159 layer->ValidateSerialization(); | 189 layer->ValidateSerialization(fake_image_serialization_processor.get(), |
190 host.get()); | |
160 } | 191 } |
161 | 192 |
162 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { | 193 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { |
194 std::unique_ptr<FakeImageSerializationProcessor> | |
195 fake_image_serialization_processor = | |
196 base::WrapUnique(new FakeImageSerializationProcessor); | |
163 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 197 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
164 TestTaskGraphRunner task_graph_runner; | 198 TestTaskGraphRunner task_graph_runner; |
165 std::unique_ptr<FakeLayerTreeHost> host = | 199 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
166 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 200 &host_client, &task_graph_runner, LayerTreeSettings(), |
201 CompositorMode::SINGLE_THREADED, | |
202 fake_image_serialization_processor.get()); | |
203 host->InitializePictureCacheForTesting(); | |
167 | 204 |
168 gfx::Size recording_source_viewport(256, 256); | 205 gfx::Size recording_source_viewport(256, 256); |
169 scoped_refptr<TestSerializationPictureLayer> layer = | 206 scoped_refptr<TestSerializationPictureLayer> layer = |
170 TestSerializationPictureLayer::Create(recording_source_viewport); | 207 TestSerializationPictureLayer::Create(recording_source_viewport); |
171 host->SetRootLayer(layer); | 208 host->SetRootLayer(layer); |
172 layer->ValidateSerialization(); | 209 layer->ValidateSerialization(fake_image_serialization_processor.get(), |
210 host.get()); | |
173 } | 211 } |
174 | 212 |
175 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 213 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
176 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 214 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
177 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); | 215 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); |
178 layer->SetBounds(gfx::Size(10, 10)); | 216 layer->SetBounds(gfx::Size(10, 10)); |
179 | 217 |
180 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 218 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
181 TestTaskGraphRunner task_graph_runner; | 219 TestTaskGraphRunner task_graph_runner; |
182 std::unique_ptr<FakeLayerTreeHost> host = | 220 std::unique_ptr<FakeLayerTreeHost> host = |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 // Do a main frame, record the picture layers. The frame number has changed | 517 // Do a main frame, record the picture layers. The frame number has changed |
480 // non-monotonically. | 518 // non-monotonically. |
481 layer->SetNeedsDisplay(); | 519 layer->SetNeedsDisplay(); |
482 host2->Composite(base::TimeTicks::Now()); | 520 host2->Composite(base::TimeTicks::Now()); |
483 EXPECT_EQ(3, layer->update_count()); | 521 EXPECT_EQ(3, layer->update_count()); |
484 EXPECT_EQ(1, host2->source_frame_number()); | 522 EXPECT_EQ(1, host2->source_frame_number()); |
485 } | 523 } |
486 | 524 |
487 } // namespace | 525 } // namespace |
488 } // namespace cc | 526 } // namespace cc |
OLD | NEW |