summaryrefslogtreecommitdiffstats
path: root/cc/layers/layer_perftest.cc
blob: 9f4913ae3fb9d3912616a411a1a56126aa889ede (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
// Copyright 2013 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/layer.h"

#include "cc/debug/lap_timer.h"
#include "cc/resources/layer_painter.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_layer_tree_host_impl.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"

namespace cc {
namespace {

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

class MockLayerPainter : public LayerPainter {
 public:
  virtual void Paint(SkCanvas* canvas, const gfx::Rect& content_rect) OVERRIDE {
  }
};


class LayerPerfTest : public testing::Test {
 public:
  LayerPerfTest()
      : host_impl_(&proxy_, &shared_bitmap_manager_),
        fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
        timer_(kWarmupRuns,
               base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
               kTimeCheckInterval) {}

 protected:
  virtual void SetUp() OVERRIDE {
    layer_tree_host_ = FakeLayerTreeHost::Create();
    layer_tree_host_->InitializeSingleThreaded(
        &fake_client_, base::MessageLoopProxy::current());
  }

  virtual void TearDown() OVERRIDE {
    layer_tree_host_->SetRootLayer(NULL);
    layer_tree_host_.reset();
  }

  FakeImplProxy proxy_;
  TestSharedBitmapManager shared_bitmap_manager_;
  FakeLayerTreeHostImpl host_impl_;

  FakeLayerTreeHostClient fake_client_;
  scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
  LapTimer timer_;
};

TEST_F(LayerPerfTest, PushPropertiesTo) {
  scoped_refptr<Layer> test_layer = Layer::Create();
  scoped_ptr<LayerImpl> impl_layer =
      LayerImpl::Create(host_impl_.active_tree(), 1);

  layer_tree_host_->SetRootLayer(test_layer);

  float transform_origin_z = 0;
  bool scrollable = true;
  bool contents_opaque = true;
  bool double_sided = true;
  bool hide_layer_and_subtree = true;
  bool masks_to_bounds = true;

  // Properties changed.
  timer_.Reset();
  do {
    test_layer->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f));
    test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
    test_layer->SetContentsOpaque(contents_opaque);
    test_layer->SetDoubleSided(double_sided);
    test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
    test_layer->SetMasksToBounds(masks_to_bounds);
    test_layer->SetScrollClipLayerId(scrollable ? test_layer->id()
                                                : Layer::INVALID_ID);
    test_layer->PushPropertiesTo(impl_layer.get());

    transform_origin_z += 0.01f;
    scrollable = !scrollable;
    contents_opaque = !contents_opaque;
    double_sided = !double_sided;
    hide_layer_and_subtree = !hide_layer_and_subtree;
    masks_to_bounds = !masks_to_bounds;

    timer_.NextLap();
  } while (!timer_.HasTimeLimitExpired());

  perf_test::PrintResult("push_properties_to",
                         "",
                         "props_changed",
                         timer_.LapsPerSecond(),
                         "runs/s",
                         true);

  // Properties didn't change.
  timer_.Reset();
  do {
    test_layer->PushPropertiesTo(impl_layer.get());
    timer_.NextLap();
  } while (!timer_.HasTimeLimitExpired());

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


}  // namespace
}  // namespace cc