Update V8 to version 4.7.24.
[chromium-blink-merge.git] / cc / trees / occlusion_tracker_perftest.cc
blob209399dce1110e643a9fa4e2bbdfc2108a81b01b
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/thread_task_runner_handle.h"
8 #include "base/time/time.h"
9 #include "cc/debug/lap_timer.h"
10 #include "cc/layers/layer_iterator.h"
11 #include "cc/layers/solid_color_layer_impl.h"
12 #include "cc/test/fake_layer_tree_host_impl_client.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_proxy.h"
15 #include "cc/test/fake_rendering_stats_instrumentation.h"
16 #include "cc/test/test_shared_bitmap_manager.h"
17 #include "cc/test/test_task_graph_runner.h"
18 #include "cc/trees/layer_tree_host_impl.h"
19 #include "cc/trees/layer_tree_impl.h"
20 #include "cc/trees/single_thread_proxy.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "testing/perf/perf_test.h"
24 namespace cc {
25 namespace {
27 static const int kTimeLimitMillis = 2000;
28 static const int kWarmupRuns = 5;
29 static const int kTimeCheckInterval = 10;
31 class OcclusionTrackerPerfTest : public testing::Test {
32 public:
33 OcclusionTrackerPerfTest()
34 : timer_(kWarmupRuns,
35 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
36 kTimeCheckInterval),
37 proxy_(base::ThreadTaskRunnerHandle::Get(), nullptr),
38 impl_(&proxy_) {}
39 void CreateHost() {
40 LayerTreeSettings settings;
41 host_impl_ = LayerTreeHostImpl::Create(settings, &client_, &proxy_, &stats_,
42 &shared_bitmap_manager_, nullptr,
43 &task_graph_runner_, 1);
44 host_impl_->InitializeRenderer(FakeOutputSurface::Create3d());
46 scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(active_tree(), 1);
47 root_layer->SetHasRenderSurface(true);
48 active_tree()->SetRootLayer(root_layer.Pass());
51 LayerTreeImpl* active_tree() { return host_impl_->active_tree(); }
53 void SetTestName(const std::string& name) { test_name_ = name; }
55 void PrintResults() {
56 CHECK(!test_name_.empty()) << "Must SetTestName() before AfterTest().";
57 perf_test::PrintResult("occlusion_tracker_time",
58 "",
59 test_name_,
60 1000 * timer_.MsPerLap(),
61 "us",
62 true);
65 protected:
66 LapTimer timer_;
67 std::string test_name_;
68 FakeLayerTreeHostImplClient client_;
69 FakeProxy proxy_;
70 DebugScopedSetImplThread impl_;
71 FakeRenderingStatsInstrumentation stats_;
72 TestSharedBitmapManager shared_bitmap_manager_;
73 TestTaskGraphRunner task_graph_runner_;
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 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 active_tree()->root_layer()->AddChild(opaque_layer.Pass());
94 bool update_lcd_text = false;
95 active_tree()->UpdateDrawProperties(update_lcd_text);
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 begin = LayerIterator::Begin(&rsll);
101 LayerIterator end = LayerIterator::End(&rsll);
103 LayerIteratorPosition 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 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 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->SetPosition(gfx::Point(i, i));
161 active_tree()->root_layer()->AddChild(opaque_layer.Pass());
164 bool update_lcd_text = false;
165 active_tree()->UpdateDrawProperties(update_lcd_text);
166 const LayerImplList& rsll = active_tree()->RenderSurfaceLayerList();
167 ASSERT_EQ(1u, rsll.size());
168 EXPECT_EQ(static_cast<size_t>(kNumOpaqueLayers),
169 rsll[0]->render_surface()->layer_list().size());
171 LayerIterator begin = LayerIterator::Begin(&rsll);
172 LayerIterator end = LayerIterator::End(&rsll);
174 // The opaque_layers add occlusion.
175 for (int i = 0; i < kNumOpaqueLayers - 1; ++i) {
176 LayerIteratorPosition pos = begin;
177 tracker.EnterLayer(pos);
178 tracker.LeaveLayer(pos);
179 ++begin;
181 LayerIteratorPosition pos = begin;
182 tracker.EnterLayer(pos);
183 tracker.LeaveLayer(pos);
185 gfx::Transform transform_to_target;
186 transform_to_target.Translate(0, 96);
188 do {
189 Occlusion occlusion =
190 tracker.GetCurrentOcclusionForLayer(transform_to_target);
191 for (int x = 0; x < viewport_rect.width(); x += 256) {
192 for (int y = 0; y < viewport_rect.height(); y += 256) {
193 gfx::Rect query_content_rect(x, y, 256, 256);
194 gfx::Rect unoccluded =
195 occlusion.GetUnoccludedContentRect(query_content_rect);
199 timer_.NextLap();
200 } while (!timer_.HasTimeLimitExpired());
202 ++begin;
203 LayerIteratorPosition next = begin;
204 EXPECT_EQ(active_tree()->root_layer(), next.current_layer);
206 ++begin;
207 EXPECT_EQ(end, begin);
209 PrintResults();
212 } // namespace
213 } // namespace cc