void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, U16CPU width, U16CPU height, SkIPoint origin, const GrCaps& caps, SkImageUsageType usage) { const Stretch::Type stretches[] = { Stretch::kNone_Type, // kUntiled_SkImageUsageType Stretch::kNearest_Type, // kTiled_Unfiltered_SkImageUsageType Stretch::kBilerp_Type, // kTiled_Filtered_SkImageUsageType }; const bool isPow2 = SkIsPow2(width) && SkIsPow2(height); const bool needToStretch = !isPow2 && usage != kUntiled_SkImageUsageType && !caps.npotTextureTileSupport(); if (needToStretch) { GrUniqueKey tmpKey; make_unstretched_key(&tmpKey, imageID, width, height, origin); Stretch stretch; stretch.fType = stretches[usage]; stretch.fWidth = SkNextPow2(width); stretch.fHeight = SkNextPow2(height); if (!make_stretched_key(tmpKey, stretch, key)) { goto UNSTRETCHED; } } else { UNSTRETCHED: make_unstretched_key(key, imageID, width, height, origin); } }
static void make_image_keys(uint32_t imageID, const SkIRect& subset, const SkGrStretch& stretch, GrUniqueKey* key, GrUniqueKey* stretchedKey) { make_unstretched_key(key, imageID, subset); if (SkGrStretch::kNone_Type != stretch.fType) { GrMakeStretchedKey(*key, stretch, stretchedKey); } }
bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override { if (fBitmap.isVolatile()) { return false; } GrUniqueKey unstretchedKey; make_unstretched_key(&unstretchedKey, fBitmap.getGenerationID(), fBitmap.getSubset()); return GrMakeStretchedKey(unstretchedKey, stretch, stretchedKey); }
static void make_bitmap_keys(const SkBitmap& bitmap, const Stretch& stretch, GrUniqueKey* key, GrUniqueKey* stretchedKey) { make_unstretched_key(bitmap, key); if (Stretch::kNone_Type != stretch.fType) { make_stretched_key(*key, stretch, stretchedKey); } }
static void make_bitmap_keys(const SkBitmap& bitmap, Stretch stretch, GrUniqueKey* key, GrUniqueKey* stretchedKey) { make_unstretched_key(bitmap, key); if (kNo_Stretch != stretch) { make_stretched_key(*key, stretch, stretchedKey); } }
GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { GrTexture* tex = fBitmap.getTexture(); if (tex) { return SkRef(tex); } GrUniqueKey unstretchedKey; make_unstretched_key(&unstretchedKey, fBitmap.getGenerationID(), fBitmap.getSubset()); GrTexture* result = ctx->textureProvider()->findAndRefTextureByUniqueKey(unstretchedKey); if (result) { return result; } return create_unstretched_bitmap_texture(ctx, fBitmap, unstretchedKey); }
void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& subset, const GrCaps& caps, SkImageUsageType usage) { const SkGrStretch::Type stretches[] = { SkGrStretch::kNone_Type, // kUntiled_SkImageUsageType SkGrStretch::kNearest_Type, // kTiled_Unfiltered_SkImageUsageType SkGrStretch::kBilerp_Type, // kTiled_Filtered_SkImageUsageType }; if (!GrTextureUsageSupported(caps, subset.width(), subset.height(), usage)) { GrUniqueKey tmpKey; make_unstretched_key(&tmpKey, imageID, subset); SkGrStretch stretch; stretch.fType = stretches[usage]; stretch.fWidth = SkNextPow2(subset.width()); stretch.fHeight = SkNextPow2(subset.height()); if (!GrMakeStretchedKey(tmpKey, stretch, key)) { goto UNSTRETCHED; } } else { UNSTRETCHED: make_unstretched_key(key, imageID, subset); } }
static void make_unstretched_key(const SkBitmap& bitmap, GrUniqueKey* key) { make_unstretched_key(key, bitmap.getGenerationID(), bitmap.width(), bitmap.height(), bitmap.pixelRefOrigin()); }