WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
160896
[Cocoa] Reduce uses of CGFonts
https://bugs.webkit.org/show_bug.cgi?id=160896
Summary
[Cocoa] Reduce uses of CGFonts
Myles C. Maxfield
Reported
2016-08-16 02:17:53 PDT
[Cocoa] Reduce uses of CGFonts
Attachments
WIP
(22.81 KB, patch)
2016-08-16 02:22 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
WIP
(38.47 KB, patch)
2016-08-16 02:37 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews106 for mac-yosemite-wk2
(1.17 MB, application/zip)
2016-08-16 11:45 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews116 for mac-yosemite
(1.08 MB, application/zip)
2016-08-16 12:08 PDT
,
Build Bot
no flags
Details
WIP
(41.91 KB, patch)
2016-08-16 12:43 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
WIP
(44.58 KB, patch)
2016-08-16 16:10 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(45.46 KB, patch)
2016-08-16 17:15 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews100 for mac-yosemite
(1.12 MB, application/zip)
2016-08-16 18:08 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews112 for mac-yosemite
(1.47 MB, application/zip)
2016-08-16 18:17 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2
(404.89 KB, application/zip)
2016-08-16 18:21 PDT
,
Build Bot
no flags
Details
WIP
(47.59 KB, patch)
2016-08-17 03:34 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
WIP
(45.81 KB, patch)
2016-08-18 14:25 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
WIP
(47.56 KB, patch)
2016-08-18 14:45 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(48.74 KB, patch)
2016-08-18 15:55 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2
(376.96 KB, application/zip)
2016-08-18 16:59 PDT
,
Build Bot
no flags
Details
WIP
(49.34 KB, patch)
2016-08-18 17:08 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(49.37 KB, patch)
2016-08-18 23:34 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
WIP
(49.74 KB, patch)
2016-08-19 00:52 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(50.32 KB, patch)
2016-08-19 02:47 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(50.26 KB, patch)
2016-08-19 02:55 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews100 for mac-yosemite
(862.02 KB, application/zip)
2016-08-19 03:48 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews107 for mac-yosemite-wk2
(835.41 KB, application/zip)
2016-08-19 03:49 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews113 for mac-yosemite
(1.48 MB, application/zip)
2016-08-19 04:02 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews125 for ios-simulator-elcapitan-wk2
(723.50 KB, application/zip)
2016-08-19 04:47 PDT
,
Build Bot
no flags
Details
WIP
(50.27 KB, patch)
2016-08-19 11:05 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch
(50.28 KB, patch)
2016-08-19 11:17 PDT
,
Myles C. Maxfield
darin
: review+
Details
Formatted Diff
Diff
Patch for committing
(52.49 KB, patch)
2016-08-22 22:59 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Patch for committing
(52.52 KB, patch)
2016-08-23 00:25 PDT
,
Myles C. Maxfield
buildbot
: commit-queue-
Details
Formatted Diff
Diff
Archive of layout-test-results from ews125 for ios-simulator-elcapitan-wk2
(265.88 KB, application/zip)
2016-08-23 01:13 PDT
,
Build Bot
no flags
Details
Patch for committing
(52.61 KB, patch)
2016-08-23 13:21 PDT
,
Myles C. Maxfield
no flags
Details
Formatted Diff
Diff
Show Obsolete
(28)
View All
Add attachment
proposed patch, testcase, etc.
Myles C. Maxfield
Comment 1
2016-08-16 02:22:29 PDT
Created
attachment 286170
[details]
WIP
Myles C. Maxfield
Comment 2
2016-08-16 02:37:13 PDT
Created
attachment 286171
[details]
WIP
Build Bot
Comment 3
2016-08-16 11:45:31 PDT
Comment on
attachment 286171
[details]
WIP
Attachment 286171
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.webkit.org/results/1882508
Number of test failures exceeded the failure limit.
Build Bot
Comment 4
2016-08-16 11:45:35 PDT
Created
attachment 286187
[details]
Archive of layout-test-results from ews106 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Build Bot
Comment 5
2016-08-16 12:08:10 PDT
Comment on
attachment 286171
[details]
WIP
Attachment 286171
[details]
did not pass mac-debug-ews (mac): Output:
http://webkit-queues.webkit.org/results/1882562
Number of test failures exceeded the failure limit.
Build Bot
Comment 6
2016-08-16 12:08:13 PDT
Created
attachment 286191
[details]
Archive of layout-test-results from ews116 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews116 Port: mac-yosemite Platform: Mac OS X 10.10.5
Myles C. Maxfield
Comment 7
2016-08-16 12:43:14 PDT
Created
attachment 286193
[details]
WIP
Myles C. Maxfield
Comment 8
2016-08-16 16:10:25 PDT
Created
attachment 286224
[details]
WIP
Myles C. Maxfield
Comment 9
2016-08-16 17:15:48 PDT
Created
attachment 286237
[details]
Patch
Build Bot
Comment 10
2016-08-16 18:08:09 PDT
Comment on
attachment 286237
[details]
Patch
Attachment 286237
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.webkit.org/results/1884168
New failing tests: fast/attachment/attachment-icon-from-file-extension.html
Build Bot
Comment 11
2016-08-16 18:08:13 PDT
Created
attachment 286242
[details]
Archive of layout-test-results from ews100 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 12
2016-08-16 18:17:46 PDT
Comment on
attachment 286237
[details]
Patch
Attachment 286237
[details]
did not pass mac-debug-ews (mac): Output:
http://webkit-queues.webkit.org/results/1884171
New failing tests: fast/attachment/attachment-icon-from-file-extension.html
Build Bot
Comment 13
2016-08-16 18:17:49 PDT
Created
attachment 286243
[details]
Archive of layout-test-results from ews112 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews112 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 14
2016-08-16 18:21:49 PDT
Comment on
attachment 286237
[details]
Patch
Attachment 286237
[details]
did not pass ios-sim-ews (ios-simulator-wk2): Output:
http://webkit-queues.webkit.org/results/1884155
Number of test failures exceeded the failure limit.
Build Bot
Comment 15
2016-08-16 18:21:52 PDT
Created
attachment 286245
[details]
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews123 Port: ios-simulator-elcapitan-wk2 Platform: Mac OS X 10.11.5
Myles C. Maxfield
Comment 16
2016-08-17 03:34:21 PDT
Created
attachment 286295
[details]
WIP
Myles C. Maxfield
Comment 17
2016-08-18 14:25:04 PDT
Created
attachment 286394
[details]
WIP
Myles C. Maxfield
Comment 18
2016-08-18 14:45:37 PDT
Created
attachment 286400
[details]
WIP
Myles C. Maxfield
Comment 19
2016-08-18 15:55:16 PDT
Created
attachment 286408
[details]
Patch
Build Bot
Comment 20
2016-08-18 16:59:23 PDT
Comment on
attachment 286408
[details]
Patch
Attachment 286408
[details]
did not pass ios-sim-ews (ios-simulator-wk2): Output:
http://webkit-queues.webkit.org/results/1895384
Number of test failures exceeded the failure limit.
Build Bot
Comment 21
2016-08-18 16:59:27 PDT
Created
attachment 286416
[details]
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews123 Port: ios-simulator-elcapitan-wk2 Platform: Mac OS X 10.11.5
Myles C. Maxfield
Comment 22
2016-08-18 17:08:00 PDT
Created
attachment 286419
[details]
WIP
Myles C. Maxfield
Comment 23
2016-08-18 23:34:32 PDT
Created
attachment 286442
[details]
Patch
Myles C. Maxfield
Comment 24
2016-08-19 00:52:16 PDT
Created
attachment 286443
[details]
WIP
Myles C. Maxfield
Comment 25
2016-08-19 02:47:45 PDT
Created
attachment 286445
[details]
Patch
Myles C. Maxfield
Comment 26
2016-08-19 02:55:12 PDT
Created
attachment 286446
[details]
Patch
Build Bot
Comment 27
2016-08-19 03:47:57 PDT
Comment on
attachment 286446
[details]
Patch
Attachment 286446
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.webkit.org/results/1898022
New failing tests: fast/text/international/vertical-text-glyph-test.html fast/text/international/vertical-text-metrics-test.html
Build Bot
Comment 28
2016-08-19 03:48:02 PDT
Created
attachment 286448
[details]
Archive of layout-test-results from ews100 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 29
2016-08-19 03:49:28 PDT
Comment on
attachment 286446
[details]
Patch
Attachment 286446
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.webkit.org/results/1898021
New failing tests: fast/text/international/vertical-text-glyph-test.html fast/text/international/vertical-text-metrics-test.html
Build Bot
Comment 30
2016-08-19 03:49:31 PDT
Created
attachment 286449
[details]
Archive of layout-test-results from ews107 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews107 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Build Bot
Comment 31
2016-08-19 04:02:05 PDT
Comment on
attachment 286446
[details]
Patch
Attachment 286446
[details]
did not pass mac-debug-ews (mac): Output:
http://webkit-queues.webkit.org/results/1898028
New failing tests: fast/text/international/vertical-text-glyph-test.html fast/text/international/vertical-text-metrics-test.html
Build Bot
Comment 32
2016-08-19 04:02:09 PDT
Created
attachment 286450
[details]
Archive of layout-test-results from ews113 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews113 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 33
2016-08-19 04:47:20 PDT
Comment on
attachment 286446
[details]
Patch
Attachment 286446
[details]
did not pass ios-sim-ews (ios-simulator-wk2): Output:
http://webkit-queues.webkit.org/results/1898087
New failing tests: svg/custom/glyph-transformation-with-hkern.svg
Build Bot
Comment 34
2016-08-19 04:47:24 PDT
Created
attachment 286451
[details]
Archive of layout-test-results from ews125 for ios-simulator-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews125 Port: ios-simulator-elcapitan-wk2 Platform: Mac OS X 10.11.5
Myles C. Maxfield
Comment 35
2016-08-19 11:05:13 PDT
Created
attachment 286462
[details]
WIP
Myles C. Maxfield
Comment 36
2016-08-19 11:17:57 PDT
Created
attachment 286464
[details]
Patch
Darin Adler
Comment 37
2016-08-20 19:01:30 PDT
Comment on
attachment 286464
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=286464&action=review
> Source/WebCore/platform/graphics/FontMetrics.h:35 > FontMetrics() > - : m_unitsPerEm(gDefaultUnitsPerEm) > - , m_ascent(0) > - , m_descent(0) > - , m_lineGap(0) > - , m_lineSpacing(0) > - , m_xHeight(0) > - , m_zeroWidth(0) > - , m_hasXHeight(false) > - , m_hasZeroWidth(false) > { > }
We should just omit this constructor entirely. The compiler will generate it without us defining it.
> Source/WebCore/platform/graphics/FontMetrics.h:100 > - int capHeight() const { return lroundf(m_capHeight); } > + int capHeight() const { return lroundf(m_capHeight.value()); }
This is a change in behavior. We will now assert if this is called when we don’t have a cap height; before we would presumably return 0. Should this return valueOr(0)?
> Source/WebCore/platform/graphics/FontMetrics.h:125 > + unsigned m_unitsPerEm { gDefaultUnitsPerEm };
Naming here with "g" is so peculiar.
> Source/WebCore/platform/graphics/FontMetrics.h:132 > + Optional<float> m_xHeight; > + Optional<float> m_capHeight;
This does not seem right. The code in this class seems to handle Nullopt and 0 identically for both of these. I can’t find any code that handled a missing height differently from 0. Although some of the new code will now abort inside Optional in that case.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:92 > + RetainPtr<NSString> familyName = adoptNS((NSString *)CTFontCopyFamilyName(font));
The reason we have separate adoptNS and adoptCF functions was originally that under garbage collection the two operations are different. It’s generally not OK to just cast a CF pointer to NS and then do the adopt in the NS context. At the moment it might be OK since WebKit no longer supports garbage collection, but later when adopt ARC it will again likely be important to not use adoptNS on a CF Copy/Create function result. So this needs to use adoptCF instead of adoptNS. We can still cast the result to NSString if we want to use NS methods on it, but not in the RetainPtr. We could also just use CFStringCompare or put in a WTF::String and use equalIgnoringASCIICase functions.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:94 > + if (![familyName length]) > + return false;
I don’t think it’s important to optimize the empty string case. I am guessing this is because some other code path was going to use CFStringCompare and in that case we need a null check.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:101 > + if ([familyName.get() compare:@"Times" options:NSCaseInsensitiveSearch] == NSOrderedSame > + || [familyName.get() compare:@"Helvetica" options:NSCaseInsensitiveSearch] == NSOrderedSame > + || [familyName.get() compare:@".Helvetica NeueUI" options:NSCaseInsensitiveSearch] == NSOrderedSame) > + return true; > + > + return false;
Typically instead of if (x) return true; return false; we just return x;
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:144 > + RetainPtr<CFStringRef> familyName = adoptCF(CTFontCopyFamilyName(m_platformData.font()));
I suggest using auto here for the RetainPtr type.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:145 > +#if !PLATFORM(IOS)
I think this is clearer as #if PLATFORM(MAC).
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:154 > ascent += floorf(((ascent + descent) * 0.15f) + 0.5f);
Should use std::floor instead of floorf. Also seems like this is rounding, so I would think std::round would be better than std::floor(x + 0.5). Also seems that the "is this one of the three font family names that need adjustment" code should go into a helper function.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:176 > + float xHeight = CGFontGetDescriptor(m_platformData.cgFont(), &descriptor) ? (descriptor.xHeight / 1000) * CTFontGetSize(m_platformData.font()) : 0;
Should consider using auto here instead of float.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:180 > + lineGap = ceilf(lineGap); > + lineSpacing = ceil(ascent) + adjustment + ceil(descent) + lineGap; > + ascent = ceilf(ascent + adjustment); > + descent = ceilf(descent);
Should use std::ceil instead of ceilf/ceil, which end up converting back and forth between float and double. In general this code seems confused about float vs. double vs. CGFloat and this will lead to slowness as we convert things back and forth.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:212 > + RetainPtr<CFDataRef> os2Table = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableOS2, kCTFontTableOptionNoOptions));
auto
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:219 > + RetainPtr<CFDataRef> headTable = adoptCF(CTFontCopyTable(m_platformData.font(), kCTFontTableHead, kCTFontTableOptionNoOptions));
auto
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:566 > + int fixedPitch = 0; > + if (RetainPtr<CFNumberRef> fixedPitchNumber = adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(m_platformData.font(), kCTFontFixedAdvanceAttribute)))) > + CFNumberGetValue(fixedPitchNumber.get(), kCFNumberIntType, &fixedPitch);
I think auto is better here than RetainPtr<CFNumberRef>. But also, I think a helper function to get an int out of a possibly-null CFNumberRef would make this cleaner.
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:567 > + m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || fixedPitch || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva")));
The caseInsensitiveCompare function used here should be used elsewhere in this file. I see lots of other places both above and below that do not use it.
> Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm:169 > + RetainPtr<CFStringRef> fontDescription = adoptCF(CFCopyDescription(font()));
Please use auto here.
> Source/WebCore/platform/graphics/opentype/OpenTypeCG.cpp:60 > + if (RetainPtr<CFDataRef> os2Table = adoptCF(CTFontCopyTable(font, kCTFontTableOS2, kCTFontTableOptionNoOptions))) {
auto
> Source/WebCore/platform/graphics/win/FontCGWin.cpp:176 > + CGAffineTransform savedMatrix = CGContextGetTextMatrix(cgContext); > CGContextSetTextMatrix(cgContext, matrix);
Annoying to not have the ScopedTextMatrix to use here. Is there a header for CG within WebCore that we can use?
Myles C. Maxfield
Comment 38
2016-08-22 22:59:21 PDT
Created
attachment 286680
[details]
Patch for committing
Myles C. Maxfield
Comment 39
2016-08-23 00:25:26 PDT
Created
attachment 286687
[details]
Patch for committing
Build Bot
Comment 40
2016-08-23 01:13:28 PDT
Comment on
attachment 286687
[details]
Patch for committing
Attachment 286687
[details]
did not pass ios-sim-ews (ios-simulator-wk2): Output:
http://webkit-queues.webkit.org/results/1926331
Number of test failures exceeded the failure limit.
Build Bot
Comment 41
2016-08-23 01:13:32 PDT
Created
attachment 286690
[details]
Archive of layout-test-results from ews125 for ios-simulator-elcapitan-wk2 The attached test failures were seen while running run-webkit-tests on the ios-sim-ews. Bot: ews125 Port: ios-simulator-elcapitan-wk2 Platform: Mac OS X 10.11.5
Myles C. Maxfield
Comment 42
2016-08-23 13:13:45 PDT
Comment on
attachment 286687
[details]
Patch for committing View in context:
https://bugs.webkit.org/attachment.cgi?id=286687&action=review
> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:99 > + if (!familyName || CFStringGetLength(familyName.get()))
Whoops.
Myles C. Maxfield
Comment 43
2016-08-23 13:15:11 PDT
Comment on
attachment 286464
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=286464&action=review
>> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:176 >> + float xHeight = CGFontGetDescriptor(m_platformData.cgFont(), &descriptor) ? (descriptor.xHeight / 1000) * CTFontGetSize(m_platformData.font()) : 0; > > Should consider using auto here instead of float.
Unfortunately, tests start failing if you change the precision. I intend to fix this, but I will do it in a separate patch because this one is supposed to have no behavior change.
>> Source/WebCore/platform/graphics/cocoa/FontCocoa.mm:180 >> + descent = ceilf(descent); > > Should use std::ceil instead of ceilf/ceil, which end up converting back and forth between float and double. > > In general this code seems confused about float vs. double vs. CGFloat and this will lead to slowness as we convert things back and forth.
Ditto.
Myles C. Maxfield
Comment 44
2016-08-23 13:21:21 PDT
Created
attachment 286763
[details]
Patch for committing
Myles C. Maxfield
Comment 45
2016-08-23 14:13:06 PDT
Committed
r204858
: <
http://trac.webkit.org/changeset/204858
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug