OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/trees/occlusion_tracker.h" | 5 #include "cc/trees/occlusion_tracker.h" |
6 | 6 |
7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
8 #include "cc/layers/layer_iterator.h" | 8 #include "cc/layers/layer_iterator.h" |
9 #include "cc/layers/solid_color_layer_impl.h" | 9 #include "cc/layers/solid_color_layer_impl.h" |
10 #include "cc/test/fake_layer_tree_host_impl_client.h" | 10 #include "cc/test/fake_layer_tree_host_impl_client.h" |
11 #include "cc/test/fake_output_surface.h" | 11 #include "cc/test/fake_output_surface.h" |
12 #include "cc/test/fake_proxy.h" | 12 #include "cc/test/fake_proxy.h" |
13 #include "cc/test/fake_rendering_stats_instrumentation.h" | 13 #include "cc/test/fake_rendering_stats_instrumentation.h" |
14 #include "cc/test/lap_timer.h" | 14 #include "cc/test/lap_timer.h" |
15 #include "cc/trees/layer_tree_host_impl.h" | 15 #include "cc/trees/layer_tree_host_impl.h" |
16 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
| 17 #include "cc/trees/single_thread_proxy.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "testing/perf/perf_test.h" | 19 #include "testing/perf/perf_test.h" |
19 | 20 |
20 namespace cc { | 21 namespace cc { |
21 namespace { | 22 namespace { |
22 | 23 |
23 static const int kTimeLimitMillis = 2000; | 24 static const int kTimeLimitMillis = 2000; |
24 static const int kWarmupRuns = 5; | 25 static const int kWarmupRuns = 5; |
25 static const int kTimeCheckInterval = 10; | 26 static const int kTimeCheckInterval = 10; |
26 | 27 |
27 class OcclusionTrackerPerfTest : public testing::Test { | 28 class OcclusionTrackerPerfTest : public testing::Test { |
28 public: | 29 public: |
29 OcclusionTrackerPerfTest() | 30 OcclusionTrackerPerfTest() |
30 : timer_(kWarmupRuns, | 31 : timer_(kWarmupRuns, |
31 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 32 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
32 kTimeCheckInterval) {} | 33 kTimeCheckInterval), |
| 34 impl_(&proxy_) {} |
33 void CreateHost() { | 35 void CreateHost() { |
34 LayerTreeSettings settings; | 36 LayerTreeSettings settings; |
35 host_impl_ = LayerTreeHostImpl::Create( | 37 host_impl_ = LayerTreeHostImpl::Create( |
36 settings, &client_, &proxy_, &stats_, NULL, 1); | 38 settings, &client_, &proxy_, &stats_, NULL, 1); |
37 host_impl_->InitializeRenderer( | 39 host_impl_->InitializeRenderer( |
38 FakeOutputSurface::Create3d().PassAs<OutputSurface>()); | 40 FakeOutputSurface::Create3d().PassAs<OutputSurface>()); |
39 | 41 |
40 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(active_tree(), 1); | 42 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(active_tree(), 1); |
41 active_tree()->SetRootLayer(root_layer.Pass()); | 43 active_tree()->SetRootLayer(root_layer.Pass()); |
42 } | 44 } |
(...skipping 10 matching lines...) Expand all Loading... |
53 1000 * timer_.MsPerLap(), | 55 1000 * timer_.MsPerLap(), |
54 "us", | 56 "us", |
55 true); | 57 true); |
56 } | 58 } |
57 | 59 |
58 protected: | 60 protected: |
59 LapTimer timer_; | 61 LapTimer timer_; |
60 std::string test_name_; | 62 std::string test_name_; |
61 FakeLayerTreeHostImplClient client_; | 63 FakeLayerTreeHostImplClient client_; |
62 FakeProxy proxy_; | 64 FakeProxy proxy_; |
| 65 DebugScopedSetImplThread impl_; |
63 FakeRenderingStatsInstrumentation stats_; | 66 FakeRenderingStatsInstrumentation stats_; |
64 scoped_ptr<LayerTreeHostImpl> host_impl_; | 67 scoped_ptr<LayerTreeHostImpl> host_impl_; |
65 }; | 68 }; |
66 | 69 |
67 // Simulates a page with several large, transformed and animated layers. | |
68 TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_FullyOccluded) { | 70 TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_FullyOccluded) { |
69 SetTestName("unoccluded_content_rect_fully_occluded"); | 71 SetTestName("unoccluded_content_rect_fully_occluded"); |
70 | 72 |
71 gfx::Rect viewport_rect(768, 1038); | 73 gfx::Rect viewport_rect(768, 1038); |
72 OcclusionTrackerBase<LayerImpl, LayerImpl::RenderSurfaceType> tracker( | 74 OcclusionTrackerBase<LayerImpl, LayerImpl::RenderSurfaceType> tracker( |
73 viewport_rect, false); | 75 viewport_rect, false); |
74 | 76 |
75 CreateHost(); | 77 CreateHost(); |
76 host_impl_->SetViewportSize(viewport_rect.size()); | 78 host_impl_->SetViewportSize(viewport_rect.size()); |
77 | 79 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 ++begin; | 128 ++begin; |
127 LayerIteratorPosition<LayerImpl> next = begin; | 129 LayerIteratorPosition<LayerImpl> next = begin; |
128 EXPECT_EQ(active_tree()->root_layer(), next.current_layer); | 130 EXPECT_EQ(active_tree()->root_layer(), next.current_layer); |
129 | 131 |
130 ++begin; | 132 ++begin; |
131 EXPECT_EQ(end, begin); | 133 EXPECT_EQ(end, begin); |
132 | 134 |
133 PrintResults(); | 135 PrintResults(); |
134 } | 136 } |
135 | 137 |
| 138 TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_10OpaqueLayers) { |
| 139 static const int kNumOpaqueLayers = 10; |
| 140 SetTestName("unoccluded_content_rect_10_opaque_layers"); |
| 141 |
| 142 gfx::Rect viewport_rect(768, 1038); |
| 143 OcclusionTrackerBase<LayerImpl, LayerImpl::RenderSurfaceType> tracker( |
| 144 viewport_rect, false); |
| 145 |
| 146 CreateHost(); |
| 147 host_impl_->SetViewportSize(viewport_rect.size()); |
| 148 |
| 149 for (int i = 0; i < kNumOpaqueLayers; ++i) { |
| 150 scoped_ptr<SolidColorLayerImpl> opaque_layer = |
| 151 SolidColorLayerImpl::Create(active_tree(), 2 + i); |
| 152 opaque_layer->SetBackgroundColor(SK_ColorRED); |
| 153 opaque_layer->SetContentsOpaque(true); |
| 154 opaque_layer->SetDrawsContent(true); |
| 155 opaque_layer->SetBounds( |
| 156 gfx::Size(viewport_rect.width() / 2, viewport_rect.height() / 2)); |
| 157 opaque_layer->SetContentBounds( |
| 158 gfx::Size(viewport_rect.width() / 2, viewport_rect.height() / 2)); |
| 159 opaque_layer->SetPosition(gfx::Point(i, i)); |
| 160 active_tree()->root_layer()->AddChild(opaque_layer.PassAs<LayerImpl>()); |
| 161 } |
| 162 |
| 163 active_tree()->UpdateDrawProperties(); |
| 164 const LayerImplList& rsll = active_tree()->RenderSurfaceLayerList(); |
| 165 ASSERT_EQ(1u, rsll.size()); |
| 166 EXPECT_EQ(static_cast<size_t>(kNumOpaqueLayers), |
| 167 rsll[0]->render_surface()->layer_list().size()); |
| 168 |
| 169 LayerIterator<LayerImpl> begin = LayerIterator<LayerImpl>::Begin(&rsll); |
| 170 LayerIterator<LayerImpl> end = LayerIterator<LayerImpl>::End(&rsll); |
| 171 |
| 172 // The opaque_layers add occlusion. |
| 173 for (int i = 0; i < kNumOpaqueLayers - 1; ++i) { |
| 174 LayerIteratorPosition<LayerImpl> pos = begin; |
| 175 tracker.EnterLayer(pos); |
| 176 tracker.LeaveLayer(pos); |
| 177 ++begin; |
| 178 } |
| 179 LayerIteratorPosition<LayerImpl> pos = begin; |
| 180 tracker.EnterLayer(pos); |
| 181 tracker.LeaveLayer(pos); |
| 182 |
| 183 gfx::Transform transform_to_target; |
| 184 transform_to_target.Translate(0, 96); |
| 185 bool impl_draw_transform_is_unknown = false; |
| 186 |
| 187 do { |
| 188 for (int x = 0; x < viewport_rect.width(); x += 256) { |
| 189 for (int y = 0; y < viewport_rect.height(); y += 256) { |
| 190 gfx::Rect query_content_rect(x, y, 256, 256); |
| 191 gfx::Rect unoccluded = |
| 192 tracker.UnoccludedContentRect(pos.target_render_surface_layer, |
| 193 query_content_rect, |
| 194 transform_to_target, |
| 195 impl_draw_transform_is_unknown); |
| 196 } |
| 197 } |
| 198 |
| 199 timer_.NextLap(); |
| 200 } while (!timer_.HasTimeLimitExpired()); |
| 201 |
| 202 ++begin; |
| 203 LayerIteratorPosition<LayerImpl> next = begin; |
| 204 EXPECT_EQ(active_tree()->root_layer(), next.current_layer); |
| 205 |
| 206 ++begin; |
| 207 EXPECT_EQ(end, begin); |
| 208 |
| 209 PrintResults(); |
| 210 } |
| 211 |
136 } // namespace | 212 } // namespace |
137 } // namespace cc | 213 } // namespace cc |
OLD | NEW |