Lock gFTMutex when modifying FT globals.

This prevents a crash when running bench_pictures with multiple threads.

Also remove an unused function and fix a typo in SkFontHost.
Review URL: https://codereview.appspot.com/6625043

git-svn-id: http://skia.googlecode.com/svn/trunk@5816 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
scroggo@google.com 2012-10-04 20:45:06 +00:00
parent d5d69ffaea
commit 94bc60f986
2 changed files with 11 additions and 14 deletions

View File

@ -25,7 +25,7 @@ class SkWStream;
platform-specific implementation that provides access to font files.
One basic task is for each create (subclass of) SkTypeface, the FontHost is
resonsible for assigning a uniqueID. The ID should be unique for the
responsible for assigning a uniqueID. The ID should be unique for the
underlying font file/data, not unique per typeface instance. Thus it is
possible/common to request a typeface for the same font more than once
(e.g. asking for the same font by name several times). The FontHost may

View File

@ -97,6 +97,7 @@ typedef FT_Error (*FT_Library_SetLcdFilterWeightsProc)(FT_Library, unsigned char
/////////////////////////////////////////////////////////////////////////
// Caller must lock gFTMutex before calling this function.
static bool InitFreetype() {
FT_Error err = FT_Init_FreeType(&gFTLibrary);
if (err) {
@ -175,8 +176,8 @@ private:
FT_Error setupSize();
void getBBoxForCurrentGlyph(SkGlyph* glyph, FT_BBox* bbox,
bool snapToPixelBoundary = false);
// Caller must lock gFTMutex before calling this function.
void updateGlyphIfLCD(SkGlyph* glyph);
void updateGlyphPosIfLCD(SkGlyph* glyph);
};
///////////////////////////////////////////////////////////////////////////
@ -242,6 +243,7 @@ SkFaceRec::SkFaceRec(SkStream* strm, uint32_t fontID)
}
// Will return 0 on failure
// Caller must lock gFTMutex before calling this function.
static SkFaceRec* ref_ft_face(uint32_t fontID) {
SkFaceRec* rec = gFaceRecHead;
while (rec) {
@ -295,6 +297,7 @@ static SkFaceRec* ref_ft_face(uint32_t fontID) {
}
}
// Caller must lock gFTMutex before calling this function.
static void unref_ft_face(FT_Face face) {
SkFaceRec* rec = gFaceRecHead;
SkFaceRec* prev = NULL;
@ -639,9 +642,11 @@ void SkFontHost::FilterRec(SkScalerContext::Rec* rec) {
//Cap the requested size as larger sizes give bogus values.
//Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed.
if (rec->fTextSize > SkIntToScalar(1 << 14)) {
rec->fTextSize = SkIntToScalar(1 << 14);
rec->fTextSize = SkIntToScalar(1 << 14);
}
SkAutoMutexAcquire ac(gFTMutex);
if (!gLCDSupportValid) {
InitFreetype();
FT_Done_FreeType(gFTLibrary);
@ -874,12 +879,12 @@ SkScalerContext_FreeType::SkScalerContext_FreeType(const SkDescriptor* desc)
}
SkScalerContext_FreeType::~SkScalerContext_FreeType() {
SkAutoMutexAcquire ac(gFTMutex);
if (fFTSize != NULL) {
FT_Done_Size(fFTSize);
}
SkAutoMutexAcquire ac(gFTMutex);
if (fFace != NULL) {
unref_ft_face(fFace);
}
@ -1014,15 +1019,6 @@ void SkScalerContext_FreeType::updateGlyphIfLCD(SkGlyph* glyph) {
}
}
}
void SkScalerContext_FreeType::updateGlyphPosIfLCD(SkGlyph* glyph) {
if (isLCD(fRec)) {
if (fLCDIsVert) {
glyph->fTop -= gLCDExtra >> 1;
} else {
glyph->fLeft -= gLCDExtra >> 1;
}
}
}
void SkScalerContext_FreeType::generateMetrics(SkGlyph* glyph) {
SkAutoMutexAcquire ac(gFTMutex);
@ -1361,3 +1357,4 @@ bool find_name_and_attributes(SkStream* stream, SkString* name,
FT_Done_FreeType(library);
return true;
}