GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / cc / resources / texture_compressor_perftest.cc
blob7d68bd6f5f3d9415e2d14de53de87fd4f860935f
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/resources/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 kImageSizeInBytes = kImageWidth * kImageHeight * 4;
22 const TextureCompressor::Quality kQualities[] = {
23 TextureCompressor::kQualityLow,
24 TextureCompressor::kQualityMedium,
25 TextureCompressor::kQualityHigh};
27 std::string FormatName(TextureCompressor::Format format) {
28 switch (format) {
29 case TextureCompressor::kFormatETC1:
30 return "ETC1";
33 NOTREACHED();
34 return "";
37 std::string QualityName(TextureCompressor::Quality quality) {
38 switch (quality) {
39 case TextureCompressor::kQualityLow:
40 return "Low";
41 case TextureCompressor::kQualityMedium:
42 return "Medium";
43 case TextureCompressor::kQualityHigh:
44 return "High";
47 NOTREACHED();
48 return "";
51 class TextureCompressorPerfTest
52 : public testing::TestWithParam<TextureCompressor::Format> {
53 public:
54 TextureCompressorPerfTest()
55 : timer_(kWarmupRuns,
56 base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
57 kTimeCheckInterval) {}
59 void SetUp() override {
60 TextureCompressor::Format format = GetParam();
61 compressor_ = TextureCompressor::Create(format);
64 void RunTest(const std::string& name, TextureCompressor::Quality quality) {
65 timer_.Reset();
66 do {
67 compressor_->Compress(src_, dst_, kImageWidth, kImageHeight, quality);
68 timer_.NextLap();
69 } while (!timer_.HasTimeLimitExpired());
71 std::string str = FormatName(GetParam()) + " " + 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, Compress256x256Image) {
84 for (int i = 0; i < kImageSizeInBytes; ++i)
85 src_[i] = i % 256;
87 for (auto& quality : kQualities)
88 RunTest("Image", quality);
91 TEST_P(TextureCompressorPerfTest, Compress256x256SolidImage) {
92 memset(src_, 0, kImageSizeInBytes);
94 for (auto& quality : kQualities)
95 RunTest("SolidImage", quality);
98 INSTANTIATE_TEST_CASE_P(TextureCompressorPerfTests,
99 TextureCompressorPerfTest,
100 ::testing::Values(TextureCompressor::kFormatETC1));
102 } // namespace
103 } // namespace cc