b=597147 part 6: move Pango shaping out of FontGroup r=jfkthame
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 08 Nov 2010 11:44:51 +1300
changeset 57265 ddba4d6b177df76198e045318402f5898c9b5669
parent 57264 c833b446c0f35534f5559560f038a0c122461abf
child 57266 1f8b0ef812227bbd6c27f01fe51e84ba258773ed
push id16852
push userktomlinson@mozilla.com
push dateWed, 10 Nov 2010 20:06:29 +0000
treeherdermozilla-central@85b93f3ea9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs597147
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=597147 part 6: move Pango shaping out of FontGroup r=jfkthame
gfx/thebes/gfxPangoFonts.cpp
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -3052,16 +3052,54 @@ SetMissingGlyphs(gfxTextRun *aTextRun, c
             ++utf16Offset;
         // We produced this UTF8 so we don't need to worry about malformed stuff
         index = g_utf8_next_char(aUTF8 + index) - aUTF8;
     }
 
     *aUTF16Offset = utf16Offset;
 }
 
+static void
+InitGlyphRunWithPango(gfxTextRun *aTextRun,
+                      const gchar *aUTF8, PRUint32 aUTF8Length,
+                      PRUint32 *aUTF16Offset,
+                      PangoAnalysis *aAnalysis,
+                      PangoGlyphUnit aOverrideSpaceWidth)
+{
+    PRUint32 utf16Offset = *aUTF16Offset;
+    PangoGlyphString *glyphString = pango_glyph_string_new();
+
+    const gchar *p = aUTF8;
+    const gchar *end = p + aUTF8Length;
+    while (p < end) {
+        if (*p == 0) {
+            aTextRun->SetMissingGlyph(utf16Offset, 0);
+            ++p;
+            ++utf16Offset;
+            continue;
+        }
+
+        // It's necessary to loop over pango_shape as it treats
+        // NULs as string terminators
+        const gchar *text = p;
+        do {
+            ++p;
+        } while(p < end && *p != 0);
+        gint len = p - text;
+
+        pango_shape(text, len, aAnalysis, glyphString);
+        SetupClusterBoundaries(aTextRun, text, len, utf16Offset, aAnalysis);
+        SetGlyphs(aTextRun, text, len, &utf16Offset, glyphString,
+                  aOverrideSpaceWidth);
+    }
+
+    pango_glyph_string_free(glyphString);
+    *aUTF16Offset = utf16Offset;
+}
+
 #if defined(ENABLE_FAST_PATH_8BIT)
 nsresult
 gfxPangoFontGroup::CreateGlyphRunsFast(gfxTextRun *aTextRun,
                                        const PRUnichar *aString,
                                        PRUint32 aLength)
 {
     gfxFcFont *gfxFont = GetBaseFont();
     aTextRun->AddGlyphRun(gfxFont, 0);
@@ -3159,20 +3197,16 @@ gfxPangoFontGroup::CreateGlyphRunsItemiz
         pango_itemize_with_base_dir(context, dir, utf8.get(), 0, utf8.Length(),
                                     nsnull, nsnull);
 
     PRUint32 utf16Offset = 0;
 #ifdef DEBUG
     PRBool isRTL = aTextRun->IsRightToLeft();
 #endif
     GList *pos = items;
-    PangoGlyphString *glyphString = pango_glyph_string_new();
-    if (!glyphString)
-        goto out; // OOM
-
     for (; pos && pos->data; pos = pos->next) {
         PangoItem *item = (PangoItem *)pos->data;
         NS_ASSERTION(isRTL == item->analysis.level % 2, "RTL assumption mismatch");
 
         PRUint32 offset = item->offset;
         PRUint32 length = item->length;
         if (offset < headerLen) {
             if (offset + length <= headerLen)
@@ -3189,44 +3223,21 @@ gfxPangoFontGroup::CreateGlyphRunsItemiz
         if (NS_FAILED(rv)) {
             NS_ERROR("AddGlyphRun Failed");
             goto out;
         }
 
         PRUint32 spaceWidth =
             moz_pango_units_from_double(font->GetMetrics().spaceWidth);
 
-        const gchar *p = utf8.get() + offset;
-        const gchar *end = p + length;
-        while (p < end) {
-            if (*p == 0) {
-                aTextRun->SetMissingGlyph(utf16Offset, 0);
-                ++p;
-                ++utf16Offset;
-                continue;
-            }
-
-            // It's necessary to loop over pango_shape as it treats
-            // NULs as string terminators
-            const gchar *text = p;
-            do {
-                ++p;
-            } while(p < end && *p != 0);
-            gint len = p - text;
-
-            pango_shape(text, len, &item->analysis, glyphString);
-            SetupClusterBoundaries(aTextRun, text, len, utf16Offset, &item->analysis);
-            SetGlyphs(aTextRun, text, len, &utf16Offset, glyphString, spaceWidth);
-        }
+        InitGlyphRunWithPango(aTextRun, utf8.get() + offset, length,
+                              &utf16Offset, &item->analysis, spaceWidth);
     }
 
 out:
-    if (glyphString)
-        pango_glyph_string_free(glyphString);
-
     for (pos = items; pos; pos = pos->next)
         pango_item_free((PangoItem *)pos->data);
 
     if (items)
         g_list_free(items);
 
     g_object_unref(context);
 }