Index: ui/gfx/codec/png_codec_perftest.cc |
diff --git a/ui/gfx/codec/png_codec_perftest.cc b/ui/gfx/codec/png_codec_perftest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ca75c23ae245a333c4b464417466c167933fd21 |
--- /dev/null |
+++ b/ui/gfx/codec/png_codec_perftest.cc |
@@ -0,0 +1,113 @@ |
+// Copyright 2016 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 "ui/gfx/codec/png_codec.h" |
+ |
+#include <stdint.h> |
+ |
+#include <memory> |
+ |
+#include "base/rand_util.h" |
+#include "cc/debug/lap_timer.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/perf/perf_test.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "third_party/skia/include/core/SkColor.h" |
+#include "third_party/skia/include/core/SkImageInfo.h" |
+ |
+namespace gfx { |
+ |
+namespace { |
+ |
+const int kTimeLimitMillis = 5000; |
+const int kWarmupRuns = 3; |
+const int kTimeCheckInterval = 1; |
+ |
+SkBitmap CreateSimpleBitmap() { |
+ SkBitmap bitmap; |
+ EXPECT_TRUE(bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(2000, 2000))); |
+ bitmap.eraseARGB(0x87, 0x65, 0x43, 0x21); |
+ return bitmap; |
+} |
+ |
+SkBitmap CreateRandomBitmap() { |
+ SkBitmap bitmap; |
+ EXPECT_TRUE(bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul(2000, 2000))); |
+ SkAutoLockPixels lock(bitmap); |
+ base::RandBytes(bitmap.getPixels(), bitmap.getSize()); |
+ for (int i = 0; i < bitmap.width(); ++i) { |
+ for (int j = 0; j < bitmap.width(); ++j) { |
+ uint32_t* pixel = bitmap.getAddr32(i, j); |
+ *pixel = SkPreMultiplyColor(*pixel); |
+ } |
+ } |
+ return bitmap; |
+} |
+ |
+} // namespace |
+ |
+class PngCodecPerfTest : public ::testing::Test { |
+ public: |
+ PngCodecPerfTest() |
+ : timer_(kWarmupRuns, |
+ base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
+ kTimeCheckInterval) {} |
+ |
+ protected: |
+ void PrintResult(const char* trace) { |
+ perf_test::PrintResult("png_encode", "", trace, timer_.MsPerLap(), "ms/run", |
+ true); |
+ } |
+ |
+ cc::LapTimer timer_; |
+ SkBitmap bitmap_; |
+}; |
+ |
+TEST_F(PngCodecPerfTest, SimpleFastEncode) { |
+ bitmap_ = CreateSimpleBitmap(); |
+ timer_.Reset(); |
+ do { |
+ std::vector<uint8_t> output; |
+ ASSERT_TRUE(PNGCodec::FastEncodeBGRASkBitmap(bitmap_, false, &output)); |
+ timer_.NextLap(); |
+ } while (!timer_.HasTimeLimitExpired()); |
+ PrintResult("fast encode"); |
+} |
+ |
+TEST_F(PngCodecPerfTest, SimpleNoCompress) { |
+ bitmap_ = CreateSimpleBitmap(); |
+ timer_.Reset(); |
+ do { |
+ std::vector<uint8_t> output; |
+ ASSERT_TRUE( |
+ PNGCodec::NoCompressEncodeBGRASkBitmap(bitmap_, false, &output)); |
+ timer_.NextLap(); |
+ } while (!timer_.HasTimeLimitExpired()); |
+ PrintResult("no compress encode"); |
+} |
+ |
+TEST_F(PngCodecPerfTest, RandomFastEncode) { |
+ bitmap_ = CreateRandomBitmap(); |
+ timer_.Reset(); |
+ do { |
+ std::vector<uint8_t> output; |
+ ASSERT_TRUE(PNGCodec::FastEncodeBGRASkBitmap(bitmap_, false, &output)); |
+ timer_.NextLap(); |
+ } while (!timer_.HasTimeLimitExpired()); |
+ PrintResult("fast encode"); |
+} |
+ |
+TEST_F(PngCodecPerfTest, RandomNoCompress) { |
+ bitmap_ = CreateRandomBitmap(); |
+ timer_.Reset(); |
+ do { |
+ std::vector<uint8_t> output; |
+ ASSERT_TRUE( |
+ PNGCodec::NoCompressEncodeBGRASkBitmap(bitmap_, false, &output)); |
+ timer_.NextLap(); |
+ } while (!timer_.HasTimeLimitExpired()); |
+ PrintResult("no compress encode"); |
+} |
+ |
+} // namespace gfx |