OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "base/logging.h" | |
6 #include "cc/debug/lap_timer.h" | |
7 #include "cc/resources/texture_compressor.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 #include "testing/perf/perf_test.h" | |
10 | |
11 namespace cc { | |
12 namespace { | |
13 | |
14 const int kTimeLimitMillis = 2000; | |
15 const int kWarmupRuns = 5; | |
16 const int kTimeCheckInterval = 10; | |
17 | |
18 const int kImageWidth = 256; | |
19 const int kImageHeight = 256; | |
20 const int kImageChannels = 4; | |
21 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels; | |
22 | |
23 std::string FormatName(TextureCompressor::Format format) { | |
24 switch (format) { | |
25 case TextureCompressor::kFormatETC1: | |
26 return "ETC1"; | |
27 } | |
28 | |
29 NOTREACHED(); | |
30 return ""; | |
31 } | |
32 | |
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"; | |
41 } | |
42 | |
43 NOTREACHED(); | |
44 return ""; | |
45 } | |
46 | |
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) {} | |
56 | |
57 void SetUp() override { | |
58 TextureCompressor::Format format = ::testing::get<1>(GetParam()); | |
59 compressor_ = TextureCompressor::Create(format); | |
60 } | |
61 | |
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()); | |
69 | |
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); | |
74 } | |
75 | |
76 protected: | |
77 LapTimer timer_; | |
78 scoped_ptr<TextureCompressor> compressor_; | |
79 uint8_t src_[kImageSizeInBytes]; | |
80 uint8_t dst_[kImageSizeInBytes]; | |
81 }; | |
82 | |
83 TEST_P(TextureCompressorPerfTest, Compress256x256BlackAndWhiteGradientImage) { | |
84 for (int i = 0; i < kImageSizeInBytes; ++i) | |
85 src_[i] = i % 256; | |
86 | |
87 RunTest("BlackAndWhiteGradientImage"); | |
88 } | |
89 | |
90 TEST_P(TextureCompressorPerfTest, Compress256x256SolidBlackImage) { | |
91 memset(src_, 0, kImageSizeInBytes); | |
92 | |
93 RunTest("SolidBlackImage"); | |
94 } | |
95 | |
96 TEST_P(TextureCompressorPerfTest, Compress256x256SolidColorImage) { | |
97 for (int i = 0; i < kImageSizeInBytes; ++i) | |
98 src_[i] = (4 - i % 4) * 50; | |
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 | |
120 } // namespace | |
121 } // namespace cc | |
OLD | NEW |