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

Unified Diff: src/gpu/SkGr.cpp

Issue 302783002: Initial work to get ETC1 data up to the GPU (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix some code clarity issues 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 6bd04dec3a841ac8186b8644ab212aca6512fba8..169a16a5cdfa72eb92b8f54410d61f683f4afeaa 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -8,9 +8,14 @@
#include "SkGr.h"
#include "SkColorFilter.h"
#include "SkConfig8888.h"
+#include "SkData.h"
#include "SkMessageBus.h"
#include "SkPixelRef.h"
#include "GrResourceCache.h"
+#include "GrGpu.h"
+#include "GrDrawTargetCaps.h"
+
+#include "etc1.h"
/* Fill out buffer with the compressed format Ganesh expects from a colortable
based bitmap. [palette (colortable) + indices].
@@ -172,6 +177,47 @@ static GrTexture* sk_gr_create_bitmap_texture(GrContext* ctx,
bitmap = &tmpBitmap;
desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info());
}
+ } else if (cache && ctx->getGpu()->caps()->compressedTextureSupport(kETC1_GrCompressedFormat)) {
+ SkData *data = bitmap->pixelRef()->refEncodedData();
robertphillips 2014/05/27 22:01:50 hmmm
+ do {
+ // Is this even encoded data?
robertphillips 2014/05/27 22:01:50 NULL == data ?
krajcevski 2014/05/27 22:19:29 Done.
+ if (!data) {
+ break;
+ }
+
+ // Is this a valid PKM encoded data?
+ const uint8_t *bytes = data->bytes();
+ if (!etc1_pkm_is_valid(bytes)) {
+ break;
+ }
+
+ 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>(bitmap->width()) ||
+ encodedHeight != static_cast<uint32_t>(bitmap->height())) {
+ break;
+ }
+
+ // Everything seems good... skip ahead to the data.
+ bytes += ETC_PKM_HEADER_SIZE;
+
+ // This texture is likely to be used again so leave it in the cache
+ GrCacheID cacheID;
+ generate_bitmap_cache_id(origBitmap, &cacheID);
+
+ GrResourceKey key;
+ GrTexture* result =
+ ctx->createCompressedTexture(params, desc, cacheID,
+ bytes, kETC1_GrCompressedFormat, &key);
+ if (NULL != result) {
+ add_genID_listener(key, origBitmap.pixelRef());
+ }
+ return result;
+
+ } while(0);
}
SkAutoLockPixels alp(*bitmap);

Powered by Google App Engine
This is Rietveld 408576698