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
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index b815df6..86fcac0 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -25,7 +25,7 @@
     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
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 4f036a81..5d35133 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -97,6 +97,7 @@
 
 /////////////////////////////////////////////////////////////////////////
 
+// Caller must lock gFTMutex before calling this function.
 static bool InitFreetype() {
     FT_Error err = FT_Init_FreeType(&gFTLibrary);
     if (err) {
@@ -175,8 +176,8 @@
     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 @@
 }
 
 // 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 @@
     }
 }
 
+// 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 @@
     //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() {
+    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::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 @@
     FT_Done_FreeType(library);
     return true;
 }
+