bug 950590 - part 2 - make SetUserFontSet support updating a gfxFontGroup's user font set on the fly, and use this in canvas rendering context. r=roc a=lsblakk
authorJonathan Kew <jkew@mozilla.com>
Sun, 22 Dec 2013 19:25:53 +0000
changeset 174489 af28fe58e2637d734dd6cba1b9f15e8061995f15
parent 174488 4b603966034c44a3be217fc3525da95ffd758fb3
child 174490 61f553e5db49afda821d2ba468c277786f290c0e
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, lsblakk
bugs950590
milestone28.0a2
bug 950590 - part 2 - make SetUserFontSet support updating a gfxFontGroup's user font set on the fly, and use this in canvas rendering context. r=roc a=lsblakk
content/canvas/src/CanvasRenderingContext2D.cpp
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxPangoFonts.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -2623,16 +2623,20 @@ CanvasRenderingContext2D::DrawOrMeasureT
       NS_STYLE_DIRECTION_RTL;
   } else {
     isRTL = GET_BIDI_OPTION_DIRECTION(document->GetBidiOptions()) == IBMBIDI_TEXTDIRECTION_RTL;
   }
 
   gfxFontGroup* currentFontStyle = GetCurrentFontStyle();
   NS_ASSERTION(currentFontStyle, "font group is null");
 
+  // ensure user font set is up to date
+  currentFontStyle->
+    SetUserFontSet(presShell->GetPresContext()->GetUserFontSet());
+
   if (currentFontStyle->GetStyle()->size == 0.0F) {
     if (aWidth) {
       *aWidth = 0;
     }
     return NS_OK;
   }
 
   const ContextState &state = CurrentState();
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -4055,21 +4055,24 @@ gfxGlyphExtents::SizeOfIncludingThis(Mal
 
 gfxFontGroup::gfxFontGroup(const nsAString& aFamilies,
                            const gfxFontStyle *aStyle,
                            gfxUserFontSet *aUserFontSet)
     : mFamilies(aFamilies)
     , mStyle(*aStyle)
     , mUnderlineOffset(UNDERLINE_OFFSET_NOT_SET)
     , mHyphenWidth(-1)
+    , mUserFontSet(aUserFontSet)
     , mTextPerf(nullptr)
     , mPageLang(gfxPlatform::GetFontPrefLangFor(aStyle->language))
     , mSkipDrawing(false)
 {
-    SetUserFontSet(aUserFontSet);
+    // We don't use SetUserFontSet() here, as we want to unconditionally call
+    // BuildFontList() rather than only do UpdateFontList() if it changed.
+    mCurrGeneration = GetGeneration();
     BuildFontList();
 }
 
 void
 gfxFontGroup::BuildFontList()
 {
 // "#if" to be removed once all platforms are moved to gfxPlatformFontList interface
 // and subclasses of gfxFontGroup eliminated
@@ -5101,32 +5104,36 @@ gfxUserFontSet*
 gfxFontGroup::GetUserFontSet()
 {
     return mUserFontSet;
 }
 
 void 
 gfxFontGroup::SetUserFontSet(gfxUserFontSet *aUserFontSet)
 {
+    if (aUserFontSet == mUserFontSet) {
+        return;
+    }
     mUserFontSet = aUserFontSet;
-    mCurrGeneration = GetGeneration();
+    mCurrGeneration = GetGeneration() - 1;
+    UpdateFontList();
 }
 
 uint64_t
 gfxFontGroup::GetGeneration()
 {
     if (!mUserFontSet)
         return 0;
     return mUserFontSet->GetGeneration();
 }
 
 void
 gfxFontGroup::UpdateFontList()
 {
-    if (mUserFontSet && mCurrGeneration != GetGeneration()) {
+    if (mCurrGeneration != GetGeneration()) {
         // xxx - can probably improve this to detect when all fonts were found, so no need to update list
         mFonts.Clear();
         mUnderlineOffset = UNDERLINE_OFFSET_NOT_SET;
         mSkipDrawing = false;
 
         // bug 548184 - need to clean up FT2, OS/2 platform code to use BuildFontList
 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(ANDROID)
         BuildFontList();
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -3508,16 +3508,19 @@ public:
     // previously created text runs in the text run word cache.  For font groups based on stylesheets
     // with no @font-face rule, this always returns 0.
     uint64_t GetGeneration();
 
     // used when logging text performance
     gfxTextPerfMetrics *GetTextPerfMetrics() { return mTextPerf; }
     void SetTextPerfMetrics(gfxTextPerfMetrics *aTextPerf) { mTextPerf = aTextPerf; }
 
+    // This will call UpdateFontList() if the user font set is changed.
+    void SetUserFontSet(gfxUserFontSet *aUserFontSet);
+
     // If there is a user font set, check to see whether the font list or any
     // caches need updating.
     virtual void UpdateFontList();
 
     bool ShouldSkipDrawing() const {
         return mSkipDrawing;
     }
 
@@ -3564,20 +3567,16 @@ protected:
      * Textrun creation short-cuts for special cases where we don't need to
      * call a font shaper to generate glyphs.
      */
     gfxTextRun *MakeEmptyTextRun(const Parameters *aParams, uint32_t aFlags);
     gfxTextRun *MakeSpaceTextRun(const Parameters *aParams, uint32_t aFlags);
     gfxTextRun *MakeBlankTextRun(uint32_t aLength,
                                  const Parameters *aParams, uint32_t aFlags);
 
-    // Used for construction/destruction.  Not intended to change the font set
-    // as invalidation of font lists and caches is not considered.
-    void SetUserFontSet(gfxUserFontSet *aUserFontSet);
-
     // Initialize the list of fonts
     void BuildFontList();
 
     // Init this font group's font metrics. If there no bad fonts, you don't need to call this.
     // But if there are one or more bad fonts which have bad underline offset,
     // you should call this with the *first* bad font.
     void InitMetricsForBadFont(gfxFont* aBadFont);
 
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -1405,20 +1405,17 @@ gfxPangoFontGroup::GetFontAt(int32_t i)
     NS_PRECONDITION(i == 0, "Only have one font");
 
     return GetBaseFont();
 }
 
 void
 gfxPangoFontGroup::UpdateFontList()
 {
-    if (!mUserFontSet)
-        return;
-
-    uint64_t newGeneration = mUserFontSet->GetGeneration();
+    uint64_t newGeneration = GetGeneration();
     if (newGeneration == mCurrGeneration)
         return;
 
     mFonts[0] = FamilyFace();
     mFontSets.Clear();
     mCachedEllipsisTextRun = nullptr;
     mUnderlineOffset = UNDERLINE_OFFSET_NOT_SET;
     mCurrGeneration = newGeneration;