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 "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
8 #include "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
9 #include "cc/layers/picture_layer_impl.h" | 9 #include "cc/layers/picture_layer_impl.h" |
10 #include "cc/resources/resource_update_queue.h" | 10 #include "cc/resources/resource_update_queue.h" |
11 #include "cc/test/fake_layer_tree_host.h" | 11 #include "cc/test/fake_layer_tree_host.h" |
12 #include "cc/test/fake_picture_layer.h" | 12 #include "cc/test/fake_picture_layer.h" |
13 #include "cc/test/fake_picture_layer_impl.h" | 13 #include "cc/test/fake_picture_layer_impl.h" |
14 #include "cc/test/fake_proxy.h" | 14 #include "cc/test/fake_proxy.h" |
15 #include "cc/test/impl_side_painting_settings.h" | 15 #include "cc/test/impl_side_painting_settings.h" |
16 #include "cc/test/test_shared_bitmap_manager.h" | |
17 #include "cc/test/test_task_graph_runner.h" | |
16 #include "cc/trees/single_thread_proxy.h" | 18 #include "cc/trees/single_thread_proxy.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 | 20 |
19 namespace cc { | 21 namespace cc { |
20 namespace { | 22 namespace { |
21 | 23 |
22 class MockContentLayerClient : public ContentLayerClient { | 24 class MockContentLayerClient : public ContentLayerClient { |
23 public: | 25 public: |
24 void PaintContents(SkCanvas* canvas, | 26 void PaintContents(SkCanvas* canvas, |
25 const gfx::Rect& clip, | 27 const gfx::Rect& clip, |
26 PaintingControlSetting picture_control) override {} | 28 PaintingControlSetting picture_control) override {} |
27 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( | 29 scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |
28 const gfx::Rect& clip, | 30 const gfx::Rect& clip, |
29 PaintingControlSetting picture_control) override { | 31 PaintingControlSetting picture_control) override { |
30 NOTIMPLEMENTED(); | 32 NOTIMPLEMENTED(); |
31 return nullptr; | 33 return nullptr; |
32 } | 34 } |
33 bool FillsBoundsCompletely() const override { return false; }; | 35 bool FillsBoundsCompletely() const override { return false; }; |
34 }; | 36 }; |
35 | 37 |
36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 38 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
37 MockContentLayerClient client; | 39 MockContentLayerClient client; |
38 scoped_refptr<PictureLayer> layer = | 40 scoped_refptr<PictureLayer> layer = |
39 PictureLayer::Create(LayerSettings(), &client); | 41 PictureLayer::Create(LayerSettings(), &client); |
40 layer->SetBounds(gfx::Size(10, 10)); | 42 layer->SetBounds(gfx::Size(10, 10)); |
41 | 43 |
42 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 44 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
43 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); | 45 TestTaskGraphRunner task_graph_runner; |
46 scoped_ptr<FakeLayerTreeHost> host = | |
47 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | |
44 host->SetRootLayer(layer); | 48 host->SetRootLayer(layer); |
45 layer->SetIsDrawable(true); | 49 layer->SetIsDrawable(true); |
46 layer->SavePaintProperties(); | 50 layer->SavePaintProperties(); |
47 | 51 |
48 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); | 52 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); |
49 layer->Update(queue.get()); | 53 layer->Update(queue.get()); |
50 | 54 |
51 EXPECT_EQ(0, host->source_frame_number()); | 55 EXPECT_EQ(0, host->source_frame_number()); |
52 host->CommitComplete(); | 56 host->CommitComplete(); |
53 EXPECT_EQ(1, host->source_frame_number()); | 57 EXPECT_EQ(1, host->source_frame_number()); |
54 | 58 |
55 layer->SetBounds(gfx::Size(0, 0)); | 59 layer->SetBounds(gfx::Size(0, 0)); |
56 layer->SavePaintProperties(); | 60 layer->SavePaintProperties(); |
57 // Intentionally skipping Update since it would normally be skipped on | 61 // Intentionally skipping Update since it would normally be skipped on |
58 // a layer with empty bounds. | 62 // a layer with empty bounds. |
59 | 63 |
60 FakeProxy proxy; | 64 FakeProxy proxy; |
61 { | 65 { |
62 DebugScopedSetImplThread impl_thread(&proxy); | 66 DebugScopedSetImplThread impl_thread(&proxy); |
63 | 67 |
64 TestSharedBitmapManager shared_bitmap_manager; | 68 TestSharedBitmapManager shared_bitmap_manager; |
65 FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy, | 69 FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy, |
66 &shared_bitmap_manager, nullptr); | 70 &shared_bitmap_manager, &task_graph_runner); |
67 host_impl.CreatePendingTree(); | 71 host_impl.CreatePendingTree(); |
68 scoped_ptr<FakePictureLayerImpl> layer_impl = | 72 scoped_ptr<FakePictureLayerImpl> layer_impl = |
69 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); | 73 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); |
70 | 74 |
71 layer->PushPropertiesTo(layer_impl.get()); | 75 layer->PushPropertiesTo(layer_impl.get()); |
72 EXPECT_FALSE(layer_impl->CanHaveTilings()); | 76 EXPECT_FALSE(layer_impl->CanHaveTilings()); |
73 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); | 77 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); |
74 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); | 78 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); |
75 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); | 79 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); |
76 } | 80 } |
77 } | 81 } |
78 | 82 |
79 TEST(PictureLayerTest, SuitableForGpuRasterization) { | 83 TEST(PictureLayerTest, SuitableForGpuRasterization) { |
80 MockContentLayerClient client; | 84 MockContentLayerClient client; |
81 scoped_refptr<PictureLayer> layer = | 85 scoped_refptr<PictureLayer> layer = |
82 PictureLayer::Create(LayerSettings(), &client); | 86 PictureLayer::Create(LayerSettings(), &client); |
83 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 87 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
84 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); | 88 TestTaskGraphRunner task_graph_runner; |
89 scoped_ptr<FakeLayerTreeHost> host = | |
90 FakeLayerTreeHost::Create(&host_client, &task_graph_runner); | |
85 host->SetRootLayer(layer); | 91 host->SetRootLayer(layer); |
86 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); | 92 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); |
87 | 93 |
88 // Layer is suitable for gpu rasterization by default. | 94 // Layer is suitable for gpu rasterization by default. |
89 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); | 95 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); |
90 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); | 96 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); |
91 | 97 |
92 // Veto gpu rasterization. | 98 // Veto gpu rasterization. |
93 recording_source->SetUnsuitableForGpuRasterizationForTesting(); | 99 recording_source->SetUnsuitableForGpuRasterizationForTesting(); |
94 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); | 100 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); |
95 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); | 101 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); |
96 } | 102 } |
97 | 103 |
98 TEST(PictureLayerTest, UseTileGridSize) { | 104 TEST(PictureLayerTest, UseTileGridSize) { |
99 LayerTreeSettings settings; | 105 LayerTreeSettings settings; |
100 settings.default_tile_grid_size = gfx::Size(123, 123); | 106 settings.default_tile_grid_size = gfx::Size(123, 123); |
101 | 107 |
102 MockContentLayerClient client; | 108 MockContentLayerClient client; |
103 scoped_refptr<PictureLayer> layer = | 109 scoped_refptr<PictureLayer> layer = |
104 PictureLayer::Create(LayerSettings(), &client); | 110 PictureLayer::Create(LayerSettings(), &client); |
105 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | 111 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); |
112 TestTaskGraphRunner task_graph_runner; | |
106 scoped_ptr<FakeLayerTreeHost> host = | 113 scoped_ptr<FakeLayerTreeHost> host = |
107 FakeLayerTreeHost::Create(&host_client, settings); | 114 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings); |
108 host->SetRootLayer(layer); | 115 host->SetRootLayer(layer); |
109 | 116 |
110 // Tile-grid is set according to its setting. | 117 // Tile-grid is set according to its setting. |
111 gfx::Size size = | 118 gfx::Size size = |
112 layer->GetRecordingSourceForTesting()->GetTileGridSizeForTesting(); | 119 layer->GetRecordingSourceForTesting()->GetTileGridSizeForTesting(); |
113 EXPECT_EQ(size.width(), 123); | 120 EXPECT_EQ(size.width(), 123); |
114 EXPECT_EQ(size.height(), 123); | 121 EXPECT_EQ(size.height(), 123); |
115 } | 122 } |
116 | 123 |
117 // PicturePile uses the source frame number as a unit for measuring invalidation | 124 // PicturePile uses the source frame number as a unit for measuring invalidation |
118 // frequency. When a pile moves between compositors, the frame number increases | 125 // frequency. When a pile moves between compositors, the frame number increases |
119 // non-monotonically. This executes that code path under this scenario allowing | 126 // non-monotonically. This executes that code path under this scenario allowing |
120 // for the code to verify correctness with DCHECKs. | 127 // for the code to verify correctness with DCHECKs. |
121 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { | 128 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { |
122 LayerTreeSettings settings; | 129 LayerTreeSettings settings; |
123 settings.single_thread_proxy_scheduler = false; | 130 settings.single_thread_proxy_scheduler = false; |
131 settings.use_zero_copy = true; | |
132 settings.use_one_copy = false; | |
enne (OOO)
2015/06/15 22:58:46
Why does this test need zero copy?
danakj
2015/06/15 23:02:35
No scheduler.
| |
124 | 133 |
125 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); | 134 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); |
126 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); | 135 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); |
127 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 136 TestSharedBitmapManager shared_bitmap_manager; |
128 new TestSharedBitmapManager()); | 137 TestTaskGraphRunner task_graph_runner; |
129 | 138 |
130 MockContentLayerClient client; | 139 MockContentLayerClient client; |
131 scoped_refptr<FakePictureLayer> layer = | 140 scoped_refptr<FakePictureLayer> layer = |
132 FakePictureLayer::Create(LayerSettings(), &client); | 141 FakePictureLayer::Create(LayerSettings(), &client); |
133 | 142 |
134 LayerTreeHost::InitParams params; | 143 LayerTreeHost::InitParams params; |
135 params.client = &host_client1; | 144 params.client = &host_client1; |
136 params.shared_bitmap_manager = shared_bitmap_manager.get(); | 145 params.shared_bitmap_manager = &shared_bitmap_manager; |
137 params.settings = &settings; | 146 params.settings = &settings; |
147 params.task_graph_runner = &task_graph_runner; | |
138 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 148 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
139 scoped_ptr<LayerTreeHost> host1 = | 149 scoped_ptr<LayerTreeHost> host1 = |
140 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); | 150 LayerTreeHost::CreateSingleThreaded(&host_client1, ¶ms); |
141 host_client1.SetLayerTreeHost(host1.get()); | 151 host_client1.SetLayerTreeHost(host1.get()); |
142 | 152 |
143 params.client = &host_client2; | 153 params.client = &host_client2; |
144 scoped_ptr<LayerTreeHost> host2 = | 154 scoped_ptr<LayerTreeHost> host2 = |
145 LayerTreeHost::CreateSingleThreaded(&host_client2, ¶ms); | 155 LayerTreeHost::CreateSingleThreaded(&host_client2, ¶ms); |
146 host_client2.SetLayerTreeHost(host2.get()); | 156 host_client2.SetLayerTreeHost(host2.get()); |
147 | 157 |
(...skipping 19 matching lines...) Expand all Loading... | |
167 // Do a main frame, record the picture layers. The frame number has changed | 177 // Do a main frame, record the picture layers. The frame number has changed |
168 // non-monotonically. | 178 // non-monotonically. |
169 layer->SetNeedsDisplay(); | 179 layer->SetNeedsDisplay(); |
170 host2->Composite(base::TimeTicks::Now()); | 180 host2->Composite(base::TimeTicks::Now()); |
171 EXPECT_EQ(3, layer->update_count()); | 181 EXPECT_EQ(3, layer->update_count()); |
172 EXPECT_EQ(1, host2->source_frame_number()); | 182 EXPECT_EQ(1, host2->source_frame_number()); |
173 } | 183 } |
174 | 184 |
175 } // namespace | 185 } // namespace |
176 } // namespace cc | 186 } // namespace cc |
OLD | NEW |