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, Compress256x256Ratio) { |
| 19 scoped_ptr<TextureCompressor> compressor = |
| 20 TextureCompressor::Create(TextureCompressor::kFormatETC1); |
| 21 uint8_t src[kImageSizeInBytes]; |
| 22 uint8_t dst[kImageSizeInBytes]; |
| 23 const unsigned int kImagePoison = 0xDEADBEEF; |
| 24 |
| 25 // Poison destination bytes |
| 26 uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst); |
| 27 for (int i = 0; i < kImageWidth * kImageHeight; i++) { |
| 28 dst_32[i] = kImagePoison; |
| 29 } |
| 30 |
| 31 // Generate test texture |
| 32 for (int i = 0; i < kImageSizeInBytes; i++) { |
| 33 src[i] = i % 256; |
| 34 } |
| 35 |
| 36 compressor->Compress(src, dst, kImageWidth, kImageHeight, |
| 37 TextureCompressor::kQualityLow); |
| 38 |
| 39 int compressed_size = 0; |
| 40 for (compressed_size = 0; compressed_size < kImageWidth * kImageHeight; |
| 41 compressed_size++) { |
| 42 if (dst_32[compressed_size] == kImagePoison) { |
| 43 compressed_size = |
| 44 compressed_size * 4; // size in bytes of the compressed block |
| 45 break; |
| 46 } |
| 47 } |
| 48 |
| 49 // Check if compression ratio is 8:1 for RGBA or BGRA images, after discarding |
| 50 // alpha channel |
| 51 EXPECT_EQ(kImageSizeInBytes, compressed_size * 8); |
| 52 } |
| 53 |
| 54 } // namespace |
| 55 } // namespace cc |
OLD | NEW |