Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(878)

Unified Diff: src/ports/SkFontHost_mac.cpp

Issue 693213002: Bisect Mac performance regression. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Bisect5 Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontHost_mac.cpp
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index a63152817a684e702aaec932d7627ceece2804b7..4d346e63600e2265185aba563ee342c9de78b89e 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -351,13 +351,6 @@ Offscreen::Offscreen() : fRGBSpace(NULL), fCG(NULL),
///////////////////////////////////////////////////////////////////////////////
-static bool find_dict_traits(CFDictionaryRef dict, CTFontSymbolicTraits* traits) {
- CFNumberRef num;
- return CFDictionaryGetValueIfPresent(dict, kCTFontSymbolicTrait, (const void**)&num)
- && CFNumberIsFloatType(num)
- && CFNumberGetValue(num, kCFNumberSInt32Type, traits);
-}
-
static bool find_dict_float(CFDictionaryRef dict, CFStringRef name, float* value) {
CFNumberRef num;
return CFDictionaryGetValueIfPresent(dict, name, (const void**)&num)
@@ -385,30 +378,22 @@ static int unit_width_to_fontstyle(float unit) {
return sk_float_round2int(value);
}
-static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc, bool* isFixedPitch) {
+static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc) {
AutoCFRelease<CFDictionaryRef> dict(
(CFDictionaryRef)CTFontDescriptorCopyAttribute(desc, kCTFontTraitsAttribute));
if (NULL == dict.get()) {
return SkFontStyle();
}
- CTFontSymbolicTraits traits;
- if (!find_dict_traits(dict, &traits)) {
- traits = 0;
- }
- if (isFixedPitch) {
- *isFixedPitch = SkToBool(traits & kCTFontMonoSpaceTrait);
- }
-
float weight, width, slant;
if (!find_dict_float(dict, kCTFontWeightTrait, &weight)) {
- weight = (traits & kCTFontBoldTrait) ? 0.5f : 0;
+ weight = 0;
}
if (!find_dict_float(dict, kCTFontWidthTrait, &width)) {
width = 0;
}
if (!find_dict_float(dict, kCTFontSlantTrait, &slant)) {
- slant = (traits & kCTFontItalicTrait) ? 0.5f : 0;
+ slant = 0;
}
return SkFontStyle(unit_weight_to_fontstyle(weight),
@@ -417,6 +402,22 @@ static SkFontStyle fontstyle_from_descriptor(CTFontDescriptorRef desc, bool* isF
: SkFontStyle::kUpright_Slant);
}
+static SkTypeface::Style computeStyleBits(CTFontRef font, bool* isFixedPitch) {
+ unsigned style = SkTypeface::kNormal;
+ CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
+
+ if (traits & kCTFontBoldTrait) {
+ style |= SkTypeface::kBold;
+ }
+ if (traits & kCTFontItalicTrait) {
+ style |= SkTypeface::kItalic;
+ }
+ if (isFixedPitch) {
+ *isFixedPitch = (traits & kCTFontMonoSpaceTrait) != 0;
+ }
+ return (SkTypeface::Style)style;
+}
+
static SkFontID CTFontRef_to_SkFontID(CTFontRef fontRef) {
SkFontID id = 0;
// CTFontGetPlatformFont and ATSFontRef are not supported on iOS, so we have to
@@ -491,8 +492,7 @@ private:
static SkTypeface* NewFromFontRef(CTFontRef fontRef, const char name[], bool isLocalStream) {
SkASSERT(fontRef);
bool isFixedPitch;
- AutoCFRelease<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(fontRef));
- SkFontStyle style = fontstyle_from_descriptor(desc, &isFixedPitch);
+ SkFontStyle style = SkFontStyle(computeStyleBits(fontRef, &isFixedPitch));
SkFontID fontID = CTFontRef_to_SkFontID(fontRef);
return new SkTypeface_Mac(style, fontID, isFixedPitch, fontRef, name, isLocalStream);
@@ -2022,7 +2022,7 @@ static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef
SkString skFamilyName;
CFStringToSkString(cfFamilyName, &skFamilyName);
cacheRequest.fName = skFamilyName.c_str();
- cacheRequest.fStyle = fontstyle_from_descriptor(desc, NULL);
+ cacheRequest.fStyle = fontstyle_from_descriptor(desc);
SkTypeface* face = SkTypefaceCache::FindByProcAndRef(find_by_NameStyle, &cacheRequest);
if (face) {
@@ -2042,8 +2042,7 @@ static SkTypeface* createFromDesc(CFStringRef cfFamilyName, CTFontDescriptorRef
}
bool isFixedPitch;
- AutoCFRelease<CTFontDescriptorRef> ctFontDesc(CTFontCopyFontDescriptor(ctFont));
- (void)fontstyle_from_descriptor(ctFontDesc, &isFixedPitch);
+ (void)computeStyleBits(ctFont, &isFixedPitch);
SkFontID fontID = CTFontRef_to_SkFontID(ctFont);
face = SkNEW_ARGS(SkTypeface_Mac, (cacheRequest.fStyle, fontID, isFixedPitch,
@@ -2078,7 +2077,7 @@ public:
SkASSERT((unsigned)index < (unsigned)fCount);
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, index);
if (style) {
- *style = fontstyle_from_descriptor(desc, NULL);
+ *style = fontstyle_from_descriptor(desc);
}
if (name) {
if (!find_desc_str(desc, kCTFontStyleNameAttribute, name)) {
@@ -2112,7 +2111,7 @@ private:
for (int i = 0; i < fCount; ++i) {
CTFontDescriptorRef desc = (CTFontDescriptorRef)CFArrayGetValueAtIndex(fArray, i);
- int metric = compute_metric(pattern, fontstyle_from_descriptor(desc, NULL));
+ int metric = compute_metric(pattern, fontstyle_from_descriptor(desc));
if (0 == metric) {
return desc;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698