| 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 17 matching lines...) Expand all Loading... |
| 28 #else | 28 #else |
| 29 return false; | 29 return false; |
| 30 #endif | 30 #endif |
| 31 } | 31 } |
| 32 | 32 |
| 33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 | 34 |
| 35 namespace SkTextureCompressor { | 35 namespace SkTextureCompressor { |
| 36 | 36 |
| 37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { | 37 void GetBlockDimensions(Format format, int* dimX, int* dimY, bool matchSpec) { |
| 38 if (NULL == dimX || NULL == dimY) { | 38 if (nullptr == dimX || nullptr == dimY) { |
| 39 return; | 39 return; |
| 40 } | 40 } |
| 41 | 41 |
| 42 if (!matchSpec && SkOpts::fill_block_dimensions(format, dimX, dimY)) { | 42 if (!matchSpec && SkOpts::fill_block_dimensions(format, dimX, dimY)) { |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // No specialized arguments, return the dimensions as they are in the spec. | 46 // No specialized arguments, return the dimensions as they are in the spec. |
| 47 static const struct FormatDimensions { | 47 static const struct FormatDimensions { |
| 48 const int fBlockSizeX; | 48 const int fBlockSizeX; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 if (proc && proc(dst, src, width, height, rowBytes)) { | 140 if (proc && proc(dst, src, width, height, rowBytes)) { |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 return false; | 144 return false; |
| 145 } | 145 } |
| 146 | 146 |
| 147 SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) { | 147 SkData* CompressBitmapToFormat(const SkPixmap& pixmap, Format format) { |
| 148 int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixma
p.height()); | 148 int compressedDataSize = GetCompressedDataSize(format, pixmap.width(), pixma
p.height()); |
| 149 if (compressedDataSize < 0) { | 149 if (compressedDataSize < 0) { |
| 150 return NULL; | 150 return nullptr; |
| 151 } | 151 } |
| 152 | 152 |
| 153 const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr()); | 153 const uint8_t* src = reinterpret_cast<const uint8_t*>(pixmap.addr()); |
| 154 SkData* dst = SkData::NewUninitialized(compressedDataSize); | 154 SkData* dst = SkData::NewUninitialized(compressedDataSize); |
| 155 | 155 |
| 156 if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colo
rType(), | 156 if (!CompressBufferToFormat((uint8_t*)dst->writable_data(), src, pixmap.colo
rType(), |
| 157 pixmap.width(), pixmap.height(), pixmap.rowBytes
(), format)) { | 157 pixmap.width(), pixmap.height(), pixmap.rowBytes
(), format)) { |
| 158 dst->unref(); | 158 dst->unref(); |
| 159 dst = NULL; | 159 dst = nullptr; |
| 160 } | 160 } |
| 161 return dst; | 161 return dst; |
| 162 } | 162 } |
| 163 | 163 |
| 164 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer, | 164 SkBlitter* CreateBlitterForFormat(int width, int height, void* compressedBuffer, |
| 165 SkTBlitterAllocator *allocator, Format format)
{ | 165 SkTBlitterAllocator *allocator, Format format)
{ |
| 166 switch(format) { | 166 switch(format) { |
| 167 case kLATC_Format: | 167 case kLATC_Format: |
| 168 return CreateLATCBlitter(width, height, compressedBuffer, allocator)
; | 168 return CreateLATCBlitter(width, height, compressedBuffer, allocator)
; |
| 169 | 169 |
| 170 case kR11_EAC_Format: | 170 case kR11_EAC_Format: |
| 171 return CreateR11EACBlitter(width, height, compressedBuffer, allocato
r); | 171 return CreateR11EACBlitter(width, height, compressedBuffer, allocato
r); |
| 172 | 172 |
| 173 case kASTC_12x12_Format: | 173 case kASTC_12x12_Format: |
| 174 return CreateASTCBlitter(width, height, compressedBuffer, allocator)
; | 174 return CreateASTCBlitter(width, height, compressedBuffer, allocator)
; |
| 175 | 175 |
| 176 default: | 176 default: |
| 177 return NULL; | 177 return nullptr; |
| 178 } | 178 } |
| 179 | 179 |
| 180 return NULL; | 180 return nullptr; |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t* sr
c, | 183 bool DecompressBufferFromFormat(uint8_t* dst, int dstRowBytes, const uint8_t* sr
c, |
| 184 int width, int height, Format format) { | 184 int width, int height, Format format) { |
| 185 int dimX, dimY; | 185 int dimX, dimY; |
| 186 GetBlockDimensions(format, &dimX, &dimY, true); | 186 GetBlockDimensions(format, &dimX, &dimY, true); |
| 187 | 187 |
| 188 if (width < 0 || ((width % dimX) != 0) || height < 0 || ((height % dimY) !=
0)) { | 188 if (width < 0 || ((width % dimX) != 0) || height < 0 || ((height % dimY) !=
0)) { |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 222 |
| 223 default: | 223 default: |
| 224 // Do nothing... | 224 // Do nothing... |
| 225 break; | 225 break; |
| 226 } | 226 } |
| 227 | 227 |
| 228 return false; | 228 return false; |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace SkTextureCompressor | 231 } // namespace SkTextureCompressor |
| OLD | NEW |