Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "cc/debug/lap_timer.h" | 6 #include "cc/debug/lap_timer.h" |
| 7 #include "cc/resources/texture_compressor.h" | 7 #include "cc/resources/texture_compressor.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/perf/perf_test.h" | 9 #include "testing/perf/perf_test.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 const int kTimeLimitMillis = 2000; | 14 const int kTimeLimitMillis = 2000; |
| 15 const int kWarmupRuns = 5; | 15 const int kWarmupRuns = 5; |
| 16 const int kTimeCheckInterval = 10; | 16 const int kTimeCheckInterval = 10; |
| 17 | 17 |
| 18 const int kImageWidth = 256; | 18 const int kImageWidth = 256; |
| 19 const int kImageHeight = 256; | 19 const int kImageHeight = 256; |
| 20 const int kImageSizeInBytes = kImageWidth * kImageHeight * 4; | 20 const int kImageChannels = 4; |
| 21 | 21 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels; |
| 22 const TextureCompressor::Quality kQualities[] = { | |
| 23 TextureCompressor::kQualityLow, | |
| 24 TextureCompressor::kQualityMedium, | |
| 25 TextureCompressor::kQualityHigh}; | |
| 26 | 22 |
| 27 std::string FormatName(TextureCompressor::Format format) { | 23 std::string FormatName(TextureCompressor::Format format) { |
| 28 switch (format) { | 24 switch (format) { |
| 29 case TextureCompressor::kFormatETC1: | 25 case TextureCompressor::kFormatETC1: |
| 30 return "ETC1"; | 26 return "ETC1"; |
| 31 } | 27 } |
| 32 | 28 |
| 33 NOTREACHED(); | 29 NOTREACHED(); |
| 34 return ""; | 30 return ""; |
| 35 } | 31 } |
| 36 | 32 |
| 37 std::string QualityName(TextureCompressor::Quality quality) { | 33 std::string QualityName(TextureCompressor::Quality quality) { |
| 38 switch (quality) { | 34 switch (quality) { |
| 39 case TextureCompressor::kQualityLow: | 35 case TextureCompressor::kQualityLow: |
| 40 return "Low"; | 36 return "Low"; |
| 41 case TextureCompressor::kQualityMedium: | 37 case TextureCompressor::kQualityMedium: |
| 42 return "Medium"; | 38 return "Medium"; |
| 43 case TextureCompressor::kQualityHigh: | 39 case TextureCompressor::kQualityHigh: |
| 44 return "High"; | 40 return "High"; |
| 45 } | 41 } |
| 46 | 42 |
| 47 NOTREACHED(); | 43 NOTREACHED(); |
| 48 return ""; | 44 return ""; |
| 49 } | 45 } |
| 50 | 46 |
| 51 class TextureCompressorPerfTest | 47 class TextureCompressorPerfTest |
| 52 : public testing::TestWithParam<TextureCompressor::Format> { | 48 : public testing::TestWithParam< |
| 49 ::testing::tuple<TextureCompressor::Quality, | |
| 50 TextureCompressor::Format>> { | |
| 53 public: | 51 public: |
| 54 TextureCompressorPerfTest() | 52 TextureCompressorPerfTest() |
| 55 : timer_(kWarmupRuns, | 53 : timer_(kWarmupRuns, |
| 56 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 54 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 57 kTimeCheckInterval) {} | 55 kTimeCheckInterval) {} |
| 58 | 56 |
| 59 void SetUp() override { | 57 void SetUp() override { |
| 60 TextureCompressor::Format format = GetParam(); | 58 quality_ = ::testing::get<0>(GetParam()); |
| 59 TextureCompressor::Format format = ::testing::get<1>(GetParam()); | |
| 61 compressor_ = TextureCompressor::Create(format); | 60 compressor_ = TextureCompressor::Create(format); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void RunTest(const std::string& name, TextureCompressor::Quality quality) { | 63 void RunTest(const std::string& name, TextureCompressor::Quality quality) { |
|
reveman
2015/05/07 14:24:35
nit: please remove the quality parameter/member an
radu.velea
2015/05/07 15:53:46
Done.
| |
| 65 timer_.Reset(); | 64 timer_.Reset(); |
| 66 do { | 65 do { |
| 67 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality); | 66 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality); |
| 68 timer_.NextLap(); | 67 timer_.NextLap(); |
| 69 } while (!timer_.HasTimeLimitExpired()); | 68 } while (!timer_.HasTimeLimitExpired()); |
| 70 | 69 |
| 71 std::string str = FormatName(GetParam()) + " " + QualityName(quality); | 70 std::string str = |
| 71 FormatName(::testing::get<1>(GetParam())) + " " + QualityName(quality); | |
|
reveman
2015/05/07 14:24:35
nit: please add a TextureCompressor::Format format
radu.velea
2015/05/07 15:53:46
Done.
| |
| 72 perf_test::PrintResult("Compress256x256", name, str, timer_.MsPerLap(), | 72 perf_test::PrintResult("Compress256x256", name, str, timer_.MsPerLap(), |
| 73 "us", true); | 73 "us", true); |
| 74 } | 74 } |
| 75 | 75 |
| 76 protected: | 76 protected: |
| 77 TextureCompressor::Quality quality_; | |
| 77 LapTimer timer_; | 78 LapTimer timer_; |
| 78 scoped_ptr<TextureCompressor> compressor_; | 79 scoped_ptr<TextureCompressor> compressor_; |
| 79 uint8_t src_[kImageSizeInBytes]; | 80 uint8_t src_[kImageSizeInBytes]; |
| 80 uint8_t dst_[kImageSizeInBytes]; | 81 uint8_t dst_[kImageSizeInBytes]; |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 TEST_P(TextureCompressorPerfTest, Compress256x256Image) { | 84 TEST_P(TextureCompressorPerfTest, Compress256x256BlackAndWhiteGradientImage) { |
| 84 for (int i = 0; i < kImageSizeInBytes; ++i) | 85 for (int i = 0; i < kImageSizeInBytes; ++i) |
| 85 src_[i] = i % 256; | 86 src_[i] = i % 256; |
| 86 | 87 |
| 87 for (auto& quality : kQualities) | 88 RunTest("BlackAndWhiteGradientImage", quality_); |
| 88 RunTest("Image", quality); | |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST_P(TextureCompressorPerfTest, Compress256x256SolidImage) { | 91 TEST_P(TextureCompressorPerfTest, Compress256x256SolidBlackImage) { |
| 92 memset(src_, 0, kImageSizeInBytes); | 92 memset(src_, 0, kImageSizeInBytes); |
| 93 | 93 |
| 94 for (auto& quality : kQualities) | 94 RunTest("SolidBlackImage", quality_); |
| 95 RunTest("SolidImage", quality); | |
| 96 } | 95 } |
| 97 | 96 |
| 98 INSTANTIATE_TEST_CASE_P(TextureCompressorPerfTests, | 97 TEST_P(TextureCompressorPerfTest, Compress256x256SolidColorImage) { |
| 99 TextureCompressorPerfTest, | 98 for (int i = 0; i < kImageSizeInBytes; ++i) |
| 100 ::testing::Values(TextureCompressor::kFormatETC1)); | 99 src_[i] = (4 - i % 4) * 50; |
| 100 | |
| 101 RunTest("SolidColorImage", quality_); | |
| 102 } | |
| 103 | |
| 104 TEST_P(TextureCompressorPerfTest, Compress256x256RandomColorImage) { | |
| 105 unsigned int kImageSeed = 1234567890; | |
| 106 // On Windows, rand() is threadsafe, and rand_r() is not available. | |
| 107 #if defined(OS_WIN) | |
|
reveman
2015/05/07 14:24:35
do we need this ifdef? we use srand and std::rand
radu.velea
2015/05/07 15:53:46
Done.
| |
| 108 srand(kImageSeed); | |
| 109 for (int i = 0; i < kImageSizeInBytes; ++i) | |
| 110 src_[i] = rand() % 256; // NOLINT | |
| 111 #else | |
| 112 for (int i = 0; i < kImageSizeInBytes; ++i) | |
| 113 src_[i] = rand_r(&kImageSeed) % 256; | |
| 114 #endif | |
| 115 RunTest("RandomColorImage", quality_); | |
| 116 } | |
| 117 | |
| 118 INSTANTIATE_TEST_CASE_P( | |
| 119 TextureCompressorPerfTests, | |
| 120 TextureCompressorPerfTest, | |
| 121 ::testing::Combine(::testing::Values(TextureCompressor::kQualityLow, | |
| 122 TextureCompressor::kQualityMedium, | |
| 123 TextureCompressor::kQualityHigh), | |
| 124 ::testing::Values(TextureCompressor::kFormatETC1))); | |
| 101 | 125 |
| 102 } // namespace | 126 } // namespace |
| 103 } // namespace cc | 127 } // namespace cc |
| OLD | NEW |