diff options
author | 2014-06-03 13:04:35 -0700 | |
---|---|---|
committer | 2014-06-03 13:04:35 -0700 | |
commit | 99ffe24200d8940ceba20f6fbf8c460f994d3cd1 (patch) | |
tree | b5fb9e1104425e2d6c3d9fd4d0832fdd66d85706 /src/gpu/SkGr.cpp | |
parent | 8a35140f3fbc0937b969e6f3356b83ee756ce065 (diff) |
Initial KTX file decoder
R=bsalomon@google.com, robertphillips@google.com, halcanary@google.com, reed@google.com
Author: krajcevski@google.com
Review URL: https://codereview.chromium.org/302333002
Diffstat (limited to 'src/gpu/SkGr.cpp')
-rw-r--r-- | src/gpu/SkGr.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 596e574198..31372cd02a 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -16,6 +16,7 @@ #include "GrDrawTargetCaps.h" #ifndef SK_IGNORE_ETC1_SUPPORT +# include "ktx.h" # include "etc1.h" #endif @@ -135,7 +136,7 @@ static void add_genID_listener(GrResourceKey key, SkPixelRef* pixelRef) { static GrTexture *load_etc1_texture(GrContext* ctx, const GrTextureParams* params, const SkBitmap &bm, GrTextureDesc desc) { - SkData *data = bm.pixelRef()->refEncodedData(); + SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); // Is this even encoded data? if (NULL == data) { @@ -144,24 +145,40 @@ static GrTexture *load_etc1_texture(GrContext* ctx, // Is this a valid PKM encoded data? const uint8_t *bytes = data->bytes(); - if (!etc1_pkm_is_valid(bytes)) { - return NULL; - } + if (etc1_pkm_is_valid(bytes)) { + uint32_t encodedWidth = etc1_pkm_get_width(bytes); + uint32_t encodedHeight = etc1_pkm_get_height(bytes); + + // Does the data match the dimensions of the bitmap? If not, + // then we don't know how to scale the image to match it... + if (encodedWidth != static_cast<uint32_t>(bm.width()) || + encodedHeight != static_cast<uint32_t>(bm.height())) { + return NULL; + } + + // Everything seems good... skip ahead to the data. + bytes += ETC_PKM_HEADER_SIZE; + desc.fConfig = kETC1_GrPixelConfig; + } else if (SkKTXFile::is_ktx(bytes)) { + SkKTXFile ktx(data); - uint32_t encodedWidth = etc1_pkm_get_width(bytes); - uint32_t encodedHeight = etc1_pkm_get_height(bytes); + // Is it actually an ETC1 texture? + if (!ktx.isETC1()) { + return NULL; + } + + // Does the data match the dimensions of the bitmap? If not, + // then we don't know how to scale the image to match it... + if (ktx.width() != bm.width() || ktx.height() != bm.height()) { + return NULL; + } - // Does the data match the dimensions of the bitmap? If not, - // then we don't know how to scale the image to match it... - if (encodedWidth != static_cast<uint32_t>(bm.width()) || - encodedHeight != static_cast<uint32_t>(bm.height())) { + bytes = ktx.pixelData(); + desc.fConfig = kETC1_GrPixelConfig; + } else { return NULL; } - // Everything seems good... skip ahead to the data. - bytes += ETC_PKM_HEADER_SIZE; - desc.fConfig = kETC1_GrPixelConfig; - // This texture is likely to be used again so leave it in the cache GrCacheID cacheID; generate_bitmap_cache_id(bm, &cacheID); |