Chromium Code Reviews| Index: cc/resources/texture_compressor_etc1_unittest.cc |
| diff --git a/cc/resources/texture_compressor_etc1_unittest.cc b/cc/resources/texture_compressor_etc1_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ac1d927f276e662f2b12f0c401d879d295a7dc6d |
| --- /dev/null |
| +++ b/cc/resources/texture_compressor_etc1_unittest.cc |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/resources/texture_compressor.h" |
| + |
| +#include "cc/base/util.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace cc { |
| +namespace { |
| + |
| +const int kImageWidth = 256; |
| +const int kImageHeight = 256; |
| +const int kImageChannels = 4; |
| +const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels; |
| + |
| +TEST(TextureCompressorETC1Test, Compress256x256CreateETC1) { |
|
reveman
2015/05/06 18:44:02
This test is not ETC1 specific. If you think this
radu.velea
2015/05/07 11:21:41
This might be useful for checking if all encoders
|
| + scoped_ptr<TextureCompressor> compressor = |
| + TextureCompressor::Create(TextureCompressor::kFormatETC1); |
| + EXPECT_NE(nullptr, compressor); |
| +} |
| + |
| +TEST(TextureCompressorETC1Test, Compress256x256RatioETC1) { |
|
reveman
2015/05/06 18:44:02
s/Compress256x256RatioETC1/Compress256x256Ratio/ a
|
| + scoped_ptr<TextureCompressor> compressor = |
| + TextureCompressor::Create(TextureCompressor::kFormatETC1); |
| + uint8_t src[kImageSizeInBytes]; |
| + uint8_t dst[kImageSizeInBytes]; |
|
reveman
2015/05/06 18:44:02
How about we add TextureCompressor API that will r
radu.velea
2015/05/07 11:21:41
That would be a good idea. I had a talk with chris
|
| + int compressed_size = 0; |
|
reveman
2015/05/06 18:44:02
nit: move this variable down to where it's first u
radu.velea
2015/05/07 11:21:41
Done.
|
| + const unsigned int kImagePoison = 0xDEADBEEF; |
| + |
| + /* Poison destination bytes */ |
|
reveman
2015/05/06 18:44:02
nit: comment style
radu.velea
2015/05/07 11:21:41
Done.
|
| + uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst); |
| + for (int i = 0; i < kImageWidth * kImageHeight; i++) { |
| + dst_32[i] = kImagePoison; |
| + } |
| + |
| + /* Generate test texture */ |
|
reveman
2015/05/06 18:44:02
nit: comment style
radu.velea
2015/05/07 11:21:41
Done.
|
| + for (int i = 0; i < kImageSizeInBytes; i++) { |
| + src[i] = i % 256; |
| + } |
| + |
| + compressor->Compress(src, dst, kImageWidth, kImageHeight, |
| + (TextureCompressor::Quality)0); |
|
reveman
2015/05/06 18:44:02
Don't use c-style casts. I think we should use a v
radu.velea
2015/05/07 11:21:41
Done.
|
| + for (compressed_size = 0; compressed_size < kImageWidth * kImageHeight; |
| + compressed_size++) { |
| + if (dst_32[compressed_size] == kImagePoison) { |
| + compressed_size = |
| + compressed_size * 4; /* size in bytes of the compressed block */ |
| + break; |
| + } |
| + } |
| + |
| + /* Check if compression ratio is 8:1 for RGBA or BGRA images, after discarding |
| + * alpha channel */ |
|
reveman
2015/05/06 18:44:02
nit: comment style
|
| + EXPECT_EQ(compressed_size * 8, kImageSizeInBytes); |
|
reveman
2015/05/06 18:44:02
expected value should be the first parameter
radu.velea
2015/05/07 11:21:41
Done.
|
| +} |
| + |
| +} // namespace |
| +} // namespace cc |