Index: src/gpu/SkGr.cpp |
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp |
index 954bb808524243d181ed5066b6d84c5ef7b29449..d62cec7ff188fd0ef6684383dccc088f3e168afb 100644 |
--- a/src/gpu/SkGr.cpp |
+++ b/src/gpu/SkGr.cpp |
@@ -8,6 +8,8 @@ |
#include "SkGr.h" |
+#include <memory> |
+ |
#include "GrCaps.h" |
#include "GrContext.h" |
#include "GrTextureParamsAdjuster.h" |
@@ -23,6 +25,8 @@ |
#include "SkErrorInternals.h" |
#include "SkGrPixelRef.h" |
#include "SkMessageBus.h" |
+#include "SkMipMap.h" |
+#include "SkMipMapLevel.h" |
#include "SkPixelRef.h" |
#include "SkResourceCache.h" |
#include "SkTextureCompressor.h" |
@@ -285,6 +289,60 @@ void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix |
pixelRef->addGenIDChangeListener(new Invalidator(key)); |
} |
+GrTexture* GrGenerateMipMapsAndUploadToTexture(GrContext* ctx, const SkBitmap& bitmap) |
+{ |
+ GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info()); |
+ if (kIndex_8_SkColorType != bitmap.colorType() && !bitmap.readyToDraw()) { |
+ GrTexture *texture = load_etc1_texture(ctx, bitmap, desc); |
+ if (texture) { |
+ return texture; |
+ } |
+ } |
+ |
+ GrTexture *texture = create_texture_from_yuv(ctx, bitmap, desc); |
+ if (texture) { |
+ return texture; |
+ } |
+ |
+ SkASSERT(sizeof(int) <= sizeof(uint32_t)); |
+ if (bitmap.width() < 0 || bitmap.height() < 0) { |
+ return nullptr; |
+ } |
+ |
+ SkAutoLockPixels alp(bitmap); |
+ if (!bitmap.readyToDraw()) { |
+ return nullptr; |
+ } |
+ |
+ std::unique_ptr<SkMipMap> mipmaps(SkMipMap::Build(bitmap, nullptr)); |
bsalomon
2016/01/22 14:33:36
We don't currently use unique_ptr in Skia. That is
cblume
2016/02/24 07:59:24
Done.
|
+ if (!mipmaps) { |
+ return nullptr; |
+ } |
+ |
+ const int mipLevelCount = mipmaps->getLevelsCount(); |
+ |
+ const bool isMipMapped = mipLevelCount > 1; |
+ desc.fIsMipMapped = isMipMapped; |
+ |
+ SkTArray<SkMipMapLevel> texels(mipLevelCount); |
+ |
+ SkMipMapLevel baseLevel(bitmap.getPixels(), bitmap.rowBytes(), bitmap.width(), |
+ bitmap.height()); |
+ texels.push_back(baseLevel); |
+ |
+ for (int i = 1; i <= mipLevelCount; ++i) { |
+ SkMipMap::Level generatedMipLevel; |
+ mipmaps->getLevel(i, &generatedMipLevel); |
+ SkMipMapLevel currentMipLevel(generatedMipLevel.fPixmap.addr(), |
+ generatedMipLevel.fPixmap.rowBytes(), |
+ generatedMipLevel.fPixmap.width(), |
+ generatedMipLevel.fPixmap.height()); |
+ texels.push_back(currentMipLevel); |
+ } |
+ |
+ return ctx->textureProvider()->createTexture(desc, true, texels); |
+} |
+ |
GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, |
const GrTextureParams& params) { |
if (bitmap.getTexture()) { |