Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / cc / layers / picture_layer_impl_perftest.cc
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.
4
5 #include "cc/layers/picture_layer_impl.h"
6
7 #include "cc/debug/lap_timer.h"
8 #include "cc/test/fake_impl_proxy.h"
9 #include "cc/test/fake_layer_tree_host_impl.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/test/fake_picture_layer_impl.h"
12 #include "cc/test/fake_picture_pile_impl.h"
13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/layer_tree_impl.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/perf/perf_test.h"
18
19 namespace cc {
20 namespace {
21
22 static const int kTimeLimitMillis = 2000;
23 static const int kWarmupRuns = 5;
24 static const int kTimeCheckInterval = 10;
25
26 void AddTiling(float scale,
27                FakePictureLayerImpl* layer,
28                std::vector<Tile*>* all_tiles) {
29   PictureLayerTiling* tiling = layer->AddTiling(scale);
30
31   tiling->CreateAllTilesForTesting();
32   std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
33   std::copy(
34       tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
35 }
36
37 class PictureLayerImplPerfTest : public testing::Test {
38  public:
39   PictureLayerImplPerfTest()
40       : proxy_(base::MessageLoopProxy::current()),
41         host_impl_(ImplSidePaintingSettings(),
42                    &proxy_,
43                    &shared_bitmap_manager_),
44         timer_(kWarmupRuns,
45                base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
46                kTimeCheckInterval) {}
47
48   virtual void SetUp() OVERRIDE {
49     host_impl_.InitializeRenderer(
50         FakeOutputSurface::Create3d().PassAs<OutputSurface>());
51   }
52
53   void SetupPendingTree(const gfx::Size& layer_bounds,
54                         const gfx::Size& tile_size) {
55     scoped_refptr<FakePicturePileImpl> pile =
56         FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
57     host_impl_.CreatePendingTree();
58     LayerTreeImpl* pending_tree = host_impl_.pending_tree();
59     pending_tree->DetachLayerTree();
60
61     scoped_ptr<FakePictureLayerImpl> pending_layer =
62         FakePictureLayerImpl::CreateWithPile(pending_tree, 7, pile);
63     pending_layer->SetDrawsContent(true);
64     pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
65
66     pending_layer_ = static_cast<FakePictureLayerImpl*>(
67         host_impl_.pending_tree()->LayerById(7));
68     pending_layer_->DoPostCommitInitializationIfNeeded();
69   }
70
71   void RunRasterIteratorConstructAndIterateTest(
72       const std::string& test_name,
73       int num_tiles,
74       const gfx::Size& viewport_size) {
75     host_impl_.SetViewportSize(viewport_size);
76     host_impl_.pending_tree()->UpdateDrawProperties();
77
78     timer_.Reset();
79     do {
80       int count = num_tiles;
81       PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
82       while (count--) {
83         ASSERT_TRUE(it) << "count: " << count;
84         ASSERT_TRUE(*it != NULL) << "count: " << count;
85         ++it;
86       }
87       timer_.NextLap();
88     } while (!timer_.HasTimeLimitExpired());
89
90     perf_test::PrintResult("layer_raster_tile_iterator_construct_and_iterate",
91                            "",
92                            test_name,
93                            timer_.LapsPerSecond(),
94                            "runs/s",
95                            true);
96   }
97
98   void RunRasterIteratorConstructTest(const std::string& test_name,
99                                       const gfx::Rect& viewport) {
100     host_impl_.SetViewportSize(viewport.size());
101     pending_layer_->SetScrollOffset(gfx::Vector2d(viewport.x(), viewport.y()));
102     host_impl_.pending_tree()->UpdateDrawProperties();
103
104     timer_.Reset();
105     do {
106       PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
107       timer_.NextLap();
108     } while (!timer_.HasTimeLimitExpired());
109
110     perf_test::PrintResult("layer_raster_tile_iterator_construct",
111                            "",
112                            test_name,
113                            timer_.LapsPerSecond(),
114                            "runs/s",
115                            true);
116   }
117
118   void RunEvictionIteratorConstructAndIterateTest(
119       const std::string& test_name,
120       int num_tiles,
121       const gfx::Size& viewport_size) {
122     host_impl_.SetViewportSize(viewport_size);
123     host_impl_.pending_tree()->UpdateDrawProperties();
124
125     TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
126                                  SMOOTHNESS_TAKES_PRIORITY,
127                                  NEW_CONTENT_TAKES_PRIORITY};
128     int priority_count = 0;
129     timer_.Reset();
130     do {
131       int count = num_tiles;
132       PictureLayerImpl::LayerEvictionTileIterator it(
133           pending_layer_, priorities[priority_count]);
134       while (count--) {
135         ASSERT_TRUE(it) << "count: " << count;
136         ASSERT_TRUE(*it != NULL) << "count: " << count;
137         ++it;
138       }
139       priority_count = (priority_count + 1) % arraysize(priorities);
140       timer_.NextLap();
141     } while (!timer_.HasTimeLimitExpired());
142
143     perf_test::PrintResult("layer_eviction_tile_iterator_construct_and_iterate",
144                            "",
145                            test_name,
146                            timer_.LapsPerSecond(),
147                            "runs/s",
148                            true);
149   }
150
151   void RunEvictionIteratorConstructTest(const std::string& test_name,
152                                         const gfx::Rect& viewport) {
153     host_impl_.SetViewportSize(viewport.size());
154     pending_layer_->SetScrollOffset(gfx::Vector2d(viewport.x(), viewport.y()));
155     host_impl_.pending_tree()->UpdateDrawProperties();
156
157     TreePriority priorities[] = {SAME_PRIORITY_FOR_BOTH_TREES,
158                                  SMOOTHNESS_TAKES_PRIORITY,
159                                  NEW_CONTENT_TAKES_PRIORITY};
160     int priority_count = 0;
161     timer_.Reset();
162     do {
163       PictureLayerImpl::LayerEvictionTileIterator it(
164           pending_layer_, priorities[priority_count]);
165       priority_count = (priority_count + 1) % arraysize(priorities);
166       timer_.NextLap();
167     } while (!timer_.HasTimeLimitExpired());
168
169     perf_test::PrintResult("layer_eviction_tile_iterator_construct",
170                            "",
171                            test_name,
172                            timer_.LapsPerSecond(),
173                            "runs/s",
174                            true);
175   }
176
177  protected:
178   TestSharedBitmapManager shared_bitmap_manager_;
179   FakeImplProxy proxy_;
180   FakeLayerTreeHostImpl host_impl_;
181   FakePictureLayerImpl* pending_layer_;
182   LapTimer timer_;
183
184  private:
185   DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
186 };
187
188 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIteratorConstructAndIterate) {
189   SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
190
191   float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
192
193   pending_layer_->AddTiling(low_res_factor);
194   pending_layer_->AddTiling(0.3f);
195   pending_layer_->AddTiling(0.7f);
196   pending_layer_->AddTiling(1.0f);
197   pending_layer_->AddTiling(2.0f);
198
199   RunRasterIteratorConstructAndIterateTest(
200       "32_100x100", 32, gfx::Size(100, 100));
201   RunRasterIteratorConstructAndIterateTest(
202       "32_500x500", 32, gfx::Size(500, 500));
203   RunRasterIteratorConstructAndIterateTest(
204       "64_100x100", 64, gfx::Size(100, 100));
205   RunRasterIteratorConstructAndIterateTest(
206       "64_500x500", 64, gfx::Size(500, 500));
207 }
208
209 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIteratorConstruct) {
210   SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
211
212   float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
213
214   pending_layer_->AddTiling(low_res_factor);
215   pending_layer_->AddTiling(0.3f);
216   pending_layer_->AddTiling(0.7f);
217   pending_layer_->AddTiling(1.0f);
218   pending_layer_->AddTiling(2.0f);
219
220   RunRasterIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
221   RunRasterIteratorConstructTest("5000_0_100x100",
222                                  gfx::Rect(5000, 0, 100, 100));
223   RunRasterIteratorConstructTest("9999_0_100x100",
224                                  gfx::Rect(9999, 0, 100, 100));
225 }
226
227 TEST_F(PictureLayerImplPerfTest, LayerEvictionTileIteratorConstructAndIterate) {
228   SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
229
230   float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
231
232   std::vector<Tile*> all_tiles;
233   AddTiling(low_res_factor, pending_layer_, &all_tiles);
234   AddTiling(0.3f, pending_layer_, &all_tiles);
235   AddTiling(0.7f, pending_layer_, &all_tiles);
236   AddTiling(1.0f, pending_layer_, &all_tiles);
237   AddTiling(2.0f, pending_layer_, &all_tiles);
238
239   ASSERT_TRUE(host_impl_.tile_manager() != NULL);
240   host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
241
242   RunEvictionIteratorConstructAndIterateTest(
243       "32_100x100", 32, gfx::Size(100, 100));
244   RunEvictionIteratorConstructAndIterateTest(
245       "32_500x500", 32, gfx::Size(500, 500));
246   RunEvictionIteratorConstructAndIterateTest(
247       "64_100x100", 64, gfx::Size(100, 100));
248   RunEvictionIteratorConstructAndIterateTest(
249       "64_500x500", 64, gfx::Size(500, 500));
250 }
251
252 TEST_F(PictureLayerImplPerfTest, LayerEvictionTileIteratorConstruct) {
253   SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
254
255   float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
256
257   std::vector<Tile*> all_tiles;
258   AddTiling(low_res_factor, pending_layer_, &all_tiles);
259   AddTiling(0.3f, pending_layer_, &all_tiles);
260   AddTiling(0.7f, pending_layer_, &all_tiles);
261   AddTiling(1.0f, pending_layer_, &all_tiles);
262   AddTiling(2.0f, pending_layer_, &all_tiles);
263
264   ASSERT_TRUE(host_impl_.tile_manager() != NULL);
265   host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);
266
267   RunEvictionIteratorConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
268   RunEvictionIteratorConstructTest("5000_0_100x100",
269                                    gfx::Rect(5000, 0, 100, 100));
270   RunEvictionIteratorConstructTest("9999_0_100x100",
271                                    gfx::Rect(9999, 0, 100, 100));
272 }
273
274 }  // namespace
275 }  // namespace cc