Title: [184796] trunk/Source/WebCore
Revision
184796
Author
mmaxfi...@apple.com
Date
2015-05-22 14:43:14 -0700 (Fri, 22 May 2015)

Log Message

[Cocoa] Use CTFontDrawGlyphs() instead of CGContextShowGlyphsWithAdvances()/CGContextShowGlyphsAtPositions()
https://bugs.webkit.org/show_bug.cgi?id=145234

Reviewed by Enrica Casucci.

Eventually, we want to migrate entirely off of text-related CoreGraphics calls
and onto CoreText calls (in order to reduce complexity as well as eventually
removing the need for FontPlatformData to hold a CGFontRef). There is an
equivalent call to CGContextShowGlyphsWithAdvances() and
CGContextShowGlyphsAtPositions(), namely, CTFontDrawGlyphs(), which we have
found is as performant as its CoreGraphics counterparts. This patch simply
migrates these two CG calls to its CT counterpart.

Performance was measured on a iPhone 4s as well as a Mid 2010 Mac Pro.

No new tests because there is no behavior change.

* platform/graphics/cocoa/FontCascadeCocoa.mm:
(WebCore::showGlyphsWithAdvances):
(WebCore::FontCascade::drawGlyphs):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (184795 => 184796)


--- trunk/Source/WebCore/ChangeLog	2015-05-22 21:23:16 UTC (rev 184795)
+++ trunk/Source/WebCore/ChangeLog	2015-05-22 21:43:14 UTC (rev 184796)
@@ -1,3 +1,26 @@
+2015-05-22  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Cocoa] Use CTFontDrawGlyphs() instead of CGContextShowGlyphsWithAdvances()/CGContextShowGlyphsAtPositions()
+        https://bugs.webkit.org/show_bug.cgi?id=145234
+
+        Reviewed by Enrica Casucci.
+
+        Eventually, we want to migrate entirely off of text-related CoreGraphics calls
+        and onto CoreText calls (in order to reduce complexity as well as eventually
+        removing the need for FontPlatformData to hold a CGFontRef). There is an
+        equivalent call to CGContextShowGlyphsWithAdvances() and
+        CGContextShowGlyphsAtPositions(), namely, CTFontDrawGlyphs(), which we have
+        found is as performant as its CoreGraphics counterparts. This patch simply
+        migrates these two CG calls to its CT counterpart.
+
+        Performance was measured on a iPhone 4s as well as a Mid 2010 Mac Pro.
+
+        No new tests because there is no behavior change.
+
+        * platform/graphics/cocoa/FontCascadeCocoa.mm:
+        (WebCore::showGlyphsWithAdvances):
+        (WebCore::FontCascade::drawGlyphs):
+
 2015-05-22  Eric Carlson  <eric.carl...@apple.com>
 
         [Mac] Don't show default controls after playing to wireless target

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm (184795 => 184796)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-22 21:23:16 UTC (rev 184795)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm	2015-05-22 21:43:14 UTC (rev 184796)
@@ -190,12 +190,10 @@
 
     const FontPlatformData& platformData = font->platformData();
     Vector<CGPoint, 256> positions(count);
-    if (platformData.isColorBitmapFont())
-        fillVectorWithHorizontalGlyphPositions(positions, context, advances, count);
+    fillVectorWithHorizontalGlyphPositions(positions, context, advances, count);
     if (platformData.orientation() == Vertical) {
-        CGAffineTransform savedMatrix;
         CGAffineTransform rotateLeftTransform = CGAffineTransformMake(0, -1, 1, 0, 0, 0);
-        savedMatrix = CGContextGetTextMatrix(context);
+        CGAffineTransform savedMatrix = CGContextGetTextMatrix(context);
         CGAffineTransform runMatrix = CGAffineTransformConcat(savedMatrix, rotateLeftTransform);
         CGContextSetTextMatrix(context, runMatrix);
 
@@ -211,21 +209,10 @@
             position.x += advances[i].width;
             position.y += advances[i].height;
         }
-        if (!platformData.isColorBitmapFont()) {
-            RenderingStyleSaver saver(platformData.ctFont(), context);
-            CGContextShowGlyphsAtPositions(context, glyphs, positions.data(), count);
-        } else
-            CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
+        CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
         CGContextSetTextMatrix(context, savedMatrix);
     } else {
-        if (!platformData.isColorBitmapFont()) {
-            RenderingStyleSaver saver(platformData.ctFont(), context);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-            CGContextShowGlyphsWithAdvances(context, glyphs, advances, count);
-#pragma clang diagnostic pop
-        } else
-            CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
+        CTFontDrawGlyphs(platformData.ctFont(), glyphs, positions.data(), count, context);
     }
 }
 
@@ -371,24 +358,13 @@
     }
 #endif
 #endif
-
-#if !PLATFORM(IOS)
-    NSFont* drawFont = [platformData.nsFont() printerFont];
-#endif
     
     CGContextSetFont(cgContext, platformData.cgFont());
 
     bool useLetterpressEffect = shouldUseLetterpressEffect(*context);
     FloatPoint point = pointAdjustedForEmoji(platformData, anchorPoint);
 
-#if PLATFORM(IOS)
-    float fontSize = platformData.size();
-    CGAffineTransform matrix = useLetterpressEffect || platformData.isColorBitmapFont() ? CGAffineTransformIdentity : CGAffineTransformMakeScale(fontSize, fontSize);
-#else
-    CGAffineTransform matrix = CGAffineTransformIdentity;
-    if (drawFont && !platformData.isColorBitmapFont())
-        memcpy(&matrix, [drawFont matrix], sizeof(matrix));
-#endif
+    CGAffineTransform matrix = CTFontGetMatrix(platformData.ctFont());
     matrix.b = -matrix.b;
     matrix.d = -matrix.d;
     if (platformData.m_syntheticOblique) {
@@ -401,17 +377,11 @@
     CGContextSetTextMatrix(cgContext, matrix);
 
 #if PLATFORM(IOS)
-    CGContextSetFontSize(cgContext, 1);
     CGContextSetShouldSubpixelQuantizeFonts(cgContext, context->shouldSubpixelQuantizeFonts());
 #else
-    setCGFontRenderingMode(cgContext, [drawFont renderingMode], context->shouldSubpixelQuantizeFonts());
-    if (drawFont)
-        CGContextSetFontSize(cgContext, 1);
-    else
-        CGContextSetFontSize(cgContext, platformData.m_size);
+    setCGFontRenderingMode(cgContext, [[platformData.nsFont() printerFont] renderingMode], context->shouldSubpixelQuantizeFonts());
 #endif
 
-
     FloatSize shadowOffset;
     float shadowBlur;
     Color shadowColor;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to