Upstream version 7.36.149.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/test/fake_impl_proxy.h"
8 #include "cc/test/fake_layer_tree_host_impl.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_picture_layer_impl.h"
11 #include "cc/test/fake_picture_pile_impl.h"
12 #include "cc/test/impl_side_painting_settings.h"
13 #include "cc/test/lap_timer.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 class PictureLayerImplPerfTest : public testing::Test {
27  public:
28   PictureLayerImplPerfTest()
29       : proxy_(base::MessageLoopProxy::current()),
30         host_impl_(ImplSidePaintingSettings(),
31                    &proxy_,
32                    &shared_bitmap_manager_),
33         timer_(kWarmupRuns,
34                base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
35                kTimeCheckInterval) {}
36
37   virtual void SetUp() OVERRIDE {
38     host_impl_.InitializeRenderer(
39         FakeOutputSurface::Create3d().PassAs<OutputSurface>());
40   }
41
42   void SetupPendingTree(const gfx::Size& layer_bounds,
43                         const gfx::Size& tile_size) {
44     scoped_refptr<FakePicturePileImpl> pile =
45         FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
46     host_impl_.CreatePendingTree();
47     LayerTreeImpl* pending_tree = host_impl_.pending_tree();
48     pending_tree->DetachLayerTree();
49
50     scoped_ptr<FakePictureLayerImpl> pending_layer =
51         FakePictureLayerImpl::CreateWithPile(pending_tree, 7, pile);
52     pending_layer->SetDrawsContent(true);
53     pending_tree->SetRootLayer(pending_layer.PassAs<LayerImpl>());
54
55     pending_layer_ = static_cast<FakePictureLayerImpl*>(
56         host_impl_.pending_tree()->LayerById(7));
57     pending_layer_->DoPostCommitInitializationIfNeeded();
58   }
59
60   void RunLayerRasterTileIteratorTest(const std::string& test_name,
61                                       int num_tiles,
62                                       const gfx::Size& viewport_size) {
63     host_impl_.SetViewportSize(viewport_size);
64     host_impl_.pending_tree()->UpdateDrawProperties();
65
66     timer_.Reset();
67     do {
68       int count = num_tiles;
69       for (PictureLayerImpl::LayerRasterTileIterator it(pending_layer_, false);
70            it && count;
71            ++it) {
72         --count;
73       }
74       timer_.NextLap();
75     } while (!timer_.HasTimeLimitExpired());
76
77     perf_test::PrintResult("layer_raster_tile_iterator",
78                            "",
79                            test_name,
80                            timer_.LapsPerSecond(),
81                            "runs/s",
82                            true);
83   }
84
85  protected:
86   TestSharedBitmapManager shared_bitmap_manager_;
87   FakeImplProxy proxy_;
88   FakeLayerTreeHostImpl host_impl_;
89   FakePictureLayerImpl* pending_layer_;
90   LapTimer timer_;
91
92  private:
93   DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
94 };
95
96 TEST_F(PictureLayerImplPerfTest, LayerRasterTileIterator) {
97   SetupPendingTree(gfx::Size(10000, 10000), gfx::Size(256, 256));
98
99   float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;
100
101   pending_layer_->AddTiling(low_res_factor);
102   pending_layer_->AddTiling(0.3f);
103   pending_layer_->AddTiling(0.7f);
104   pending_layer_->AddTiling(1.0f);
105   pending_layer_->AddTiling(2.0f);
106
107   RunLayerRasterTileIteratorTest("32_100x100", 32, gfx::Size(100, 100));
108   RunLayerRasterTileIteratorTest("32_500x500", 32, gfx::Size(500, 500));
109   RunLayerRasterTileIteratorTest("64_100x100", 64, gfx::Size(100, 100));
110   RunLayerRasterTileIteratorTest("64_500x500", 64, gfx::Size(500, 500));
111 }
112
113 }  // namespace
114 }  // namespace cc