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"
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
) {
25 case TextureCompressor::kFormatETC1
:
33 std::string
QualityName(TextureCompressor::Quality quality
) {
35 case TextureCompressor::kQualityLow
:
37 case TextureCompressor::kQualityMedium
:
39 case TextureCompressor::kQualityHigh
:
47 class TextureCompressorPerfTest
48 : public testing::TestWithParam
<
49 ::testing::tuple
<TextureCompressor::Quality
,
50 TextureCompressor::Format
>> {
52 TextureCompressorPerfTest()
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());
66 compressor_
->Compress(src_
, dst_
, kImageWidth
, kImageHeight
, quality
);
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(),
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
)
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;
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
)));