Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: cc/resources/texture_compressor_unittest.cc

Issue 1096703002: Reland: Add ETC1 powered SSE encoder for tile texture compression (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
reveman 2015/05/05 15:30:11 If this is supposed to contain generic texture com
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 #define TEST_IMAGE_WIDTH 256
14 #define TEST_IMAGE_HEIGHT 256
15 #define TEST_IMAGE_CHANNELS 4
16 #define TEST_IMAGE_SIZE \
17 (TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * TEST_IMAGE_CHANNELS)
18
19 #define TEST_IMAGE_POISON 0xDEADBEEF
20 #define TEST_PIXEL_LIMIT 256
reveman 2015/05/05 15:30:11 please use constants instead of defines. and maybe
21
22 TEST(TextureCompressorTest, CreateETC1) {
23 scoped_ptr<TextureCompressor> compressor =
24 TextureCompressor::Create(TextureCompressor::kFormatETC1);
25 EXPECT_NE(nullptr, compressor);
26 }
27
28 TEST(TextureCompressorTest, CompressRatioETC1) {
29 scoped_ptr<TextureCompressor> compressor =
30 TextureCompressor::Create(TextureCompressor::kFormatETC1);
31 uint8_t src[TEST_IMAGE_SIZE];
32 uint8_t dst[TEST_IMAGE_SIZE];
33 int compressed_size = 0;
34
35 /* Poison destination bytes */
36 uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst);
37 for (int i = 0; i < TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT; i++) {
38 dst_32[i] = TEST_IMAGE_POISON;
39 }
40
41 /* Generate test texture */
42 for (int i = 0; i < TEST_IMAGE_SIZE; i++) {
43 src[i] = i % TEST_PIXEL_LIMIT;
44 }
45
46 compressor->Compress(src, dst, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT,
47 (TextureCompressor::Quality)0);
48 for (compressed_size = 0;
49 compressed_size < TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT;
50 compressed_size++) {
51 if (dst_32[compressed_size] == TEST_IMAGE_POISON) {
52 compressed_size =
53 compressed_size * 4; /* size in bytes of the compressed block */
54 break;
55 }
56 }
57
58 /* Check if compression ratio is 8:1 for RGBA or BGRA images, after discarding
59 * alpha channel */
60 EXPECT_EQ(compressed_size * 8, TEST_IMAGE_SIZE);
61 }
62
63 } // namespace
64 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698