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 "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkData.h" | 10 #include "SkData.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 SkAutoPixmapStorage pixmap; | 58 SkAutoPixmapStorage pixmap; |
59 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); | 59 pixmap.alloc(SkImageInfo::MakeA8(kWidth, kHeight)); |
60 // leaving the pixels uninitialized, as they don't affect the test... | 60 // leaving the pixels uninitialized, as they don't affect the test... |
61 | 61 |
62 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 62 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
63 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 63 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
64 if (!compresses_a8(fmt)) { | 64 if (!compresses_a8(fmt)) { |
65 continue; | 65 continue; |
66 } | 66 } |
67 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 67 sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, f
mt)); |
68 REPORTER_ASSERT(reporter, nullptr == data); | 68 REPORTER_ASSERT(reporter, nullptr == data); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 /** | 72 /** |
73 * Make sure that we properly fail when we don't have the correct bitmap type. | 73 * Make sure that we properly fail when we don't have the correct bitmap type. |
74 * compressed textures can (currently) only be created from A8 bitmaps. | 74 * compressed textures can (currently) only be created from A8 bitmaps. |
75 */ | 75 */ |
76 DEF_TEST(CompressAlphaFailColorType, reporter) { | 76 DEF_TEST(CompressAlphaFailColorType, reporter) { |
77 static const int kWidth = 12; | 77 static const int kWidth = 12; |
78 static const int kHeight = 12; | 78 static const int kHeight = 12; |
79 | 79 |
80 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e | 80 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e |
81 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t | 81 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t |
82 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | 82 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would |
83 // need to be updated. | 83 // need to be updated. |
84 REPORTER_ASSERT(reporter, kWidth % 12 == 0); | 84 REPORTER_ASSERT(reporter, kWidth % 12 == 0); |
85 REPORTER_ASSERT(reporter, kHeight % 12 == 0); | 85 REPORTER_ASSERT(reporter, kHeight % 12 == 0); |
86 | 86 |
87 SkAutoPixmapStorage pixmap; | 87 SkAutoPixmapStorage pixmap; |
88 pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); | 88 pixmap.alloc(SkImageInfo::MakeN32Premul(kWidth, kHeight)); |
89 // leaving the pixels uninitialized, as they don't affect the test... | 89 // leaving the pixels uninitialized, as they don't affect the test... |
90 | 90 |
91 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 91 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
92 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 92 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
93 if (!compresses_a8(fmt)) { | 93 if (!compresses_a8(fmt)) { |
94 continue; | 94 continue; |
95 } | 95 } |
96 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 96 sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, f
mt)); |
97 REPORTER_ASSERT(reporter, nullptr == data); | 97 REPORTER_ASSERT(reporter, nullptr == data); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 /** | 101 /** |
102 * Make sure that if you compress a texture with alternating black/white pixels,
and | 102 * Make sure that if you compress a texture with alternating black/white pixels,
and |
103 * then decompress it, you get what you started with. | 103 * then decompress it, you get what you started with. |
104 */ | 104 */ |
105 DEF_TEST(CompressCheckerboard, reporter) { | 105 DEF_TEST(CompressCheckerboard, reporter) { |
106 static const int kWidth = 48; // We need the number to be divisible by both | 106 static const int kWidth = 48; // We need the number to be divisible by both |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 148 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
149 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 149 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
150 | 150 |
151 // Ignore formats for RGBA data, since the decompressed buffer | 151 // Ignore formats for RGBA data, since the decompressed buffer |
152 // won't match the size and contents of the original. | 152 // won't match the size and contents of the original. |
153 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { | 153 if (!decompresses_a8(fmt) || !compresses_a8(fmt)) { |
154 continue; | 154 continue; |
155 } | 155 } |
156 | 156 |
157 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(pixmap,
fmt)); | 157 sk_sp<SkData> data(SkTextureCompressor::CompressBitmapToFormat(pixmap, f
mt)); |
158 REPORTER_ASSERT(reporter, data); | 158 REPORTER_ASSERT(reporter, data); |
159 if (nullptr == data) { | 159 if (nullptr == data) { |
160 continue; | 160 continue; |
161 } | 161 } |
162 | 162 |
163 bool decompResult = | 163 bool decompResult = |
164 SkTextureCompressor::DecompressBufferFromFormat( | 164 SkTextureCompressor::DecompressBufferFromFormat( |
165 decompBuffer, kWidth, | 165 decompBuffer, kWidth, |
166 data->bytes(), | 166 data->bytes(), |
167 kWidth, kHeight, fmt); | 167 kWidth, kHeight, fmt); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; | 205 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; |
206 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); | 206 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); |
207 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); | 207 REPORTER_ASSERT(reporter, (kSizeToBe % kLATCEncodedBlockSize) == 0); |
208 | 208 |
209 for (int lum = 0; lum < 256; ++lum) { | 209 for (int lum = 0; lum < 256; ++lum) { |
210 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); | 210 uint8_t* pixels = reinterpret_cast<uint8_t*>(pixmap.writable_addr()); |
211 for (int i = 0; i < kWidth*kHeight; ++i) { | 211 for (int i = 0; i < kWidth*kHeight; ++i) { |
212 pixels[i] = lum; | 212 pixels[i] = lum; |
213 } | 213 } |
214 | 214 |
215 SkAutoDataUnref latcData( | 215 sk_sp<SkData> latcData( |
216 SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); | 216 SkTextureCompressor::CompressBitmapToFormat(pixmap, kLATCFormat)); |
217 REPORTER_ASSERT(reporter, latcData); | 217 REPORTER_ASSERT(reporter, latcData); |
218 if (nullptr == latcData) { | 218 if (nullptr == latcData) { |
219 continue; | 219 continue; |
220 } | 220 } |
221 | 221 |
222 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); | 222 REPORTER_ASSERT(reporter, kSizeToBe == latcData->size()); |
223 | 223 |
224 // Make sure that it all matches a given block encoding. Since we have | 224 // Make sure that it all matches a given block encoding. Since we have |
225 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing | 225 // COMPRESS_LATC_FAST defined in SkTextureCompressor_LATC.cpp, we are us
ing |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 268 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
269 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 269 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
270 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 270 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
271 | 271 |
272 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 272 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
273 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 273 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
274 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 274 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
275 } | 275 } |
276 } | 276 } |
277 } | 277 } |
OLD | NEW |