Assert complex precondition in SkGlyphCache::Visit.

SkGlyphCache::Visit takes a descriptor and a typeface, but it is implied
that the fFontID in the descriptor is the id of the typeface. This seems
to be handled correctly by current callers but this is a subtle
requirement which if violated could lead to subtle bugs.

Review-Url: https://codereview.chromium.org/1992053002
This commit is contained in:
bungeman 2016-05-19 07:43:52 -07:00 committed by Commit bot
parent 0876158ecd
commit de3c3568ee

View File

@ -520,6 +520,16 @@ SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
}
SkASSERT(desc);
// Precondition: the typeface id must be the fFontID in the descriptor
SkDEBUGCODE(
uint32_t length;
const SkScalerContext::Rec* rec = static_cast<const SkScalerContext::Rec*>(
desc->findEntry(kRec_SkDescriptorTag, &length));
SkASSERT(rec);
SkASSERT(length == sizeof(*rec));
SkASSERT(typeface->uniqueID() == rec->fFontID);
)
SkGlyphCache_Globals& globals = get_globals();
SkGlyphCache* cache;