GrTexture* GrTextureMaker::refCachedTexture(GrContext* ctx, const GrTextureParams* params) { SkGrStretch stretch; get_stretch(ctx, this->width(), this->height(), params, &stretch); if (SkGrStretch::kNone_Type == stretch.fType) { return this->onRefUnstretchedTexture(ctx); } GrUniqueKey stretchedKey; if (this->onMakeStretchedKey(stretch, &stretchedKey)) { GrTexture* result = ctx->textureProvider()->findAndRefTextureByUniqueKey(stretchedKey); if (result) { return result; } } GrTexture* result = this->onGenerateStretchedTexture(ctx, stretch); if (!result) { return nullptr; } if (stretchedKey.isValid()) { ctx->textureProvider()->assignUniqueKeyToTexture(stretchedKey, result); this->onNotifyStretchCached(stretchedKey); } return result; }
bool GrIsBitmapInCache(const GrContext* ctx, const SkBitmap& bitmap, const GrTextureParams* params) { Stretch stretch; get_stretch(ctx, bitmap.width(), bitmap.height(), params, &stretch); // Handle the case where the bitmap is explicitly texture backed. GrTexture* texture = bitmap.getTexture(); if (texture) { if (Stretch::kNone_Type == stretch.fType) { return true; } // No keys for volatile bitmaps. if (bitmap.isVolatile()) { return false; } const GrUniqueKey& key = texture->getUniqueKey(); if (!key.isValid()) { return false; } GrUniqueKey stretchedKey; make_stretched_key(key, stretch, &stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey); } // We don't cache volatile bitmaps if (bitmap.isVolatile()) { return false; } GrUniqueKey key, stretchedKey; make_bitmap_keys(bitmap, stretch, &key, &stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey( (Stretch::kNone_Type == stretch.fType) ? key : stretchedKey); }
GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, const GrTextureParams* params) { Stretch stretch; get_stretch(ctx, bitmap.width(), bitmap.height(), params, &stretch); GrTexture* result = bitmap.getTexture(); if (result) { if (Stretch::kNone_Type == stretch.fType) { return SkRef(result); } GrUniqueKey stretchedKey; // Don't create a key for the resized version if the bmp is volatile. if (!bitmap.isVolatile()) { const GrUniqueKey& key = result->getUniqueKey(); if (key.isValid()) { make_stretched_key(key, stretch, &stretchedKey); GrTexture* stretched = ctx->textureProvider()->findAndRefTextureByUniqueKey(stretchedKey); if (stretched) { return stretched; } } } return stretch_texture(result, stretch, bitmap.pixelRef(), stretchedKey); } GrUniqueKey key, resizedKey; if (!bitmap.isVolatile()) { // If the bitmap isn't changing try to find a cached copy first. make_bitmap_keys(bitmap, stretch, &key, &resizedKey); result = ctx->textureProvider()->findAndRefTextureByUniqueKey( resizedKey.isValid() ? resizedKey : key); if (result) { return result; } } result = create_bitmap_texture(ctx, bitmap, stretch, key, resizedKey); if (result) { return result; } SkErrorInternals::SetError( kInternalError_SkError, "---- failed to create texture for cache [%d %d]\n", bitmap.width(), bitmap.height()); return NULL; }
bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& subset, GrTexture* nativeTexture, const GrTextureParams* params) { SkGrStretch stretch; get_stretch(ctx, subset.width(), subset.height(), params, &stretch); // Handle the case where the bitmap/image is explicitly texture backed. if (nativeTexture) { if (SkGrStretch::kNone_Type == stretch.fType) { return true; } const GrUniqueKey& key = nativeTexture->getUniqueKey(); if (!key.isValid()) { return false; } GrUniqueKey stretchedKey; GrMakeStretchedKey(key, stretch, &stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey); } GrUniqueKey key, stretchedKey; make_image_keys(imageID, subset, stretch, &key, &stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey( (SkGrStretch::kNone_Type == stretch.fType) ? key : stretchedKey); }