Check that findImage does not change the format

Change-Id: I28e002bdd51492eee6b32beb81d3910603da1bc7
Reviewed-on: https://skia-review.googlesource.com/c/174283
Commit-Queue: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Herb Derby 2018-12-04 10:46:21 -05:00 committed by Skia Commit-Bot
parent 92d8ea6f99
commit add7bd9797

View File

@ -181,6 +181,7 @@ SkGlyph* SkGlyphCache::allocateNewGlyph(SkPackedGlyphID packedGlyphID, MetricsTy
const void* SkGlyphCache::findImage(const SkGlyph& glyph) {
if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) {
if (nullptr == glyph.fImage) {
SkDEBUGCODE(SkMask::Format oldFormat = (SkMask::Format)glyph.fMaskFormat);
size_t size = const_cast<SkGlyph&>(glyph).allocImage(&fAlloc);
// check that alloc() actually succeeded
if (glyph.fImage) {
@ -191,6 +192,7 @@ const void* SkGlyphCache::findImage(const SkGlyph& glyph) {
// is smaller, and if so, strink the alloc size in fImageAlloc.
fMemoryUsed += size;
}
SkASSERT(oldFormat == glyph.fMaskFormat);
}
}
return glyph.fImage;
@ -205,7 +207,7 @@ void SkGlyphCache::initializeImage(const volatile void* data, size_t size, SkGly
size_t allocSize = glyph->allocImage(&fAlloc);
// check that alloc() actually succeeded
if (glyph->fImage) {
SkAssertResult(size == allocSize);
SkASSERT(size == allocSize);
memcpy(glyph->fImage, const_cast<const void*>(data), allocSize);
fMemoryUsed += size;
}