summaryrefslogtreecommitdiffstats
path: root/cc/layers/picture_layer_impl_perftest.cc
blob: 9e7d82bf6fc33e20e7b0f7bce47a2819c973b113 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/layers/picture_layer_impl.h"

#include "base/thread_task_runner_handle.h"
#include "cc/debug/lap_timer.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_picture_layer_impl.h"
#include "cc/test/fake_picture_pile_impl.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/tiles/tiling_set_raster_queue_all.h"
#include "cc/trees/layer_tree_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"

namespace cc {
namespace {

static const int kTimeLimitMillis = 2000;
static const int kWarmupRuns = 5;
static const int kTimeCheckInterval = 10;

void AddTiling(float scale,
               FakePictureLayerImpl* layer,
               std::vector<Tile*>* all_tiles) {
  PictureLayerTiling* tiling = layer->AddTiling(scale);

  tiling->set_resolution(HIGH_RESOLUTION);
  tiling->CreateAllTilesForTesting();
  std::vector<Tile*> tiling_tiles = tiling->AllTilesForTesting();
  std::copy(
      tiling_tiles.begin(), tiling_tiles.end(), std::back_inserter(*all_tiles));
}

class PictureLayerImplPerfTest : public testing::Test {
 public:
  PictureLayerImplPerfTest()
      : proxy_(base::ThreadTaskRunnerHandle::Get()),
        host_impl_(LayerTreeSettings(),
                   &proxy_,
                   &shared_bitmap_manager_,
                   &task_graph_runner_),
        timer_(kWarmupRuns,
               base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
               kTimeCheckInterval) {}

  void SetUp() override {
    host_impl_.InitializeRenderer(FakeOutputSurface::Create3d());
  }

  void SetupActiveTree(const gfx::Size& layer_bounds,
                       const gfx::Size& tile_size) {
    scoped_refptr<FakePicturePileImpl> pile =
        FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds);
    LayerTreeImpl* active_tree = host_impl_.active_tree();
    active_tree->DetachLayerTree();

    scoped_ptr<FakePictureLayerImpl> active_layer =
        FakePictureLayerImpl::CreateWithRasterSource(active_tree, 7, pile);
    active_layer->SetDrawsContent(true);
    active_layer->SetHasRenderSurface(true);
    active_tree->SetRootLayer(active_layer.Pass());

    active_layer_ = static_cast<FakePictureLayerImpl*>(
        host_impl_.active_tree()->LayerById(7));
  }

  void RunRasterQueueConstructAndIterateTest(const std::string& test_name,
                                             int num_tiles,
                                             const gfx::Size& viewport_size) {
    host_impl_.SetViewportSize(viewport_size);
    bool update_lcd_text = false;
    host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);

    timer_.Reset();
    do {
      int count = num_tiles;
      scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
          active_layer_->picture_layer_tiling_set(), false));
      while (count--) {
        ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
        ASSERT_TRUE(queue->Top().tile()) << "count: " << count;
        queue->Pop();
      }
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult("tiling_set_raster_queue_construct_and_iterate", "",
                           test_name, timer_.LapsPerSecond(), "runs/s", true);
  }

  void RunRasterQueueConstructTest(const std::string& test_name,
                                   const gfx::Rect& viewport) {
    host_impl_.SetViewportSize(viewport.size());
    active_layer_->PushScrollOffsetFromMainThreadAndClobberActiveValue(
        gfx::ScrollOffset(viewport.x(), viewport.y()));
    bool update_lcd_text = false;
    host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);

    timer_.Reset();
    do {
      scoped_ptr<TilingSetRasterQueueAll> queue(new TilingSetRasterQueueAll(
          active_layer_->picture_layer_tiling_set(), false));
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult("tiling_set_raster_queue_construct", "", test_name,
                           timer_.LapsPerSecond(), "runs/s", true);
  }

  void RunEvictionQueueConstructAndIterateTest(
      const std::string& test_name,
      int num_tiles,
      const gfx::Size& viewport_size) {
    host_impl_.SetViewportSize(viewport_size);
    active_layer_->MarkAllTilingsUsed();
    bool update_lcd_text = false;
    host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);

    timer_.Reset();
    do {
      int count = num_tiles;
      scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
          active_layer_->picture_layer_tiling_set()));
      while (count--) {
        ASSERT_TRUE(!queue->IsEmpty()) << "count: " << count;
        ASSERT_TRUE(queue->Top().tile()) << "count: " << count;
        queue->Pop();
      }
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult("tiling_set_eviction_queue_construct_and_iterate",
                           "", test_name, timer_.LapsPerSecond(), "runs/s",
                           true);
  }

  void RunEvictionQueueConstructTest(const std::string& test_name,
                                     const gfx::Rect& viewport) {
    host_impl_.SetViewportSize(viewport.size());
    active_layer_->PushScrollOffsetFromMainThreadAndClobberActiveValue(
        gfx::ScrollOffset(viewport.x(), viewport.y()));
    active_layer_->MarkAllTilingsUsed();
    bool update_lcd_text = false;
    host_impl_.active_tree()->UpdateDrawProperties(update_lcd_text);

    timer_.Reset();
    do {
      scoped_ptr<TilingSetEvictionQueue> queue(new TilingSetEvictionQueue(
          active_layer_->picture_layer_tiling_set()));
      timer_.NextLap();
    } while (!timer_.HasTimeLimitExpired());

    perf_test::PrintResult("tiling_set_eviction_queue_construct", "", test_name,
                           timer_.LapsPerSecond(), "runs/s", true);
  }

 protected:
  TestSharedBitmapManager shared_bitmap_manager_;
  TestTaskGraphRunner task_graph_runner_;
  FakeImplProxy proxy_;
  FakeLayerTreeHostImpl host_impl_;
  FakePictureLayerImpl* active_layer_;
  LapTimer timer_;

 private:
  DISALLOW_COPY_AND_ASSIGN(PictureLayerImplPerfTest);
};

TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstructAndIterate) {
  SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));

  float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;

  active_layer_->AddTiling(low_res_factor);
  active_layer_->AddTiling(0.3f);
  active_layer_->AddTiling(0.7f);
  active_layer_->AddTiling(1.0f);
  active_layer_->AddTiling(2.0f);

  RunRasterQueueConstructAndIterateTest("32_100x100", 32, gfx::Size(100, 100));
  RunRasterQueueConstructAndIterateTest("32_500x500", 32, gfx::Size(500, 500));
  RunRasterQueueConstructAndIterateTest("64_100x100", 64, gfx::Size(100, 100));
  RunRasterQueueConstructAndIterateTest("64_500x500", 64, gfx::Size(500, 500));
}

TEST_F(PictureLayerImplPerfTest, TilingSetRasterQueueConstruct) {
  SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));

  float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;

  active_layer_->AddTiling(low_res_factor);
  active_layer_->AddTiling(0.3f);
  active_layer_->AddTiling(0.7f);
  active_layer_->AddTiling(1.0f);
  active_layer_->AddTiling(2.0f);

  RunRasterQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
  RunRasterQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
  RunRasterQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
}

TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstructAndIterate) {
  SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));

  float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;

  std::vector<Tile*> all_tiles;
  AddTiling(low_res_factor, active_layer_, &all_tiles);
  AddTiling(0.3f, active_layer_, &all_tiles);
  AddTiling(0.7f, active_layer_, &all_tiles);
  AddTiling(1.0f, active_layer_, &all_tiles);
  AddTiling(2.0f, active_layer_, &all_tiles);

  ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
  host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);

  RunEvictionQueueConstructAndIterateTest(
      "32_100x100", 32, gfx::Size(100, 100));
  RunEvictionQueueConstructAndIterateTest(
      "32_500x500", 32, gfx::Size(500, 500));
  RunEvictionQueueConstructAndIterateTest(
      "64_100x100", 64, gfx::Size(100, 100));
  RunEvictionQueueConstructAndIterateTest(
      "64_500x500", 64, gfx::Size(500, 500));
}

TEST_F(PictureLayerImplPerfTest, TilingSetEvictionQueueConstruct) {
  SetupActiveTree(gfx::Size(10000, 10000), gfx::Size(256, 256));

  float low_res_factor = host_impl_.settings().low_res_contents_scale_factor;

  std::vector<Tile*> all_tiles;
  AddTiling(low_res_factor, active_layer_, &all_tiles);
  AddTiling(0.3f, active_layer_, &all_tiles);
  AddTiling(0.7f, active_layer_, &all_tiles);
  AddTiling(1.0f, active_layer_, &all_tiles);
  AddTiling(2.0f, active_layer_, &all_tiles);

  ASSERT_TRUE(host_impl_.tile_manager() != nullptr);
  host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(all_tiles);

  RunEvictionQueueConstructTest("0_0_100x100", gfx::Rect(0, 0, 100, 100));
  RunEvictionQueueConstructTest("5000_0_100x100", gfx::Rect(5000, 0, 100, 100));
  RunEvictionQueueConstructTest("9999_0_100x100", gfx::Rect(9999, 0, 100, 100));
}

}  // namespace
}  // namespace cc