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" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 SkAutoPixmapStorage pixmap; | 56 SkAutoPixmapStorage pixmap; |
57 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); | 57 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); |
58 // leaving the pixels uninitialized, as they don't affect the test... | 58 // leaving the pixels uninitialized, as they don't affect the test... |
59 | 59 |
60 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 60 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
61 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 61 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
62 if (!compresses_a8(fmt)) { | 62 if (!compresses_a8(fmt)) { |
63 continue; | 63 continue; |
64 } | 64 } |
65 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 65 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); |
66 REPORTER_ASSERT(reporter, NULL == data); | 66 REPORTER_ASSERT(reporter, nullptr == data); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 /** | 70 /** |
71 * Make sure that we properly fail when we don't have the correct bitmap type. | 71 * Make sure that we properly fail when we don't have the correct bitmap type. |
72 * compressed textures can (currently) only be created from A8 bitmaps. | 72 * compressed textures can (currently) only be created from A8 bitmaps. |
73 */ | 73 */ |
74 DEF_TEST(CompressAlphaFailColorType, reporter) { | 74 DEF_TEST(CompressAlphaFailColorType, reporter) { |
75 static const int kWidth = 12; | 75 static const int kWidth = 12; |
76 static const int kHeight = 12; | 76 static const int kHeight = 12; |
77 | 77 |
78 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e | 78 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e |
79 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t | 79 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t |
80 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | 80 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would |
81 // need to be updated. | 81 // need to be updated. |
82 REPORTER_ASSERT(reporter, kWidth % 12 == 0); | 82 REPORTER_ASSERT(reporter, kWidth % 12 == 0); |
83 REPORTER_ASSERT(reporter, kHeight % 12 == 0); | 83 REPORTER_ASSERT(reporter, kHeight % 12 == 0); |
84 | 84 |
85 SkAutoPixmapStorage pixmap; | 85 SkAutoPixmapStorage pixmap; |
86 pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); | 86 pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); |
87 // leaving the pixels uninitialized, as they don't affect the test... | 87 // leaving the pixels uninitialized, as they don't affect the test... |
88 | 88 |
89 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 89 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
90 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 90 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
91 if (!compresses_a8(fmt)) { | 91 if (!compresses_a8(fmt)) { |
92 continue; | 92 continue; |
93 } | 93 } |
94 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 94 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); |
95 REPORTER_ASSERT(reporter, NULL == data); | 95 REPORTER_ASSERT(reporter, nullptr == data); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 /** | 99 /** |
100 * Make sure that if you compress a texture with alternating black/white pixels,
and | 100 * Make sure that if you compress a texture with alternating black/white pixels,
and |
101 * then decompress it, you get what you started with. | 101 * then decompress it, you get what you started with. |
102 */ | 102 */ |
103 DEF_TEST(CompressCheckerboard, reporter) { | 103 DEF_TEST(CompressCheckerboard, reporter) { |
104 static const int kWidth = 48; // We need the number to be divisible by both | 104 static const int kWidth = 48; // We need the number to be divisible by both |
105 static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC). | 105 static const int kHeight = 48; // 12 (ASTC) and 16 (ARM NEON R11 EAC). |
106 | 106 |
107 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e | 107 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e |
108 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t | 108 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t |
109 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | 109 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would |
110 // need to be updated. Additionally, ARM NEON and SSE code paths support up
to | 110 // need to be updated. Additionally, ARM NEON and SSE code paths support up
to |
111 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence,
the | 111 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence,
the |
112 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3
= 48 | 112 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3
= 48 |
113 REPORTER_ASSERT(reporter, kWidth % 48 == 0); | 113 REPORTER_ASSERT(reporter, kWidth % 48 == 0); |
114 REPORTER_ASSERT(reporter, kHeight % 48 == 0); | 114 REPORTER_ASSERT(reporter, kHeight % 48 == 0); |
115 | 115 |
116 SkAutoPixmapStorage pixmap; | 116 SkAutoPixmapStorage pixmap; |
117 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); | 117 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); |
118 | 118 |
119 // Populate the pixels | 119 // Populate the pixels |
120 { | 120 { |
121 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); | 121 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); |
122 REPORTER_ASSERT(reporter, pixels); | 122 REPORTER_ASSERT(reporter, pixels); |
123 if (NULL == pixels) { | 123 if (nullptr == pixels) { |
124 return; | 124 return; |
125 } | 125 } |
126 | 126 |
127 for (int y = 0; y < kHeight; ++y) { | 127 for (int y = 0; y < kHeight; ++y) { |
128 for (int x = 0; x < kWidth; ++x) { | 128 for (int x = 0; x < kWidth; ++x) { |
129 if ((x ^ y) & 1) { | 129 if ((x ^ y) & 1) { |
130 pixels[x] = 0xFF; | 130 pixels[x] = 0xFF; |
131 } else { | 131 } else { |
132 pixels[x] = 0; | 132 pixels[x] = 0; |
133 } | 133 } |
134 } | 134 } |
135 pixels += pixmap.rowBytes(); | 135 pixels += pixmap.rowBytes(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 SkAutoMalloc decompMemory(kWidth*kHeight); | 139 SkAutoMalloc decompMemory(kWidth*kHeight); |
140 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); | 140 uint8_t* decompBuffer = reinterpret_cast<uint8_t*>(decompMemory.get()); |
141 REPORTER_ASSERT(reporter, decompBuffer); | 141 REPORTER_ASSERT(reporter, decompBuffer); |
142 if (NULL == decompBuffer) { | 142 if (nullptr == decompBuffer) { |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 146 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
147 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 147 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
148 | 148 |
149 // Ignore formats for RGBA data, since the decompressed buffer | 149 // Ignore formats for RGBA data, since the decompressed buffer |
150 // won't match the size and contents of the original. | 150 // won't match the size and contents of the original. |
151 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { | 151 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { |
152 continue; | 152 continue; |
153 } | 153 } |
154 | 154 |
155 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 155 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); |
156 REPORTER_ASSERT(reporter, data); | 156 REPORTER_ASSERT(reporter, data); |
157 if (NULL == data) { | 157 if (nullptr == data) { |
158 continue; | 158 continue; |
159 } | 159 } |
160 | 160 |
161 bool decompResult = | 161 bool decompResult = |
162 SkTextureCompressor::DecompressBufferFromFormat( | 162 SkTextureCompressor::DecompressBufferFromFormat( |
163 decompBuffer, kWidth, | 163 decompBuffer, kWidth, |
164 data->bytes(), | 164 data->bytes(), |
165 kWidth, kHeight, fmt); | 165 kWidth, kHeight, fmt); |
166 REPORTER_ASSERT(reporter, decompResult); | 166 REPORTER_ASSERT(reporter, decompResult); |
167 | 167 |
168 const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr()); | 168 const uint8_t* pixels = reinterpret_cast<const uint8_t*>(pixmap.addr()); |
169 REPORTER_ASSERT(reporter, pixels); | 169 REPORTER_ASSERT(reporter, pixels); |
170 if (NULL == pixels) { | 170 if (nullptr == pixels) { |
171 continue; | 171 continue; |
172 } | 172 } |
173 | 173 |
174 for (int y = 0; y < kHeight; ++y) { | 174 for (int y = 0; y < kHeight; ++y) { |
175 for (int x = 0; x < kWidth; ++x) { | 175 for (int x = 0; x < kWidth; ++x) { |
176 bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWid
th + x]; | 176 bool ok = pixels[y*pixmap.rowBytes() + x] == decompBuffer[y*kWid
th + x]; |
177 REPORTER_ASSERT(reporter, ok); | 177 REPORTER_ASSERT(reporter, ok); |
178 } | 178 } |
179 } | 179 } |
180 } | 180 } |
(...skipping 25 matching lines...) Expand all Loading... |
206 | 206 |
207 for (int lum = 0; lum < 256; ++lum) { | 207 for (int lum = 0; lum < 256; ++lum) { |
208 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); | 208 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); |
209 for (int i = 0; i < kWidth*kHeight; ++i) { | 209 for (int i = 0; i < kWidth*kHeight; ++i) { |
210 pixels[i] = lum; | 210 pixels[i] = lum; |
211 } | 211 } |
212 | 212 |
213 SkAutoDataUnref latcData( | 213 SkAutoDataUnref latcData( |
214 SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); | 214 SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); |
215 REPORTER_ASSERT(reporter, latcData); | 215 REPORTER_ASSERT(reporter, latcData); |
216 if (NULL == latcData) { | 216 if (nullptr == latcData) { |
217 continue; | 217 continue; |
218 } | 218 } |
219 | 219 |
220 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); | 220 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); |
221 | 221 |
222 // Make sure that it all matches a given block encoding. Since we have | 222 // Make sure that it all matches a given block encoding. Since we have |
223 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing | 223 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing |
224 // an approximation scheme that optimizes for speed against coverage map
s. | 224 // an approximation scheme that optimizes for speed against coverage map
s. |
225 // That means that each palette in the encoded block is exactly the same
, | 225 // That means that each palette in the encoded block is exactly the same
, |
226 // and that the three bits saved per pixel are computed from the top thr
ee | 226 // and that the three bits saved per pixel are computed from the top thr
ee |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 266 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
267 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 267 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
268 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 268 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
269 | 269 |
270 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 270 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
271 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 271 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
272 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 272 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
273 } | 273 } |
274 } | 274 } |
275 } | 275 } |
OLD | NEW |