Bug 602792. Lazy initialize mUseFontGlyphWidths to avoid unnecessary font io. r=jkew, a=blocker
authorJohn Daggett <jdaggett@mozilla.com>
Sat, 22 Jan 2011 01:44:33 +0900
changeset 61086 2a14b48cc2877c945798f99b4c13719e7c944f91
parent 61085 5c836d01b70a82e75e33fa538b7bc1cdb5fe8acb
child 61087 ffb56732bdbeba4566897e7656a99b257749cc17
push idunknown
push userunknown
push dateunknown
reviewersjkew, blocker
bugs602792
milestone2.0b10pre
Bug 602792. Lazy initialize mUseFontGlyphWidths to avoid unnecessary font io. r=jkew, a=blocker
gfx/thebes/gfxDWriteFonts.cpp
gfx/thebes/gfxDWriteFonts.h
gfx/thebes/gfxFT2FontBase.h
gfx/thebes/gfxFont.h
gfx/thebes/gfxGDIFont.h
gfx/thebes/gfxHarfBuzzShaper.cpp
--- a/gfx/thebes/gfxDWriteFonts.cpp
+++ b/gfx/thebes/gfxDWriteFonts.cpp
@@ -667,16 +667,26 @@ gfxDWriteFont::GetFontTable(PRUint32 aTa
         if (mFontEntry->GetExistingFontTable(aTag, &blob)) {
             return blob;
         }
     }
 
     return nsnull;
 }
 
+PRBool
+gfxDWriteFont::ProvidesGlyphWidths()
+{
+    if (!mInitialized) {
+        Initialize();
+    }
+    return !mUseSubpixelPositions ||
+           (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD);
+}
+
 PRInt32
 gfxDWriteFont::GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID)
 {
     if (!mGlyphWidths.IsInitialized()) {
         mGlyphWidths.Init(200);
     }
 
     PRInt32 width = -1;
--- a/gfx/thebes/gfxDWriteFonts.h
+++ b/gfx/thebes/gfxDWriteFonts.h
@@ -79,20 +79,17 @@ public:
     }
 
     IDWriteFontFace *GetFontFace();
 
     // override gfxFont table access function to bypass gfxFontEntry cache,
     // use DWrite API to get direct access to system font data
     virtual hb_blob_t *GetFontTable(PRUint32 aTag);
 
-    virtual PRBool ProvidesGlyphWidths() const {
-        return !mUseSubpixelPositions ||
-               (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD);
-    }
+    virtual PRBool ProvidesGlyphWidths();
 
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
 protected:
     friend class gfxDWriteShaper;
 
     virtual void CreatePlatformShaper();
 
--- a/gfx/thebes/gfxFT2FontBase.h
+++ b/gfx/thebes/gfxFT2FontBase.h
@@ -58,17 +58,17 @@ public:
     void GetGlyphExtents(PRUint32 aGlyph,
                          cairo_text_extents_t* aExtents);
     virtual const gfxFont::Metrics& GetMetrics();
     virtual nsString GetUniqueName();
     virtual PRUint32 GetSpaceGlyph();
     virtual hb_blob_t *GetFontTable(PRUint32 aTag);
     virtual PRBool ProvidesGetGlyph() const { return PR_TRUE; }
     virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector);
-    virtual PRBool ProvidesGlyphWidths() const { return PR_TRUE; }
+    virtual PRBool ProvidesGlyphWidths() { return PR_TRUE; }
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
     cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; };
     virtual PRBool SetupCairoFont(gfxContext *aContext);
 
 protected:
     cairo_scaled_font_t *mScaledFont;
     PRUint32 mSpaceGlyph;
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1008,17 +1008,17 @@ public:
     // Only used if ProvidesGetGlyph() returns PR_TRUE.
     virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector) {
         return 0;
     }
 
     // subclasses may provide (possibly hinted) glyph widths (in font units);
     // if they do not override this, harfbuzz will use unhinted widths
     // derived from the font tables
-    virtual PRBool ProvidesGlyphWidths() const {
+    virtual PRBool ProvidesGlyphWidths() {
         return PR_FALSE;
     }
 
     // The return value is interpreted as a horizontal advance in 16.16 fixed
     // point format.
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) {
         return -1;
     }
--- a/gfx/thebes/gfxGDIFont.h
+++ b/gfx/thebes/gfxGDIFont.h
@@ -71,17 +71,17 @@ public:
 
     virtual PRUint32 GetSpaceGlyph();
 
     virtual PRBool SetupCairoFont(gfxContext *aContext);
 
     /* required for MathML to suppress effects of ClearType "padding" */
     virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption);
 
-    virtual PRBool ProvidesGlyphWidths() const { return PR_TRUE; }
+    virtual PRBool ProvidesGlyphWidths() { return PR_TRUE; }
 
     // get hinted glyph width in pixels as 16.16 fixed-point value
     virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID);
 
 protected:
     virtual void CreatePlatformShaper();
 
     /* override to check for uniscribe failure and fall back to GDI */
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -78,17 +78,17 @@ gfxHarfBuzzShaper::gfxHarfBuzzShaper(gfx
       mKernTable(nsnull),
       mHmtxTable(nsnull),
       mNumLongMetrics(0),
       mCmapTable(nsnull),
       mCmapFormat(-1),
       mSubtableOffset(0),
       mUVSTableOffset(0),
       mUseFontGetGlyph(aFont->ProvidesGetGlyph()),
-      mUseFontGlyphWidths(aFont->ProvidesGlyphWidths())
+      mUseFontGlyphWidths(PR_FALSE)
 {
 }
 
 gfxHarfBuzzShaper::~gfxHarfBuzzShaper()
 {
     hb_blob_destroy(mCmapTable);
     hb_blob_destroy(mHmtxTable);
     hb_blob_destroy(mKernTable);
@@ -704,16 +704,19 @@ gfxHarfBuzzShaper::InitTextRun(gfxContex
                                PRUint32 aRunStart,
                                PRUint32 aRunLength,
                                PRInt32 aRunScript)
 {
     // some font back-ends require this in order to get proper hinted metrics
     mFont->SetupCairoFont(aContext);
 
     if (!mHBFace) {
+
+        mUseFontGlyphWidths = mFont->ProvidesGlyphWidths();
+
         // set up the harfbuzz face etc the first time we use the font
 
         if (!sHBFontFuncs) {
             // static function callback pointers, initialized by the first
             // harfbuzz shaper used
             sHBFontFuncs = hb_font_funcs_create();
             hb_font_funcs_set_glyph_func(sHBFontFuncs, HBGetGlyph);
             hb_font_funcs_set_glyph_advance_func(sHBFontFuncs,