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/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
| 11 #include "cc/layers/empty_content_layer_client.h" |
11 #include "cc/layers/layer_settings.h" | 12 #include "cc/layers/layer_settings.h" |
12 #include "cc/layers/picture_layer_impl.h" | 13 #include "cc/layers/picture_layer_impl.h" |
13 #include "cc/playback/display_item_list_settings.h" | 14 #include "cc/playback/display_item_list_settings.h" |
| 15 #include "cc/proto/layer.pb.h" |
14 #include "cc/test/fake_display_list_recording_source.h" | 16 #include "cc/test/fake_display_list_recording_source.h" |
15 #include "cc/test/fake_layer_tree_host.h" | 17 #include "cc/test/fake_layer_tree_host.h" |
16 #include "cc/test/fake_picture_layer.h" | 18 #include "cc/test/fake_picture_layer.h" |
17 #include "cc/test/fake_picture_layer_impl.h" | 19 #include "cc/test/fake_picture_layer_impl.h" |
18 #include "cc/test/fake_proxy.h" | 20 #include "cc/test/fake_proxy.h" |
19 #include "cc/test/layer_tree_settings_for_testing.h" | 21 #include "cc/test/layer_tree_settings_for_testing.h" |
20 #include "cc/test/test_shared_bitmap_manager.h" | 22 #include "cc/test/test_shared_bitmap_manager.h" |
21 #include "cc/test/test_task_graph_runner.h" | 23 #include "cc/test/test_task_graph_runner.h" |
22 #include "cc/trees/single_thread_proxy.h" | 24 #include "cc/trees/single_thread_proxy.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 | 26 |
25 namespace cc { | 27 namespace cc { |
| 28 |
| 29 class TestSerializationPictureLayer : public PictureLayer { |
| 30 public: |
| 31 static scoped_refptr<TestSerializationPictureLayer> Create( |
| 32 const gfx::Size& recording_source_viewport) { |
| 33 return make_scoped_refptr(new TestSerializationPictureLayer( |
| 34 LayerSettings(), EmptyContentLayerClient::GetInstance(), |
| 35 FakeDisplayListRecordingSource::CreateFilledRecordingSource( |
| 36 recording_source_viewport), |
| 37 recording_source_viewport)); |
| 38 } |
| 39 |
| 40 FakeDisplayListRecordingSource* recording_source() { |
| 41 return static_cast<FakeDisplayListRecordingSource*>( |
| 42 recording_source_.get()); |
| 43 } |
| 44 |
| 45 void set_invalidation(const Region& invalidation) { |
| 46 *invalidation_.region() = invalidation; |
| 47 } |
| 48 |
| 49 void set_last_updated_visible_layer_rect(const gfx::Rect& rect) { |
| 50 last_updated_visible_layer_rect_ = rect; |
| 51 } |
| 52 |
| 53 void set_update_source_frame_number(int number) { |
| 54 update_source_frame_number_ = number; |
| 55 } |
| 56 |
| 57 void set_is_mask(bool is_mask) { is_mask_ = is_mask; } |
| 58 |
| 59 void set_nearest_neighbor(bool nearest_neighbor) { |
| 60 nearest_neighbor_ = nearest_neighbor; |
| 61 } |
| 62 |
| 63 void ValidateSerialization() { |
| 64 proto::LayerProperties proto; |
| 65 LayerSpecificPropertiesToProto(&proto); |
| 66 |
| 67 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 68 TestTaskGraphRunner task_graph_runner; |
| 69 scoped_ptr<FakeLayerTreeHost> host = |
| 70 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 71 scoped_refptr<TestSerializationPictureLayer> layer = |
| 72 TestSerializationPictureLayer::Create(recording_source_viewport_); |
| 73 host->SetRootLayer(layer); |
| 74 layer->FromLayerSpecificPropertiesProto(proto); |
| 75 |
| 76 // Validate that the PictureLayer specific fields are properly set. |
| 77 EXPECT_TRUE(recording_source()->EqualsTo(*layer->recording_source())); |
| 78 EXPECT_EQ(last_updated_visible_layer_rect_, |
| 79 layer->last_updated_visible_layer_rect_); |
| 80 EXPECT_EQ(update_source_frame_number_, layer->update_source_frame_number_); |
| 81 EXPECT_EQ(is_mask_, layer->is_mask_); |
| 82 EXPECT_EQ(nearest_neighbor_, layer->nearest_neighbor_); |
| 83 } |
| 84 |
| 85 private: |
| 86 TestSerializationPictureLayer(const LayerSettings& settings, |
| 87 ContentLayerClient* client, |
| 88 scoped_ptr<DisplayListRecordingSource> source, |
| 89 const gfx::Size& recording_source_viewport) |
| 90 : PictureLayer(settings, client, std::move(source)), |
| 91 recording_source_viewport_(recording_source_viewport) {} |
| 92 ~TestSerializationPictureLayer() override {} |
| 93 |
| 94 gfx::Size recording_source_viewport_; |
| 95 |
| 96 DISALLOW_COPY_AND_ASSIGN(TestSerializationPictureLayer); |
| 97 }; |
| 98 |
26 namespace { | 99 namespace { |
27 | 100 |
28 class MockContentLayerClient : public ContentLayerClient { | 101 TEST(PictureLayerTest, TestSetAllPropsSerializationDeserialization) { |
29 public: | 102 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
30 gfx::Rect PaintableRegion() override { return gfx::Rect(); } | 103 TestTaskGraphRunner task_graph_runner; |
31 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 104 scoped_ptr<FakeLayerTreeHost> host = |
32 PaintingControlSetting picture_control) override { | 105 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
33 return DisplayItemList::Create(gfx::Rect(), DisplayItemListSettings()); | 106 |
34 } | 107 gfx::Size recording_source_viewport(256, 256); |
35 bool FillsBoundsCompletely() const override { return false; }; | 108 scoped_refptr<TestSerializationPictureLayer> layer = |
36 size_t GetApproximateUnsharedMemoryUsage() const override { return 0; } | 109 TestSerializationPictureLayer::Create(recording_source_viewport); |
37 }; | 110 host->SetRootLayer(layer); |
| 111 |
| 112 Region region(gfx::Rect(14, 15, 16, 17)); |
| 113 layer->set_invalidation(region); |
| 114 layer->set_last_updated_visible_layer_rect(gfx::Rect(5, 6, 7, 8)); |
| 115 layer->set_is_mask(true); |
| 116 layer->set_nearest_neighbor(true); |
| 117 |
| 118 layer->SetBounds(recording_source_viewport); |
| 119 layer->set_update_source_frame_number(0); |
| 120 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 121 layer->recording_source()->add_draw_rect( |
| 122 gfx::Rect(recording_source_viewport)); |
| 123 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 124 layer->recording_source()->Rerecord(); |
| 125 layer->ValidateSerialization(); |
| 126 } |
| 127 |
| 128 TEST(PictureLayerTest, TestSerializationDeserialization) { |
| 129 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 130 TestTaskGraphRunner task_graph_runner; |
| 131 scoped_ptr<FakeLayerTreeHost> host = |
| 132 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 133 |
| 134 gfx::Size recording_source_viewport(256, 256); |
| 135 scoped_refptr<TestSerializationPictureLayer> layer = |
| 136 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 137 host->SetRootLayer(layer); |
| 138 |
| 139 layer->SetBounds(recording_source_viewport); |
| 140 layer->set_update_source_frame_number(0); |
| 141 layer->recording_source()->SetDisplayListUsesCachedPicture(false); |
| 142 layer->recording_source()->add_draw_rect( |
| 143 gfx::Rect(recording_source_viewport)); |
| 144 layer->recording_source()->SetGenerateDiscardableImagesMetadata(true); |
| 145 layer->recording_source()->Rerecord(); |
| 146 layer->ValidateSerialization(); |
| 147 } |
| 148 |
| 149 TEST(PictureLayerTest, TestEmptySerializationDeserialization) { |
| 150 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
| 151 TestTaskGraphRunner task_graph_runner; |
| 152 scoped_ptr<FakeLayerTreeHost> host = |
| 153 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
| 154 |
| 155 gfx::Size recording_source_viewport(256, 256); |
| 156 scoped_refptr<TestSerializationPictureLayer> layer = |
| 157 TestSerializationPictureLayer::Create(recording_source_viewport); |
| 158 host->SetRootLayer(layer); |
| 159 layer->ValidateSerialization(); |
| 160 } |
38 | 161 |
39 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 162 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
40 MockContentLayerClient client; | 163 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
41 scoped_refptr<PictureLayer> layer = | 164 scoped_refptr<PictureLayer> layer = |
42 PictureLayer::Create(LayerSettings(), &client); | 165 PictureLayer::Create(LayerSettings(), client); |
43 layer->SetBounds(gfx::Size(10, 10)); | 166 layer->SetBounds(gfx::Size(10, 10)); |
44 | 167 |
45 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 168 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
46 TestTaskGraphRunner task_graph_runner; | 169 TestTaskGraphRunner task_graph_runner; |
47 scoped_ptr<FakeLayerTreeHost> host = | 170 scoped_ptr<FakeLayerTreeHost> host = |
48 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 171 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
49 host->SetRootLayer(layer); | 172 host->SetRootLayer(layer); |
50 layer->SetIsDrawable(true); | 173 layer->SetIsDrawable(true); |
51 layer->SavePaintProperties(); | 174 layer->SavePaintProperties(); |
52 layer->Update(); | 175 layer->Update(); |
(...skipping 23 matching lines...) Expand all Loading... |
76 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); | 199 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); |
77 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); | 200 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); |
78 } | 201 } |
79 | 202 |
80 TEST(PictureLayerTest, SuitableForGpuRasterization) { | 203 TEST(PictureLayerTest, SuitableForGpuRasterization) { |
81 scoped_ptr<FakeDisplayListRecordingSource> recording_source_owned( | 204 scoped_ptr<FakeDisplayListRecordingSource> recording_source_owned( |
82 new FakeDisplayListRecordingSource); | 205 new FakeDisplayListRecordingSource); |
83 FakeDisplayListRecordingSource* recording_source = | 206 FakeDisplayListRecordingSource* recording_source = |
84 recording_source_owned.get(); | 207 recording_source_owned.get(); |
85 | 208 |
86 MockContentLayerClient client; | 209 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
87 scoped_refptr<FakePictureLayer> layer = | 210 scoped_refptr<FakePictureLayer> layer = |
88 FakePictureLayer::CreateWithRecordingSource( | 211 FakePictureLayer::CreateWithRecordingSource( |
89 LayerSettings(), &client, std::move(recording_source_owned)); | 212 LayerSettings(), client, std::move(recording_source_owned)); |
90 | 213 |
91 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 214 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
92 TestTaskGraphRunner task_graph_runner; | 215 TestTaskGraphRunner task_graph_runner; |
93 scoped_ptr<FakeLayerTreeHost> host = | 216 scoped_ptr<FakeLayerTreeHost> host = |
94 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | 217 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); |
95 host->SetRootLayer(layer); | 218 host->SetRootLayer(layer); |
96 | 219 |
97 // Update layers to initialize the recording source. | 220 // Update layers to initialize the recording source. |
98 gfx::Size layer_bounds(200, 200); | 221 gfx::Size layer_bounds(200, 200); |
99 gfx::Rect layer_rect(layer_bounds); | 222 gfx::Rect layer_rect(layer_bounds); |
100 Region invalidation(layer_rect); | 223 Region invalidation(layer_rect); |
101 recording_source->UpdateAndExpandInvalidation( | 224 recording_source->UpdateAndExpandInvalidation( |
102 &client, &invalidation, layer_bounds, layer_rect, 1, | 225 client, &invalidation, layer_bounds, layer_rect, 1, |
103 DisplayListRecordingSource::RECORD_NORMALLY); | 226 DisplayListRecordingSource::RECORD_NORMALLY); |
104 | 227 |
105 // Layer is suitable for gpu rasterization by default. | 228 // Layer is suitable for gpu rasterization by default. |
106 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); | 229 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); |
107 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); | 230 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); |
108 | 231 |
109 // Veto gpu rasterization. | 232 // Veto gpu rasterization. |
110 recording_source->SetUnsuitableForGpuRasterization(); | 233 recording_source->SetUnsuitableForGpuRasterization(); |
111 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); | 234 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); |
112 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); | 235 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); |
113 } | 236 } |
114 | 237 |
115 // PicturePile uses the source frame number as a unit for measuring invalidation | 238 // PicturePile uses the source frame number as a unit for measuring invalidation |
116 // frequency. When a pile moves between compositors, the frame number increases | 239 // frequency. When a pile moves between compositors, the frame number increases |
117 // non-monotonically. This executes that code path under this scenario allowing | 240 // non-monotonically. This executes that code path under this scenario allowing |
118 // for the code to verify correctness with DCHECKs. | 241 // for the code to verify correctness with DCHECKs. |
119 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { | 242 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { |
120 LayerTreeSettingsForTesting settings; | 243 LayerTreeSettingsForTesting settings; |
121 settings.single_thread_proxy_scheduler = false; | 244 settings.single_thread_proxy_scheduler = false; |
122 settings.use_zero_copy = true; | 245 settings.use_zero_copy = true; |
123 | 246 |
124 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); | 247 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); |
125 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); | 248 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); |
126 TestSharedBitmapManager shared_bitmap_manager; | 249 TestSharedBitmapManager shared_bitmap_manager; |
127 TestTaskGraphRunner task_graph_runner; | 250 TestTaskGraphRunner task_graph_runner; |
128 | 251 |
129 MockContentLayerClient client; | 252 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
130 scoped_refptr<FakePictureLayer> layer = | 253 scoped_refptr<FakePictureLayer> layer = |
131 FakePictureLayer::Create(LayerSettings(), &client); | 254 FakePictureLayer::Create(LayerSettings(), client); |
132 | 255 |
133 LayerTreeHost::InitParams params; | 256 LayerTreeHost::InitParams params; |
134 params.client = &host_client1; | 257 params.client = &host_client1; |
135 params.shared_bitmap_manager = &shared_bitmap_manager; | 258 params.shared_bitmap_manager = &shared_bitmap_manager; |
136 params.settings = &settings; | 259 params.settings = &settings; |
137 params.task_graph_runner = &task_graph_runner; | 260 params.task_graph_runner = &task_graph_runner; |
138 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 261 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
139 scoped_ptr<LayerTreeHost> host1 = | 262 scoped_ptr<LayerTreeHost> host1 = |
140 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); | 263 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); |
141 host1->SetVisible(true); | 264 host1->SetVisible(true); |
(...skipping 27 matching lines...) Expand all Loading... |
169 // Do a main frame, record the picture layers. The frame number has changed | 292 // Do a main frame, record the picture layers. The frame number has changed |
170 // non-monotonically. | 293 // non-monotonically. |
171 layer->SetNeedsDisplay(); | 294 layer->SetNeedsDisplay(); |
172 host2->Composite(base::TimeTicks::Now()); | 295 host2->Composite(base::TimeTicks::Now()); |
173 EXPECT_EQ(3, layer->update_count()); | 296 EXPECT_EQ(3, layer->update_count()); |
174 EXPECT_EQ(1, host2->source_frame_number()); | 297 EXPECT_EQ(1, host2->source_frame_number()); |
175 } | 298 } |
176 | 299 |
177 } // namespace | 300 } // namespace |
178 } // namespace cc | 301 } // namespace cc |
OLD | NEW |