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