| Index: src/gpu/SkGr.cpp
|
| diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
|
| index 954bb808524243d181ed5066b6d84c5ef7b29449..22b1f889056f23d32ef83e62f13f3a37fbfe1f30 100644
|
| --- a/src/gpu/SkGr.cpp
|
| +++ b/src/gpu/SkGr.cpp
|
| @@ -23,6 +23,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 +287,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;
|
| + }
|
| +
|
| + SkMipMap* mipmaps = SkMipMap::Build(bitmap, nullptr);
|
| + 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()) {
|
|
|