Add ICU message format support
[chromium-blink-merge.git] / cc / raster / texture_compressor_perftest.cc
blob4b2967c0ba646e5129d767c999ec29de137ecd4e
1 // Copyright 2015 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.
5 #include "base/logging.h"
6 #include "cc/debug/lap_timer.h"
7 #include "cc/raster/texture_compressor.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/perf/perf_test.h"
11 namespace cc {
12 namespace {
14 const int kTimeLimitMillis = 2000;
15 const int kWarmupRuns = 5;
16 const int kTimeCheckInterval = 10;
18 const int kImageWidth = 256;
19 const int kImageHeight = 256;
20 const int kImageChannels = 4;
21 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels;
23 std::string FormatName(TextureCompressor::Format format) {
24 switch (format) {
25 case TextureCompressor::kFormatETC1:
26 return "ETC1";
29 NOTREACHED();
30 return "";
33 std::string QualityName(TextureCompressor::Quality quality) {
34 switch (quality) {
35 case TextureCompressor::kQualityLow:
36 return "Low";
37 case TextureCompressor::kQualityMedium:
38 return "Medium";
39 case TextureCompressor::kQualityHigh:
40 return "High";
43 NOTREACHED();
44 return "";
47 class TextureCompressorPerfTest
48 : public testing::TestWithParam<
49 ::testing::tuple<TextureCompressor::Quality,
50 TextureCompressor::Format>> {
51 public:
52 TextureCompressorPerfTest()
53 : timer_(kWarmupRuns,
54 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
55 kTimeCheckInterval) {}
57 void SetUp() override {
58 TextureCompressor::Format format = ::testing::get<1>(GetParam());
59 compressor_ = TextureCompressor::Create(format);
62 void RunTest(const std::string& name) {
63 TextureCompressor::Quality quality = ::testing::get<0>(GetParam());
64 timer_.Reset();
65 do {
66 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality);
67 timer_.NextLap();
68 } while (!timer_.HasTimeLimitExpired());
70 TextureCompressor::Format format = ::testing::get<1>(GetParam());
71 std::string str = FormatName(format) + " " + QualityName(quality);
72 perf_test::PrintResult("Compress256x256", name, str, timer_.MsPerLap(),
73 "us", true);
76 protected:
77 LapTimer timer_;
78 scoped_ptr<TextureCompressor> compressor_;
79 uint8_t src_[kImageSizeInBytes];
80 uint8_t dst_[kImageSizeInBytes];
83 TEST_P(TextureCompressorPerfTest, Compress256x256BlackAndWhiteGradientImage) {
84 for (int i = 0; i < kImageSizeInBytes; ++i)
85 src_[i] = i % 256;
87 RunTest("BlackAndWhiteGradientImage");
90 TEST_P(TextureCompressorPerfTest, Compress256x256SolidBlackImage) {
91 memset(src_, 0, kImageSizeInBytes);
93 RunTest("SolidBlackImage");
96 TEST_P(TextureCompressorPerfTest, Compress256x256SolidColorImage) {
97 for (int i = 0; i < kImageSizeInBytes; ++i)
98 src_[i] = (4 - i % 4) * 50;
100 RunTest("SolidColorImage");
103 TEST_P(TextureCompressorPerfTest, Compress256x256RandomColorImage) {
104 unsigned int kImageSeed = 1234567890;
105 srand(kImageSeed);
106 for (int i = 0; i < kImageSizeInBytes; ++i)
107 src_[i] = rand() % 256; // NOLINT
109 RunTest("RandomColorImage");
112 INSTANTIATE_TEST_CASE_P(
113 TextureCompressorPerfTests,
114 TextureCompressorPerfTest,
115 ::testing::Combine(::testing::Values(TextureCompressor::kQualityLow,
116 TextureCompressor::kQualityMedium,
117 TextureCompressor::kQualityHigh),
118 ::testing::Values(TextureCompressor::kFormatETC1)));
120 } // namespace
121 } // namespace cc