Title: [206466] trunk/Source/WebCore
Revision
206466
Author
mmaxfi...@apple.com
Date
2016-09-27 14:58:56 -0700 (Tue, 27 Sep 2016)

Log Message

[Cocoa] Improve performance of complex text codepath
https://bugs.webkit.org/show_bug.cgi?id=161936

Reviewed by Simon Fraser.

CoreText exposes a bit on the CTRunStatus which represents whether
the run actually uses the glyph origins concept introduced in
r205396. If this bit is not set, we can use the (slightly faster)
call to CTRunGetAdvances() instead of
CTRunGetBaseAdvancesAndOrigins(). In addition, if none of the runs
have this bit set, we don't need to allocate storage for the vector
of origins at all, thereby using less memory.

No new tests because there is no behavior change.

* platform/graphics/mac/ComplexTextController.cpp:
(WebCore::ComplexTextController::advance):
(WebCore::ComplexTextController::adjustGlyphsAndAdvances):
* platform/graphics/mac/ComplexTextController.h:
(WebCore::ComplexTextController::ComplexTextRun::glyphOrigins):
(WebCore::ComplexTextController::glyphOrigin):
* platform/graphics/mac/ComplexTextControllerCoreText.mm:
(WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
* platform/spi/cocoa/CoreTextSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206465 => 206466)


