summaryrefslogtreecommitdiffstats
path: root/chromium/cc/resources/picture_pile_impl_perftest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/cc/resources/picture_pile_impl_perftest.cc')
-rw-r--r--chromium/cc/resources/picture_pile_impl_perftest.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/chromium/cc/resources/picture_pile_impl_perftest.cc b/chromium/cc/resources/picture_pile_impl_perftest.cc
new file mode 100644
index 00000000000..7ced0eaa1be
--- /dev/null
+++ b/chromium/cc/resources/picture_pile_impl_perftest.cc
@@ -0,0 +1,89 @@
+// 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/resources/picture_pile_impl.h"
+
+#include "cc/debug/lap_timer.h"
+#include "cc/test/fake_picture_pile_impl.h"
+#include "cc/test/fake_rendering_stats_instrumentation.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/perf/perf_test.h"
+
+namespace cc {
+namespace {
+
+const int kTimeLimitMillis = 2000;
+const int kWarmupRuns = 5;
+const int kTimeCheckInterval = 10;
+
+const int kTileSize = 100;
+const int kLayerSize = 1000;
+
+class PicturePileImplPerfTest : public testing::Test {
+ public:
+ PicturePileImplPerfTest()
+ : timer_(kWarmupRuns,
+ base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
+ kTimeCheckInterval) {}
+
+ void RunAnalyzeTest(const std::string& test_name, float contents_scale) {
+ scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
+ gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
+ // Content rect that will align with top-left tile at scale 1.0.
+ gfx::Rect content_rect(0, 0, kTileSize, kTileSize);
+
+ PicturePileImpl::Analysis analysis;
+ timer_.Reset();
+ do {
+ pile->AnalyzeInRect(content_rect, contents_scale, &analysis);
+ timer_.NextLap();
+ } while (!timer_.HasTimeLimitExpired());
+
+ perf_test::PrintResult(
+ "analyze", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
+ }
+
+ void RunRasterTest(const std::string& test_name, float contents_scale) {
+ scoped_refptr<PicturePileImpl> pile = FakePicturePileImpl::CreateFilledPile(
+ gfx::Size(kTileSize, kTileSize), gfx::Size(kLayerSize, kLayerSize));
+ // Content rect that will align with top-left tile at scale 1.0.
+ gfx::Rect content_rect(0, 0, kTileSize, kTileSize);
+
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
+ bitmap.allocPixels();
+ SkCanvas canvas(bitmap);
+
+ FakeRenderingStatsInstrumentation rendering_stats_instrumentation;
+ timer_.Reset();
+ do {
+ pile->RasterToBitmap(&canvas,
+ content_rect,
+ contents_scale,
+ &rendering_stats_instrumentation);
+ timer_.NextLap();
+ } while (!timer_.HasTimeLimitExpired());
+
+ perf_test::PrintResult(
+ "raster", "", test_name, timer_.LapsPerSecond(), "runs/s", true);
+ }
+
+ private:
+ LapTimer timer_;
+};
+
+TEST_F(PicturePileImplPerfTest, Analyze) {
+ RunAnalyzeTest("1", 1.0f);
+ RunAnalyzeTest("4", 0.5f);
+ RunAnalyzeTest("100", 0.1f);
+}
+
+TEST_F(PicturePileImplPerfTest, Raster) {
+ RunRasterTest("1", 1.0f);
+ RunRasterTest("4", 0.5f);
+ RunRasterTest("100", 0.1f);
+}
+
+} // namespace
+} // namespace cc