| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // 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 |
| 52 // 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 |
| 53 // 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 |
| 54 // larger than 1 should fail. | 54 // larger than 1 should fail. |
| 55 REPORTER_ASSERT(reporter, kWidth % 4 != 0); | 55 REPORTER_ASSERT(reporter, kWidth % 4 != 0); |
| 56 REPORTER_ASSERT(reporter, kHeight % 4 != 0); | 56 REPORTER_ASSERT(reporter, kHeight % 4 != 0); |
| 57 | 57 |
| 58 bool setInfoSuccess = bitmap.setInfo(info); | 58 bool setInfoSuccess = bitmap.setInfo(info); |
| 59 REPORTER_ASSERT(reporter, setInfoSuccess); | 59 REPORTER_ASSERT(reporter, setInfoSuccess); |
| 60 | 60 |
| 61 bool allocPixelsSuccess = bitmap.allocPixels(info); | 61 bitmap.allocPixels(info); |
| 62 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 63 bitmap.unlockPixels(); | 62 bitmap.unlockPixels(); |
| 64 | 63 |
| 65 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 64 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
| 66 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 65 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
| 67 if (!compresses_a8(fmt)) { | 66 if (!compresses_a8(fmt)) { |
| 68 continue; | 67 continue; |
| 69 } | 68 } |
| 70 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 69 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
| 71 REPORTER_ASSERT(reporter, NULL == data); | 70 REPORTER_ASSERT(reporter, NULL == data); |
| 72 } | 71 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 85 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e | 84 // ASTC is at most 12x12, and any dimension divisible by 12 is also divisibl
e |
| 86 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t | 85 // by 4, which is the dimensions of R11_EAC and LATC. In the future, we migh
t |
| 87 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | 86 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would |
| 88 // need to be updated. | 87 // need to be updated. |
| 89 REPORTER_ASSERT(reporter, kWidth % 12 == 0); | 88 REPORTER_ASSERT(reporter, kWidth % 12 == 0); |
| 90 REPORTER_ASSERT(reporter, kHeight % 12 == 0); | 89 REPORTER_ASSERT(reporter, kHeight % 12 == 0); |
| 91 | 90 |
| 92 bool setInfoSuccess = bitmap.setInfo(info); | 91 bool setInfoSuccess = bitmap.setInfo(info); |
| 93 REPORTER_ASSERT(reporter, setInfoSuccess); | 92 REPORTER_ASSERT(reporter, setInfoSuccess); |
| 94 | 93 |
| 95 bool allocPixelsSuccess = bitmap.allocPixels(info); | 94 bitmap.allocPixels(info); |
| 96 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 97 bitmap.unlockPixels(); | 95 bitmap.unlockPixels(); |
| 98 | 96 |
| 99 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { | 97 for (int i = 0; i < SkTextureCompressor::kFormatCnt; ++i) { |
| 100 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); | 98 const SkTextureCompressor::Format fmt = static_cast<SkTextureCompressor:
:Format>(i); |
| 101 if (!compresses_a8(fmt)) { | 99 if (!compresses_a8(fmt)) { |
| 102 continue; | 100 continue; |
| 103 } | 101 } |
| 104 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); | 102 SkAutoDataUnref data(SkTextureCompressor::CompressBitmapToFormat(bitmap,
fmt)); |
| 105 REPORTER_ASSERT(reporter, NULL == data); | 103 REPORTER_ASSERT(reporter, NULL == data); |
| 106 } | 104 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 121 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would | 119 // support additional variants of ASTC, such as 5x6 and 8x8, in which case t
his would |
| 122 // need to be updated. Additionally, ARM NEON and SSE code paths support up
to | 120 // need to be updated. Additionally, ARM NEON and SSE code paths support up
to |
| 123 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence,
the | 121 // four blocks of R11 EAC at once, so they operate on 16-wide blocks. Hence,
the |
| 124 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3
= 48 | 122 // valid width and height is going to be the LCM of 12 and 16 which is 4*4*3
= 48 |
| 125 REPORTER_ASSERT(reporter, kWidth % 48 == 0); | 123 REPORTER_ASSERT(reporter, kWidth % 48 == 0); |
| 126 REPORTER_ASSERT(reporter, kHeight % 48 == 0); | 124 REPORTER_ASSERT(reporter, kHeight % 48 == 0); |
| 127 | 125 |
| 128 bool setInfoSuccess = bitmap.setInfo(info); | 126 bool setInfoSuccess = bitmap.setInfo(info); |
| 129 REPORTER_ASSERT(reporter, setInfoSuccess); | 127 REPORTER_ASSERT(reporter, setInfoSuccess); |
| 130 | 128 |
| 131 bool allocPixelsSuccess = bitmap.allocPixels(info); | 129 bitmap.allocPixels(info); |
| 132 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 133 bitmap.unlockPixels(); | 130 bitmap.unlockPixels(); |
| 134 | 131 |
| 135 // Populate bitmap | 132 // Populate bitmap |
| 136 { | 133 { |
| 137 SkAutoLockPixels alp(bitmap); | 134 SkAutoLockPixels alp(bitmap); |
| 138 | 135 |
| 139 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); | 136 uint8_t* pixels = reinterpret_cast<uint8_t*>(bitmap.getPixels()); |
| 140 REPORTER_ASSERT(reporter, NULL != pixels); | 137 REPORTER_ASSERT(reporter, NULL != pixels); |
| 141 if (NULL == pixels) { | 138 if (NULL == pixels) { |
| 142 return; | 139 return; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 static const int kLATCEncodedBlockSize = 8; | 205 static const int kLATCEncodedBlockSize = 8; |
| 209 | 206 |
| 210 SkBitmap bitmap; | 207 SkBitmap bitmap; |
| 211 static const int kWidth = 8; | 208 static const int kWidth = 8; |
| 212 static const int kHeight = 8; | 209 static const int kHeight = 8; |
| 213 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); | 210 SkImageInfo info = SkImageInfo::MakeA8(kWidth, kHeight); |
| 214 | 211 |
| 215 bool setInfoSuccess = bitmap.setInfo(info); | 212 bool setInfoSuccess = bitmap.setInfo(info); |
| 216 REPORTER_ASSERT(reporter, setInfoSuccess); | 213 REPORTER_ASSERT(reporter, setInfoSuccess); |
| 217 | 214 |
| 218 bool allocPixelsSuccess = bitmap.allocPixels(info); | 215 bitmap.allocPixels(info); |
| 219 REPORTER_ASSERT(reporter, allocPixelsSuccess); | |
| 220 bitmap.unlockPixels(); | 216 bitmap.unlockPixels(); |
| 221 | 217 |
| 222 int latcDimX, latcDimY; | 218 int latcDimX, latcDimY; |
| 223 SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); | 219 SkTextureCompressor::GetBlockDimensions(kLATCFormat, &latcDimX, &latcDimY); |
| 224 | 220 |
| 225 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0); | 221 REPORTER_ASSERT(reporter, kWidth % latcDimX == 0); |
| 226 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0); | 222 REPORTER_ASSERT(reporter, kHeight % latcDimY == 0); |
| 227 const size_t kSizeToBe = | 223 const size_t kSizeToBe = |
| 228 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; | 224 SkTextureCompressor::GetCompressedDataSize(kLATCFormat, kWidth, kHeight)
; |
| 229 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); | 225 REPORTER_ASSERT(reporter, kSizeToBe == ((kWidth*kHeight*kLATCEncodedBlockSiz
e)/16)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | | 263 (kIndex << 28) | (kIndex << 31) | (kIndex << 34) | (kIndex << 37
) | |
| 268 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | | 264 (kIndex << 40) | (kIndex << 43) | (kIndex << 46) | (kIndex << 49
) | |
| 269 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); | 265 (kIndex << 52) | (kIndex << 55) | (kIndex << 58) | (kIndex << 61
)); |
| 270 | 266 |
| 271 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); | 267 const uint64_t* blockPtr = reinterpret_cast<const uint64_t*>(latcData->d
ata()); |
| 272 for (size_t i = 0; i < (kSizeToBe/8); ++i) { | 268 for (size_t i = 0; i < (kSizeToBe/8); ++i) { |
| 273 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); | 269 REPORTER_ASSERT(reporter, blockPtr[i] == kConstColorEncoding); |
| 274 } | 270 } |
| 275 } | 271 } |
| 276 } | 272 } |
| OLD | NEW |