Home | History | Annotate | Download | only in layers
      1 // Copyright 2013 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/layer.h"
      6 
      7 #include "cc/resources/layer_painter.h"
      8 #include "cc/test/fake_impl_proxy.h"
      9 #include "cc/test/fake_layer_tree_host.h"
     10 #include "cc/test/fake_layer_tree_host_client.h"
     11 #include "cc/test/fake_layer_tree_host_impl.h"
     12 #include "cc/test/lap_timer.h"
     13 
     14 #include "testing/gtest/include/gtest/gtest.h"
     15 #include "testing/perf/perf_test.h"
     16 
     17 namespace cc {
     18 namespace {
     19 
     20 static const int kTimeLimitMillis = 3000;
     21 static const int kWarmupRuns = 5;
     22 static const int kTimeCheckInterval = 10;
     23 
     24 class MockLayerPainter : public LayerPainter {
     25  public:
     26   virtual void Paint(SkCanvas* canvas,
     27                      gfx::Rect content_rect,
     28                      gfx::RectF* opaque) OVERRIDE {}
     29 };
     30 
     31 
     32 class LayerPerfTest : public testing::Test {
     33  public:
     34   LayerPerfTest()
     35       : host_impl_(&proxy_),
     36         fake_client_(FakeLayerTreeHostClient::DIRECT_3D),
     37         timer_(kWarmupRuns,
     38                base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
     39                kTimeCheckInterval) {}
     40 
     41  protected:
     42   virtual void SetUp() OVERRIDE {
     43     layer_tree_host_ = FakeLayerTreeHost::Create();
     44     layer_tree_host_->InitializeSingleThreaded(&fake_client_);
     45   }
     46 
     47   virtual void TearDown() OVERRIDE {
     48     layer_tree_host_->SetRootLayer(NULL);
     49     layer_tree_host_.reset();
     50   }
     51 
     52   FakeImplProxy proxy_;
     53   FakeLayerTreeHostImpl host_impl_;
     54 
     55   FakeLayerTreeHostClient fake_client_;
     56   scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
     57   LapTimer timer_;
     58 };
     59 
     60 TEST_F(LayerPerfTest, PushPropertiesTo) {
     61   scoped_refptr<Layer> test_layer = Layer::Create();
     62   scoped_ptr<LayerImpl> impl_layer =
     63       LayerImpl::Create(host_impl_.active_tree(), 1);
     64 
     65   layer_tree_host_->SetRootLayer(test_layer);
     66 
     67   float anchor_point_z = 0;
     68   bool scrollable = true;
     69   bool contents_opaque = true;
     70   bool double_sided = true;
     71   bool hide_layer_and_subtree = true;
     72   bool masks_to_bounds = true;
     73 
     74   // Properties changed.
     75   timer_.Reset();
     76   do {
     77     test_layer->SetNeedsDisplayRect(gfx::RectF(0.f, 0.f, 5.f, 5.f));
     78     test_layer->SetAnchorPointZ(anchor_point_z);
     79     test_layer->SetContentsOpaque(contents_opaque);
     80     test_layer->SetDoubleSided(double_sided);
     81     test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
     82     test_layer->SetMasksToBounds(masks_to_bounds);
     83     test_layer->SetScrollable(scrollable);
     84     test_layer->PushPropertiesTo(impl_layer.get());
     85 
     86     anchor_point_z += 0.01f;
     87     scrollable = !scrollable;
     88     contents_opaque = !contents_opaque;
     89     double_sided = !double_sided;
     90     hide_layer_and_subtree = !hide_layer_and_subtree;
     91     masks_to_bounds = !masks_to_bounds;
     92 
     93     timer_.NextLap();
     94   } while (!timer_.HasTimeLimitExpired());
     95 
     96   perf_test::PrintResult("push_properties_to",
     97                          "",
     98                          "props_changed",
     99                          timer_.LapsPerSecond(),
    100                          "runs/s",
    101                          true);
    102 
    103   // Properties didn't change.
    104   timer_.Reset();
    105   do {
    106     test_layer->PushPropertiesTo(impl_layer.get());
    107     timer_.NextLap();
    108   } while (!timer_.HasTimeLimitExpired());
    109 
    110   perf_test::PrintResult("push_properties_to",
    111                          "",
    112                          "props_didnt_change",
    113                          timer_.LapsPerSecond(),
    114                          "runs/s",
    115                          true);
    116 }
    117 
    118 
    119 }  // namespace
    120 }  // namespace cc
    121