Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Unified Diff: src/gpu/SkGr.cpp

Issue 302333002: Initial KTX file decoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address code review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/SkGr.cpp
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 9dc215c735d5e243a5ec981a02ebb23954031eb5..4b771aa30ab6e3f054f28d0b4c5eadefea6615e3 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -9,6 +9,7 @@
#include "SkColorFilter.h"
#include "SkConfig8888.h"
#include "SkData.h"
+#include "SkKTXFile.h"
#include "SkMessageBus.h"
#include "SkPixelRef.h"
#include "GrResourceCache.h"
@@ -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(bytes, data->size());
- 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);

Powered by Google App Engine
This is Rietveld 408576698