Update Smart lock strings in chrome://settings.
[chromium-blink-merge.git] / cc / trees / occlusion_tracker_perftest.cc
blob7346f2594dea8d7862b68651ae09cd6dc9d1803c
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
3 // found in the LICENSE file.
5 #include "cc/trees/occlusion_tracker.h"
7 #include "base/time/time.h"
8 #include "cc/debug/lap_timer.h"
9 #include "cc/layers/layer_iterator.h"
10 #include "cc/layers/solid_color_layer_impl.h"
11 #include "cc/test/fake_layer_tree_host_impl_client.h"
12 #include "cc/test/fake_output_surface.h"
13 #include "cc/test/fake_proxy.h"
14 #include "cc/test/fake_rendering_stats_instrumentation.h"
15 #include "cc/test/test_shared_bitmap_manager.h"
16 #include "cc/trees/layer_tree_host_impl.h"
17 #include "cc/trees/layer_tree_impl.h"
18 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "testing/perf/perf_test.h"
22 namespace cc {
23 namespace {
25 static const int kTimeLimitMillis = 2000;
26 static const int kWarmupRuns = 5;
27 static const int kTimeCheckInterval = 10;
29 class OcclusionTrackerPerfTest : public testing::Test {
30 public:
31 OcclusionTrackerPerfTest()
32 : timer_(kWarmupRuns,
33 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
34 kTimeCheckInterval),
35 impl_(&proxy_) {}
36 void CreateHost() {
37 LayerTreeSettings settings;
38 shared_bitmap_manager_.reset(new TestSharedBitmapManager());
39 host_impl_ = LayerTreeHostImpl::Create(settings,
40 &client_,
41 &proxy_,
42 &stats_,
43 shared_bitmap_manager_.get(),
44 NULL,
45 1);
46 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
48 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(active_tree(), 1);
49 active_tree()->SetRootLayer(root_layer.Pass());
52 LayerTreeImpl* active_tree() { return host_impl_->active_tree(); }
54 void SetTestName(const std::string& name) { test_name_ = name; }
56 void PrintResults() {
57 CHECK(!test_name_.empty()) << "Must SetTestName() before AfterTest().";
58 perf_test::PrintResult("occlusion_tracker_time",
59 "",
60 test_name_,
61 1000 * timer_.MsPerLap(),
62 "us",
63 true);
66 protected:
67 LapTimer timer_;
68 std::string test_name_;
69 FakeLayerTreeHostImplClient client_;
70 FakeProxy proxy_;
71 DebugScopedSetImplThread impl_;
72 FakeRenderingStatsInstrumentation stats_;
73 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_;
74 scoped_ptr<LayerTreeHostImpl> host_impl_;
77 TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_FullyOccluded) {
78 SetTestName("unoccluded_content_rect_fully_occluded");
80 gfx::Rect viewport_rect(768, 1038);
81 OcclusionTracker<LayerImpl> tracker(viewport_rect);
83 CreateHost();
84 host_impl_->SetViewportSize(viewport_rect.size());
86 scoped_ptr<SolidColorLayerImpl> opaque_layer =
87 SolidColorLayerImpl::Create(active_tree(), 2);
88 opaque_layer->SetBackgroundColor(SK_ColorRED);
89 opaque_layer->SetContentsOpaque(true);
90 opaque_layer->SetDrawsContent(true);
91 opaque_layer->SetBounds(viewport_rect.size());
92 opaque_layer->SetContentBounds(viewport_rect.size());
93 active_tree()->root_layer()->AddChild(opaque_layer.Pass());
95 active_tree()->UpdateDrawProperties();
96 const LayerImplList& rsll = active_tree()->RenderSurfaceLayerList();
97 ASSERT_EQ(1u, rsll.size());
98 EXPECT_EQ(1u, rsll[0]->render_surface()->layer_list().size());
100 LayerIterator<LayerImpl> begin = LayerIterator<LayerImpl>::Begin(&rsll);
101 LayerIterator<LayerImpl> end = LayerIterator<LayerImpl>::End(&rsll);
103 LayerIteratorPosition<LayerImpl> pos = begin;
105 // The opaque_layer adds occlusion over the whole viewport.
106 tracker.EnterLayer(pos);
107 tracker.LeaveLayer(pos);
109 gfx::Transform transform_to_target;
110 transform_to_target.Translate(0, 96);
112 do {
113 Occlusion occlusion =
114 tracker.GetCurrentOcclusionForLayer(transform_to_target);
115 for (int x = 0; x < viewport_rect.width(); x += 256) {
116 for (int y = 0; y < viewport_rect.height(); y += 256) {
117 gfx::Rect query_content_rect(x, y, 256, 256);
118 gfx::Rect unoccluded =
119 occlusion.GetUnoccludedContentRect(query_content_rect);
120 // Sanity test that we're not hitting early outs.
121 bool expect_empty =
122 query_content_rect.right() <= viewport_rect.width() &&
123 query_content_rect.bottom() + 96 <= viewport_rect.height();
124 CHECK_EQ(expect_empty, unoccluded.IsEmpty())
125 << query_content_rect.ToString();
129 timer_.NextLap();
130 } while (!timer_.HasTimeLimitExpired());
132 ++begin;
133 LayerIteratorPosition<LayerImpl> next = begin;
134 EXPECT_EQ(active_tree()->root_layer(), next.current_layer);
136 ++begin;
137 EXPECT_EQ(end, begin);
139 PrintResults();
142 TEST_F(OcclusionTrackerPerfTest, UnoccludedContentRect_10OpaqueLayers) {
143 static const int kNumOpaqueLayers = 10;
144 SetTestName("unoccluded_content_rect_10_opaque_layers");
146 gfx::Rect viewport_rect(768, 1038);
147 OcclusionTracker<LayerImpl> tracker(viewport_rect);
149 CreateHost();
150 host_impl_->SetViewportSize(viewport_rect.size());
152 for (int i = 0; i < kNumOpaqueLayers; ++i) {
153 scoped_ptr<SolidColorLayerImpl> opaque_layer =
154 SolidColorLayerImpl::Create(active_tree(), 2 + i);
155 opaque_layer->SetBackgroundColor(SK_ColorRED);
156 opaque_layer->SetContentsOpaque(true);
157 opaque_layer->SetDrawsContent(true);
158 opaque_layer->SetBounds(
159 gfx::Size(viewport_rect.width() / 2, viewport_rect.height() / 2));
160 opaque_layer->SetContentBounds(
161 gfx::Size(viewport_rect.width() / 2, viewport_rect.height() / 2));
162 opaque_layer->SetPosition(gfx::Point(i, i));
163 active_tree()->root_layer()->AddChild(opaque_layer.Pass());
166 active_tree()->UpdateDrawProperties();
167 const LayerImplList& rsll = active_tree()->RenderSurfaceLayerList();
168 ASSERT_EQ(1u, rsll.size());
169 EXPECT_EQ(static_cast<size_t>(kNumOpaqueLayers),
170 rsll[0]->render_surface()->layer_list().size());
172 LayerIterator<LayerImpl> begin = LayerIterator<LayerImpl>::Begin(&rsll);
173 LayerIterator<LayerImpl> end = LayerIterator<LayerImpl>::End(&rsll);
175 // The opaque_layers add occlusion.
176 for (int i = 0; i < kNumOpaqueLayers - 1; ++i) {
177 LayerIteratorPosition<LayerImpl> pos = begin;
178 tracker.EnterLayer(pos);
179 tracker.LeaveLayer(pos);
180 ++begin;
182 LayerIteratorPosition<LayerImpl> pos = begin;
183 tracker.EnterLayer(pos);
184 tracker.LeaveLayer(pos);
186 gfx::Transform transform_to_target;
187 transform_to_target.Translate(0, 96);
189 do {
190 Occlusion occlusion =
191 tracker.GetCurrentOcclusionForLayer(transform_to_target);
192 for (int x = 0; x < viewport_rect.width(); x += 256) {
193 for (int y = 0; y < viewport_rect.height(); y += 256) {
194 gfx::Rect query_content_rect(x, y, 256, 256);
195 gfx::Rect unoccluded =
196 occlusion.GetUnoccludedContentRect(query_content_rect);
200 timer_.NextLap();
201 } while (!timer_.HasTimeLimitExpired());
203 ++begin;
204 LayerIteratorPosition<LayerImpl> next = begin;
205 EXPECT_EQ(active_tree()->root_layer(), next.current_layer);
207 ++begin;
208 EXPECT_EQ(end, begin);
210 PrintResults();
213 } // namespace
214 } // namespace cc