Update V8 to version 4.7.42.
[chromium-blink-merge.git] / cc / raster / texture_compressor_etc1_unittest.cc
blobd0c63f46f633284fd30407b9167cd88d1b89da19
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 "cc/raster/texture_compressor.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace cc {
10 namespace {
12 const int kImageWidth = 256;
13 const int kImageHeight = 256;
14 const int kImageChannels = 4;
15 const int kImageSizeInBytes = kImageWidth * kImageHeight * kImageChannels;
17 TEST(TextureCompressorETC1Test, Compress256x256Ratio) {
18 scoped_ptr<TextureCompressor> compressor =
19 TextureCompressor::Create(TextureCompressor::kFormatETC1);
20 uint8_t src[kImageSizeInBytes];
21 uint8_t dst[kImageSizeInBytes];
22 const unsigned int kImagePoison = 0xDEADBEEF;
24 // Poison destination bytes so we can see how much has been
25 // overwritten by compression algorithm.
26 uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst);
27 for (int i = 0; i < kImageWidth * kImageHeight; i++) {
28 dst_32[i] = kImagePoison;
31 // Generate test texture.
32 for (int i = 0; i < kImageSizeInBytes; i++) {
33 src[i] = i % 256;
36 compressor->Compress(src, dst, kImageWidth, kImageHeight,
37 TextureCompressor::kQualityLow);
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 // Represents size in bytes of the compressed block.
44 compressed_size = compressed_size * 4;
45 break;
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);
54 } // namespace
55 } // namespace cc