OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkEndian.h" | 10 #include "SkEndian.h" |
11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
12 #include "SkTextureCompressor.h" | 12 #include "SkTextureCompressor.h" |
13 #include "Test.h" | 13 #include "Test.h" |
14 | 14 |
15 // TODO: Create separate tests for RGB and RGBA data once | |
16 // ASTC and ETC1 decompression is implemented. | |
17 | |
18 static bool decompresses_a8(SkTextureCompressor::Format fmt) { | |
19 switch (fmt) { | |
20 case SkTextureCompressor::kLATC_Format: | |
21 case SkTextureCompressor::kR11_EAC_Format: | |
22 return true; | |
23 | |
24 default: | |
25 return false; | |
26 } | |
27 } | |
28 | |
29 static bool compresses_a8(SkTextureCompressor::Format fmt) { | |
30 switch (fmt) { | |
31 case SkTextureCompressor::kLATC_Format: | |
32 case SkTextureCompressor::kR11_EAC_Format: | |
33 case SkTextureCompressor::kASTC_12x12_Format: | |
34 return true; | |
35 | |
36 default: | |
37 return false; | |
38 } | |
39 } | |
40 | |
41 /** | 15 /** |
42 * Make sure that we properly fail when we don't have multiple of four image dim
ensions. | 16 * Make sure that we properly fail when we don't have multiple of four image dim
ensions. |
43 */ | 17 */ |
44 DEF_TEST(CompressAlphaFailDimensions, reporter) { | 18 DEF_TEST(CompressAlphaFailDimensions, reporter) { |
45 SkBitmap bitmap; | 19 SkBitmap bitmap; |
46 static const int kWidth = 17; | 20 static const int kWidth = 17; |
47 static const int kHeight = 17; | 21 static const int kHeight = 17; |
48 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); | 22 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); |
49 | 23 |
50 // R11_EAC and LATC are both dimensions of 4, so we need to make sure that w
e | 24 // R11_EAC and LATC are both dimensions of 4, so we need to make sure that w
e |
51 // are violating those assumptions. And if we are, then we're also violating
the | 25 // are violating those assumptions. And if we are, then we're also violating
the |
52 // assumptions of ASTC, which is 12x12 since any number not divisible by 4 i
s | 26 // assumptions of ASTC, which is 12x12 since any number not divisible by 4 i
s |
53 // also not divisible by 12. Our dimensions are prime, so any block dimensio
n | 27 // also not divisible by 12. Our dimensions are prime, so any block dimensio
n |
54 // larger than 1 should fail. | 28 // larger than 1 should fail. |
55 REPORTER_ASSERT(reporter, kWidth % 4 != 0); | 29 REPORTER_ASSERT(reporter, kWidth % 4 != 0); |
56 REPORTER_ASSERT(reporter, kHeight % 4 != 0); | 30 REPORTER_ASSERT(reporter, kHeight % 4 != 0); |
57 | 31 |
58 bool setInfoSuccess = bitmap.setInfo(info); | 32 bool setInfoSuccess = bitmap.setInfo(info); |
59 REPORTER_ASSERT(reporter, setInfoSuccess); | 33 REPORTER_ASSERT(reporter, setInfoSuccess); |
60 | 34 |
61 bool allocPixelsSuccess = bitmap.allocPixels(info); | 35 bool allocPixelsSuccess = bitmap.allocPixels(info); |
62 REPORTER_ASSERT(reporter, allocPixelsSuccess); | 36 REPORTER_ASSERT(reporter, allocPixelsSuccess); |
63 bitmap.unlockPixels(); | 37 bitmap.unlockPixels(); |
64 | 38 |
65 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 39 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
66 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 40 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
67 if (!compresses_a8(fmt)) { | |
68 continue; | |
69 } | |
70 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 41 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
71 REPORTER_ASSERT(reporter, NULL == data); | 42 REPORTER_ASSERT(reporter, NULL == data); |
72 } | 43 } |
73 } | 44 } |
74 | 45 |
75 /** | 46 /** |
76 * Make sure that we properly fail when we don't have the correct bitmap type. | 47 * Make sure that we properly fail when we don't have the correct bitmap type. |
77 * compressed textures can (currently) only be created from A8 bitmaps. | 48 * compressed textures can (currently) only be created from A8 bitmaps. |
78 */ | 49 */ |
79 DEF_TEST(CompressAlphaFailColorType, reporter) { | 50 DEF_TEST(CompressAlphaFailColorType, reporter) { |
(...skipping 11 matching lines...) Expand all Loading... |
91 | 62 |
92 bool setInfoSuccess = bitmap.setInfo(info); | 63 bool setInfoSuccess = bitmap.setInfo(info); |
93 REPORTER_ASSERT(reporter, setInfoSuccess); | 64 REPORTER_ASSERT(reporter, setInfoSuccess); |
94 | 65 |
95 bool allocPixelsSuccess = bitmap.allocPixels(info); | 66 bool allocPixelsSuccess = bitmap.allocPixels(info); |
96 REPORTER_ASSERT(reporter, allocPixelsSuccess); | 67 REPORTER_ASSERT(reporter, allocPixelsSuccess); |
97 bitmap.unlockPixels(); | 68 bitmap.unlockPixels(); |
98 | 69 |
99 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 70 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
100 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 71 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
101 if (!compresses_a8(fmt)) { | |
102 continue; | |
103 } | |
104 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 72 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
105 REPORTER_ASSERT(reporter, NULL == data); | 73 REPORTER_ASSERT(reporter, NULL == data); |
106 } | 74 } |
107 } | 75 } |
108 | 76 |
109 /** | 77 /** |
110 * Make sure that if you compress a texture with alternating black/white pixels,
and | 78 * Make sure that if you compress a texture with alternating black/white pixels,
and |
111 * then decompress it, you get what you started with. | 79 * then decompress it, you get what you started with. |
112 */ | 80 */ |
113 DEF_TEST(CompressCheckerboard, reporter) { | 81 DEF_TEST(CompressCheckerboard, reporter) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 REPORTER_ASSERT(reporter, NULL != decompBuffer); | 127 REPORTER_ASSERT(reporter, NULL != decompBuffer); |
160 if (NULL == decompBuffer) { | 128 if (NULL == decompBuffer) { |
161 return; | 129 return; |
162 } | 130 } |
163 | 131 |
164 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 132 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
165 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 133 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
166 | 134 |
167 // Ignore formats for RGBA data, since the decompressed buffer | 135 // Ignore formats for RGBA data, since the decompressed buffer |
168 // won't match the size and contents of the original. | 136 // won't match the size and contents of the original. |
169 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { | 137 // TODO: Create separate tests for RGB and RGBA data once |
| 138 // ASTC and ETC1 decompression is implemented. |
| 139 if (SkTextureCompressor::kASTC_12x12_Format == fmt || |
| 140 SkTextureCompressor::kETC1_Format == fmt) { |
170 continue; | 141 continue; |
171 } | 142 } |
172 | 143 |
173 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 144 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
174 REPORTER_ASSERT(reporter, NULL != data); | 145 REPORTER_ASSERT(reporter, NULL != data); |
175 if (NULL == data) { | 146 if (NULL == data) { |
176 continue; | 147 continue; |
177 } | 148 } |
178 | 149 |
179 bool decompResult = | 150 bool decompResult = |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 238 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
268 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 239 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
269 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 240 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
270 | 241 |
271 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 242 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
272 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 243 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
273 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 244 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
274 } | 245 } |
275 } | 246 } |
276 } | 247 } |
OLD | NEW |