| Index: src/gpu/SkGr.cpp
|
| diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
|
| index 471c9721cf55bd5357dc186a0f6f6f9ea3fd8cc5..6fd1a1090b7cb60a5ad6e82b9d5c6bce89b18bdc 100644
|
| --- a/src/gpu/SkGr.cpp
|
| +++ b/src/gpu/SkGr.cpp
|
| @@ -19,6 +19,7 @@
|
| #include "SkErrorInternals.h"
|
| #include "SkGrPixelRef.h"
|
| #include "SkMessageBus.h"
|
| +#include "SkMipMap.h"
|
| #include "SkPixelRef.h"
|
| #include "SkResourceCache.h"
|
| #include "SkTextureCompressor.h"
|
| @@ -636,6 +637,37 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
|
| return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms);
|
| }
|
|
|
| +GrTexture* GrMipMapTexture(GrContext* ctx,
|
| + const SkBitmap& bitmap,
|
| + SkDiscardableFactoryProc fact) {
|
| + // If the SkBitmap is already backed by a texture, we do not want to read the contents back
|
| + // to the cpu and generate the mipmap only to send it back to the GPU.
|
| + SkASSERT(!bitmap.getTexture());
|
| +
|
| + GrSurfaceDesc desc;
|
| + generate_bitmap_texture_desc(bitmap, &desc);
|
| +
|
| + auto mipmap = SkMipMap::Build(bitmap, fact);
|
| + if (mipmap == NULL) {
|
| + // could not create the mipmap
|
| + return NULL;
|
| + } else {
|
| + auto mipLevelCount = mipmap->getLevelsCount();
|
| + desc.fIsMipMapped = mipLevelCount > 1;
|
| + SkTArray<SkMipMapLevel> texels(mipLevelCount);
|
| + for (int i = 0; i < mipLevelCount; i++) {
|
| + SkMipMap::Level level;
|
| + mipmap->getLevel(i, &level);
|
| +
|
| + SkMipMapLevel currentMipLevel(level.fPixels, level.fRowBytes);
|
| +
|
| + texels.push_back(currentMipLevel);
|
| + }
|
| + return ctx->textureProvider()->createTexture(desc, true, texels);
|
| + // TODO: BitmapInvalidator support
|
| + }
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
|
|
| // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
|
|
|