| 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 kImageChannels = 4; | 20 const int kImageSizeInBytes = kImageWidth * kImageHeight * 4; |
| 21 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels; | 21 |
| 22 const TextureCompressor::Quality kQualities[] = { |
| 23 TextureCompressor::kQualityLow, |
| 24 TextureCompressor::kQualityMedium, |
| 25 TextureCompressor::kQualityHigh}; |
| 22 | 26 |
| 23 std::string FormatName(TextureCompressor::Format format) { | 27 std::string FormatName(TextureCompressor::Format format) { |
| 24 switch (format) { | 28 switch (format) { |
| 25 case TextureCompressor::kFormatETC1: | 29 case TextureCompressor::kFormatETC1: |
| 26 return "ETC1"; | 30 return "ETC1"; |
| 27 } | 31 } |
| 28 | 32 |
| 29 NOTREACHED(); | 33 NOTREACHED(); |
| 30 return ""; | 34 return ""; |
| 31 } | 35 } |
| 32 | 36 |
| 33 std::string QualityName(TextureCompressor::Quality quality) { | 37 std::string QualityName(TextureCompressor::Quality quality) { |
| 34 switch (quality) { | 38 switch (quality) { |
| 35 case TextureCompressor::kQualityLow: | 39 case TextureCompressor::kQualityLow: |
| 36 return "Low"; | 40 return "Low"; |
| 37 case TextureCompressor::kQualityMedium: | 41 case TextureCompressor::kQualityMedium: |
| 38 return "Medium"; | 42 return "Medium"; |
| 39 case TextureCompressor::kQualityHigh: | 43 case TextureCompressor::kQualityHigh: |
| 40 return "High"; | 44 return "High"; |
| 41 } | 45 } |
| 42 | 46 |
| 43 NOTREACHED(); | 47 NOTREACHED(); |
| 44 return ""; | 48 return ""; |
| 45 } | 49 } |
| 46 | 50 |
| 47 class TextureCompressorPerfTest | 51 class TextureCompressorPerfTest |
| 48 : public testing::TestWithParam< | 52 : public testing::TestWithParam<TextureCompressor::Format> { |
| 49 ::testing::tuple<TextureCompressor::Quality, | |
| 50 TextureCompressor::Format>> { | |
| 51 public: | 53 public: |
| 52 TextureCompressorPerfTest() | 54 TextureCompressorPerfTest() |
| 53 : timer_(kWarmupRuns, | 55 : timer_(kWarmupRuns, |
| 54 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 56 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 55 kTimeCheckInterval) {} | 57 kTimeCheckInterval) {} |
| 56 | 58 |
| 57 void SetUp() override { | 59 void SetUp() override { |
| 58 TextureCompressor::Format format = ::testing::get<1>(GetParam()); | 60 TextureCompressor::Format format = GetParam(); |
| 59 compressor_ = TextureCompressor::Create(format); | 61 compressor_ = TextureCompressor::Create(format); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void RunTest(const std::string& name) { | 64 void RunTest(const std::string& name, TextureCompressor::Quality quality) { |
| 63 TextureCompressor::Quality quality = ::testing::get<0>(GetParam()); | |
| 64 timer_.Reset(); | 65 timer_.Reset(); |
| 65 do { | 66 do { |
| 66 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality); | 67 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality); |
| 67 timer_.NextLap(); | 68 timer_.NextLap(); |
| 68 } while (!timer_.HasTimeLimitExpired()); | 69 } while (!timer_.HasTimeLimitExpired()); |
| 69 | 70 |
| 70 TextureCompressor::Format format = ::testing::get<1>(GetParam()); | 71 std::string str = FormatName(GetParam()) + " " + QualityName(quality); |
| 71 std::string str = FormatName(format) + " " + QualityName(quality); | |
| 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 LapTimer timer_; | 77 LapTimer timer_; |
| 78 scoped_ptr<TextureCompressor> compressor_; | 78 scoped_ptr<TextureCompressor> compressor_; |
| 79 uint8_t src_[kImageSizeInBytes]; | 79 uint8_t src_[kImageSizeInBytes]; |
| 80 uint8_t dst_[kImageSizeInBytes]; | 80 uint8_t dst_[kImageSizeInBytes]; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 TEST_P(TextureCompressorPerfTest, Compress256x256BlackAndWhiteGradientImage) { | 83 TEST_P(TextureCompressorPerfTest, Compress256x256Image) { |
| 84 for (int i = 0; i < kImageSizeInBytes; ++i) | 84 for (int i = 0; i < kImageSizeInBytes; ++i) |
| 85 src_[i] = i % 256; | 85 src_[i] = i % 256; |
| 86 | 86 |
| 87 RunTest("BlackAndWhiteGradientImage"); | 87 for (auto& quality : kQualities) |
| 88 RunTest("Image", quality); |
| 88 } | 89 } |
| 89 | 90 |
| 90 TEST_P(TextureCompressorPerfTest, Compress256x256SolidBlackImage) { | 91 TEST_P(TextureCompressorPerfTest, Compress256x256SolidImage) { |
| 91 memset(src_, 0, kImageSizeInBytes); | 92 memset(src_, 0, kImageSizeInBytes); |
| 92 | 93 |
| 93 RunTest("SolidBlackImage"); | 94 for (auto& quality : kQualities) |
| 95 RunTest("SolidImage", quality); |
| 94 } | 96 } |
| 95 | 97 |
| 96 TEST_P(TextureCompressorPerfTest, Compress256x256SolidColorImage) { | 98 INSTANTIATE_TEST_CASE_P(TextureCompressorPerfTests, |
| 97 for (int i = 0; i < kImageSizeInBytes; ++i) | 99 TextureCompressorPerfTest, |
| 98 src_[i] = (4 - i % 4) * 50; | 100 ::testing::Values(TextureCompressor::kFormatETC1)); |
| 99 | |
| 100 RunTest("SolidColorImage"); | |
| 101 } | |
| 102 | |
| 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 | |
| 108 | |
| 109 RunTest("RandomColorImage"); | |
| 110 } | |
| 111 | |
| 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))); | |
| 119 | 101 |
| 120 } // namespace | 102 } // namespace |
| 121 } // namespace cc | 103 } // namespace cc |
| OLD | NEW |