--- trunk/Source/WebCore/ChangeLog	2016-09-27 21:54:38 UTC (rev 206465)
+++ trunk/Source/WebCore/ChangeLog	2016-09-27 21:58:56 UTC (rev 206466)
@@ -1,3 +1,30 @@
+2016-09-26  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Improve performance of complex text codepath
+        https://bugs.webkit.org/show_bug.cgi?id=161936
+
+        Reviewed by Simon Fraser.
+
+        CoreText exposes a bit on the CTRunStatus which represents whether
+        the run actually uses the glyph origins concept introduced in
+        r205396. If this bit is not set, we can use the (slightly faster)
+        call to CTRunGetAdvances() instead of
+        CTRunGetBaseAdvancesAndOrigins(). In addition, if none of the runs
+        have this bit set, we don't need to allocate storage for the vector
+        of origins at all, thereby using less memory.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/mac/ComplexTextController.cpp:
+        (WebCore::ComplexTextController::advance):
+        (WebCore::ComplexTextController::adjustGlyphsAndAdvances):
+        * platform/graphics/mac/ComplexTextController.h:
+        (WebCore::ComplexTextController::ComplexTextRun::glyphOrigins):
+        (WebCore::ComplexTextController::glyphOrigin):
+        * platform/graphics/mac/ComplexTextControllerCoreText.mm:
+        (WebCore::ComplexTextController::ComplexTextRun::ComplexTextRun):
+        * platform/spi/cocoa/CoreTextSPI.h:
+
 2016-09-27  Ryosuke Niwa  <rn...@webkit.org>
 
         Import w3c shadow DOM tests and fix one assertion

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp (206465 => 206466)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2016-09-27 21:54:38 UTC (rev 206465)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.cpp	2016-09-27 21:58:56 UTC (rev 206466)
@@ -568,9 +568,9 @@
         if (glyphBuffer && !leftmostGlyph) {
             CGSize initialAdvance = complexTextRun.initialAdvance();
 #if USE_LAYOUT_SPECIFIC_ADVANCES
-            unsigned index = ltr ? 0 : m_glyphOrigins.size() - 1;
-            initialAdvance.width += m_glyphOrigins[index].x;
-            initialAdvance.height += m_glyphOrigins[index].y;
+            unsigned index = ltr ? 0 : m_adjustedBaseAdvances.size() - 1;
+            initialAdvance.width += glyphOrigin(index).x;
+            initialAdvance.height += glyphOrigin(index).y;
 #endif
             glyphBuffer->setInitialAdvance(initialAdvance);
 
@@ -597,8 +597,8 @@
                 GlyphBufferAdvance paintAdvance = adjustedBaseAdvance;
 #if USE_LAYOUT_SPECIFIC_ADVANCES
                 if (k + 1 < m_adjustedBaseAdvances.size()) {
-                    paintAdvance.setWidth(paintAdvance.width() + m_glyphOrigins[k + 1].x - m_glyphOrigins[k].x);
-                    paintAdvance.setHeight(paintAdvance.height() - m_glyphOrigins[k + 1].y + m_glyphOrigins[k].y);
+                    paintAdvance.setWidth(paintAdvance.width() + glyphOrigin(k + 1).x - glyphOrigin(k).x);
+                    paintAdvance.setHeight(paintAdvance.height() - glyphOrigin(k + 1).y + glyphOrigin(k).y);
                 }
 #endif
                 glyphBuffer->add(m_adjustedGlyphs[k], &complexTextRun.font(), paintAdvance, complexTextRun.indexAt(m_glyphInCurrentRun));
@@ -786,7 +786,12 @@
             advance.height *= -1;
             m_adjustedBaseAdvances.append(advance);
 #if USE_LAYOUT_SPECIFIC_ADVANCES
-            m_glyphOrigins.append(complexTextRun.glyphOrigins()[i]);
+            if (auto* origins = complexTextRun.glyphOrigins()) {
+                ASSERT(m_glyphOrigins.size() < m_adjustedBaseAdvances.size());
+                m_glyphOrigins.grow(m_adjustedBaseAdvances.size());
+                m_glyphOrigins[m_glyphOrigins.size() - 1] = origins[i];
+                ASSERT(m_glyphOrigins.size() == m_adjustedBaseAdvances.size());
+            }
 #endif
             m_adjustedGlyphs.append(glyph);
             

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h (206465 => 206466)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2016-09-27 21:54:38 UTC (rev 206465)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextController.h	2016-09-27 21:58:56 UTC (rev 206466)
@@ -39,6 +39,10 @@
 typedef const struct __CTRun * CTRunRef;
 typedef const struct __CTLine * CTLineRef;
 
+namespace WTF {
+template<> struct VectorTraits<CGPoint> : SimpleClassVectorTraits { };
+}
+
 namespace WebCore {
 
 class FontCascade;
@@ -48,7 +52,7 @@
 enum GlyphIterationStyle { IncludePartialGlyphs, ByWholeGlyphs };
 
 // ComplexTextController is responsible for rendering and measuring glyphs for
-// complex scripts on OS X.
+// complex scripts on macOS and iOS.
 class ComplexTextController {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -108,7 +112,7 @@
          */
         CGSize initialAdvance() const { return m_initialAdvance; }
         const CGSize* baseAdvances() const { return m_baseAdvances; }
-        const CGPoint* glyphOrigins() const { return m_glyphOrigins.data(); }
+        const CGPoint* glyphOrigins() const { return m_glyphOrigins.size() == glyphCount() ? m_glyphOrigins.data() : nullptr; }
         bool isLTR() const { return m_isLTR; }
         bool isMonotonic() const { return m_isMonotonic; }
         void setIsNonMonotonic();
@@ -150,6 +154,8 @@
 
     float runWidthSoFarFraction(unsigned glyphStartOffset, unsigned glyphEndOffset, unsigned oldCharacterInCurrentGlyph, GlyphIterationStyle) const;
 
+    CGPoint glyphOrigin(unsigned index) const { return index < m_glyphOrigins.size() ? m_glyphOrigins[index] : CGPointZero; }
+
     Vector<CGSize, 256> m_adjustedBaseAdvances;
     Vector<CGPoint, 256> m_glyphOrigins;
     Vector<CGGlyph, 256> m_adjustedGlyphs;

Modified: trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm (206465 => 206466)


--- trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2016-09-27 21:54:38 UTC (rev 206465)
+++ trunk/Source/WebCore/platform/graphics/mac/ComplexTextControllerCoreText.mm	2016-09-27 21:58:56 UTC (rev 206466)
@@ -133,18 +133,21 @@
     }
 
 #if USE_LAYOUT_SPECIFIC_ADVANCES
-    m_baseAdvancesVector.grow(m_glyphCount);
-    m_glyphOrigins.grow(m_glyphCount);
-    CTRunGetBaseAdvancesAndOrigins(ctRun, CFRangeMake(0, 0), m_baseAdvancesVector.data(), m_glyphOrigins.data());
-    m_baseAdvances = m_baseAdvancesVector.data();
-#else
-    m_baseAdvances = CTRunGetAdvancesPtr(ctRun);
-    if (!m_baseAdvances) {
+    if (CTRunGetStatus(ctRun) & kCTRunStatusHasOrigins) {
         m_baseAdvancesVector.grow(m_glyphCount);
-        CTRunGetAdvances(ctRun, CFRangeMake(0, 0), m_baseAdvancesVector.data());
+        m_glyphOrigins.grow(m_glyphCount);
+        CTRunGetBaseAdvancesAndOrigins(ctRun, CFRangeMake(0, 0), m_baseAdvancesVector.data(), m_glyphOrigins.data());
         m_baseAdvances = m_baseAdvancesVector.data();
+    } else
+#endif
+    {
+        m_baseAdvances = CTRunGetAdvancesPtr(ctRun);
+        if (!m_baseAdvances) {
+            m_baseAdvancesVector.grow(m_glyphCount);
+            CTRunGetAdvances(ctRun, CFRangeMake(0, 0), m_baseAdvancesVector.data());
+            m_baseAdvances = m_baseAdvancesVector.data();
+        }
     }
-#endif
 }
 
 // Missing glyphs run constructor. Core Text will not generate a run of missing glyphs, instead falling back on

Modified: trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h (206465 => 206466)


--- trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2016-09-27 21:54:38 UTC (rev 206465)
+++ trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h	2016-09-27 21:58:56 UTC (rev 206466)
@@ -54,6 +54,10 @@
     kCTFontDescriptorOptionPreferAppleSystemFont = kCTFontOptionsPreferSystemFont
 };
 
+enum {
+    kCTRunStatusHasOrigins = (1 << 4),
+};
+
 #endif
 
 WTF_EXTERN_C_BEGIN
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to