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
|
// Copyright 2013 The Chromium Authors
// 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 "base/task/single_thread_task_runner.h"
#include "base/timer/lap_timer.h"
#include "cc/animation/animation_host.h"
#include "cc/test/fake_impl_task_runner_provider.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 "cc/test/stub_layer_tree_host_single_thread_client.h"
#include "cc/test/test_task_graph_runner.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_result_reporter.h"
namespace cc {
namespace {
static const int kTimeLimitMillis = 3000;
static const int kWarmupRuns = 5;
static const int kTimeCheckInterval = 10;
class LayerPerfTest : public testing::Test {
public:
LayerPerfTest()
: host_impl_(&task_runner_provider_, &task_graph_runner_),
timer_(kWarmupRuns,
base::Milliseconds(kTimeLimitMillis),
kTimeCheckInterval) {}
protected:
void SetUp() override {
animation_host_ = AnimationHost::CreateForTesting(ThreadInstance::kMain);
layer_tree_host_ = FakeLayerTreeHost::Create(
&fake_client_, &task_graph_runner_, animation_host_.get());
layer_tree_host_->InitializeSingleThreaded(
&single_thread_client_,
base::SingleThreadTaskRunner::GetCurrentDefault());
}
void TearDown() override {
layer_tree_host_->SetRootLayer(nullptr);
layer_tree_host_ = nullptr;
}
perf_test::PerfResultReporter SetUpReporter(
const std::string& metric_basename,
const std::string& story_name) {
perf_test::PerfResultReporter reporter(metric_basename, story_name);
reporter.RegisterImportantMetric("", "runs/s");
return reporter;
}
FakeImplTaskRunnerProvider task_runner_provider_;
TestTaskGraphRunner task_graph_runner_;
FakeLayerTreeHostImpl host_impl_;
StubLayerTreeHostSingleThreadClient single_thread_client_;
FakeLayerTreeHostClient fake_client_;
std::unique_ptr<AnimationHost> animation_host_;
std::unique_ptr<FakeLayerTreeHost> layer_tree_host_;
base::LapTimer timer_;
};
TEST_F(LayerPerfTest, PushPropertiesTo) {
scoped_refptr<Layer> test_layer = Layer::Create();
std::unique_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 hide_layer_and_subtree = true;
bool masks_to_bounds = true;
// Properties changed.
timer_.Reset();
do {
test_layer->SetNeedsDisplayRect(gfx::Rect(5, 5));
test_layer->SetTransformOrigin(gfx::Point3F(0.f, 0.f, transform_origin_z));
test_layer->SetContentsOpaque(contents_opaque);
test_layer->SetHideLayerAndSubtree(hide_layer_and_subtree);
test_layer->SetMasksToBounds(masks_to_bounds);
// Here and elsewhere: when doing a full commit, we would call
// layer_tree_host_->ActivateCommitState() and the second argument would
// come from layer_tree_host_->active_commit_state(); we use
// pending_commit_state() just to keep the test code simple.
test_layer->PushPropertiesTo(
impl_layer.get(), *layer_tree_host_->GetPendingCommitState(),
layer_tree_host_->GetThreadUnsafeCommitState());
transform_origin_z += 0.01f;
scrollable = !scrollable;
contents_opaque = !contents_opaque;
hide_layer_and_subtree = !hide_layer_and_subtree;
masks_to_bounds = !masks_to_bounds;
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter =
SetUpReporter("push_properties_to", "props_changed");
reporter.AddResult("", timer_.LapsPerSecond());
// Properties didn't change.
timer_.Reset();
do {
test_layer->PushPropertiesTo(
impl_layer.get(), *layer_tree_host_->GetPendingCommitState(),
layer_tree_host_->GetThreadUnsafeCommitState());
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
reporter = SetUpReporter("push_properties_to", "props_didnt_change");
reporter.AddResult("", timer_.LapsPerSecond());
}
TEST_F(LayerPerfTest, ImplPushPropertiesTo) {
std::unique_ptr<LayerImpl> test_layer =
LayerImpl::Create(host_impl_.active_tree(), 1);
std::unique_ptr<LayerImpl> impl_layer =
LayerImpl::Create(host_impl_.active_tree(), 2);
SkColor4f background_color = SkColors::kRed;
gfx::Size bounds(1000, 1000);
bool draws_content = true;
bool contents_opaque = true;
bool masks_to_bounds = true;
// Properties changed.
timer_.Reset();
do {
test_layer->SetBackgroundColor(background_color);
test_layer->SetSafeOpaqueBackgroundColor(background_color);
test_layer->SetDrawsContent(draws_content);
test_layer->SetContentsOpaque(contents_opaque);
test_layer->PushPropertiesTo(impl_layer.get());
background_color =
background_color == SkColors::kRed ? SkColors::kGreen : SkColors::kRed;
bounds = bounds == gfx::Size(1000, 1000) ? gfx::Size(500, 500)
: gfx::Size(1000, 1000);
draws_content = !draws_content;
contents_opaque = !contents_opaque;
masks_to_bounds = !masks_to_bounds;
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PerfResultReporter reporter =
SetUpReporter("impl_push_properties_to", "props_changed");
reporter.AddResult("", timer_.LapsPerSecond());
// Properties didn't change.
timer_.Reset();
do {
test_layer->PushPropertiesTo(impl_layer.get());
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
reporter = SetUpReporter("impl_push_properties_to", "props_didnt_change");
reporter.AddResult("", timer_.LapsPerSecond());
}
} // namespace
} // namespace cc
|