Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Unified Diff: src/core/SkGlyphCache.cpp

Issue 18132009: move failable work outside of constructors for SkGlyphCache and SkScalerContextGDI. If we fail, try… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkGlyphCache.cpp
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 61dc6ae257775bd5ad733b32f510c94164745c90..12e06643fed6434ff1bc6eec9e0e726d7c417a30 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -53,14 +53,15 @@ bool gSkSuppressFontCachePurgeSpew;
#define kMinGlyphImageSize (16*2)
#define kMinAllocAmount ((sizeof(SkGlyph) + kMinGlyphImageSize) * kMinGlyphCount)
-SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc)
- : fGlyphAlloc(kMinAllocAmount) {
+SkGlyphCache::SkGlyphCache(SkTypeface* typeface, const SkDescriptor* desc, SkScalerContext* ctx)
+ : fScalerContext(ctx), fGlyphAlloc(kMinAllocAmount) {
SkASSERT(typeface);
+ SkASSERT(desc);
+ SkASSERT(ctx);
fPrev = fNext = NULL;
fDesc = desc->copy();
- fScalerContext = typeface->createScalerContext(desc);
fScalerContext->getFontMetrics(&fFontMetrics);
// init to 0 so that all of the pointers will be null
@@ -589,7 +590,20 @@ SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
ac.release(); // release the mutex now
insideMutex = false; // can't use globals anymore
- cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc));
+ // Check if we can create a scaler-context before creating the glyphcache.
+ // If not, we may have exhausted OS/font resources, so try purging the
+ // cache once and try again.
+ {
+ SkScalerContext* ctx = typeface->createScalerContext(desc);
+ if (!ctx) {
+ getSharedGlobals().purgeAll();
+ ctx = typeface->createScalerContext(desc);
+ if (!ctx) {
+ sk_throw();
+ }
+ }
+ cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc, ctx));
+ }
FOUND_IT:
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698