| 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 "SkTextureCompressor.h" | 8 #include "SkTextureCompressor.h" |
| 9 #include "SkTextureCompressor_ASTC.h" | 9 #include "SkTextureCompressor_ASTC.h" |
| 10 #include "SkTextureCompressor_LATC.h" | 10 #include "SkTextureCompressor_LATC.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (proc) { | 169 if (proc) { |
| 170 return proc(dst, src, width, height, rowBytes); | 170 return proc(dst, src, width, height, rowBytes); |
| 171 } | 171 } |
| 172 | 172 |
| 173 return false; | 173 return false; |
| 174 } | 174 } |
| 175 | 175 |
| 176 SkData *CompressBitmapToFormat(const SkBitmap &bitmap, Format format) { | 176 SkData* CompressBitmapToFormat(const SkBitmap &bitmap, Format format) { |
| 177 SkAutoLockPixels alp(bitmap); | 177 SkAutoLockPixels alp(bitmap); |
| 178 | 178 |
| 179 int compressedDataSize = GetCompressedDataSize(format, bitmap.width(), bitma
p.height()); | 179 int compressedDataSize = GetCompressedDataSize(format, bitmap.width(), bitma
p.height()); |
| 180 if (compressedDataSize < 0) { | 180 if (compressedDataSize < 0) { |
| 181 return NULL; | 181 return NULL; |
| 182 } | 182 } |
| 183 | 183 |
| 184 const uint8_t* src = reinterpret_cast<const uint8_t*>(bitmap.getPixels()); | 184 const uint8_t* src = reinterpret_cast<const uint8_t*>(bitmap.getPixels()); |
| 185 uint8_t* dst = reinterpret_cast<uint8_t*>(sk_malloc_throw(compressedDataSize
)); | 185 SkData* dst = SkData::NewUninitialized(compressedDataSize); |
| 186 | 186 |
| 187 if (CompressBufferToFormat(dst, src, bitmap.colorType(), bitmap.width(), bit
map.height(), | 187 if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, bitmap.colo
rType(), |
| 188 bitmap.rowBytes(), format)) { | 188 bitmap.width(), bitmap.height(), bitmap.rowBytes
(), format)) { |
| 189 return SkData::NewFromMalloc(dst, compressedDataSize); | 189 dst->unref(); |
| 190 dst = NULL; |
| 190 } | 191 } |
| 191 | 192 return dst; |
| 192 sk_free(dst); | |
| 193 return NULL; | |
| 194 } | 193 } |
| 195 | 194 |
| 196 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer, | 195 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer, |
| 197 SkTBlitterAllocator *allocator, Format format)
{ | 196 SkTBlitterAllocator *allocator, Format format)
{ |
| 198 switch(format) { | 197 switch(format) { |
| 199 case kLATC_Format: | 198 case kLATC_Format: |
| 200 return CreateLATCBlitter(width, height, compressedBuffer, allocator)
; | 199 return CreateLATCBlitter(width, height, compressedBuffer, allocator)
; |
| 201 | 200 |
| 202 case kR11_EAC_Format: | 201 case kR11_EAC_Format: |
| 203 return CreateR11EACBlitter(width, height, compressedBuffer, allocato
r); | 202 return CreateR11EACBlitter(width, height, compressedBuffer, allocato
r); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 253 |
| 255 default: | 254 default: |
| 256 // Do nothing... | 255 // Do nothing... |
| 257 break; | 256 break; |
| 258 } | 257 } |
| 259 | 258 |
| 260 return false; | 259 return false; |
| 261 } | 260 } |
| 262 | 261 |
| 263 } // namespace SkTextureCompressor | 262 } // namespace SkTextureCompressor |
| OLD | NEW |