Chromium Code Reviews| 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 "cc/resources/texture_compressor.h" | |
| 6 | |
| 7 #include "cc/base/util.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace cc { | |
| 11 namespace { | |
| 12 | |
| 13 const int kImageWidth = 256; | |
| 14 const int kImageHeight = 256; | |
| 15 const int kImageChannels = 4; | |
| 16 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels; | |
| 17 | |
| 18 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
| |
| 19 scoped_ptr<TextureCompressor> compressor = | |
| 20 TextureCompressor::Create(TextureCompressor::kFormatETC1); | |
| 21 EXPECT_NE(nullptr, compressor); | |
| 22 } | |
| 23 | |
| 24 TEST(TextureCompressorETC1Test, Compress256x256RatioETC1) { | |
|
reveman
2015/05/06 18:44:02
s/Compress256x256RatioETC1/Compress256x256Ratio/ a
| |
| 25 scoped_ptr<TextureCompressor> compressor = | |
| 26 TextureCompressor::Create(TextureCompressor::kFormatETC1); | |
| 27 uint8_t src[kImageSizeInBytes]; | |
| 28 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
| |
| 29 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.
| |
| 30 const unsigned int kImagePoison = 0xDEADBEEF; | |
| 31 | |
| 32 /* Poison destination bytes */ | |
|
reveman
2015/05/06 18:44:02
nit: comment style
radu.velea
2015/05/07 11:21:41
Done.
| |
| 33 uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst); | |
| 34 for (int i = 0; i < kImageWidth * kImageHeight; i++) { | |
| 35 dst_32[i] = kImagePoison; | |
| 36 } | |
| 37 | |
| 38 /* Generate test texture */ | |
|
reveman
2015/05/06 18:44:02
nit: comment style
radu.velea
2015/05/07 11:21:41
Done.
| |
| 39 for (int i = 0; i < kImageSizeInBytes; i++) { | |
| 40 src[i] = i % 256; | |
| 41 } | |
| 42 | |
| 43 compressor->Compress(src, dst, kImageWidth, kImageHeight, | |
| 44 (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.
| |
| 45 for (compressed_size = 0; compressed_size < kImageWidth * kImageHeight; | |
| 46 compressed_size++) { | |
| 47 if (dst_32[compressed_size] == kImagePoison) { | |
| 48 compressed_size = | |
| 49 compressed_size * 4; /* size in bytes of the compressed block */ | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 /* Check if compression ratio is 8:1 for RGBA or BGRA images, after discarding | |
| 55 * alpha channel */ | |
|
reveman
2015/05/06 18:44:02
nit: comment style
| |
| 56 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.
| |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 } // namespace cc | |
| OLD | NEW |