aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbungeman <bungeman@google.com>2014-11-04 10:27:35 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-04 10:27:35 -0800
commit47eda52e8fb88f0725b401762a3e0bddc98e9fb3 (patch)
tree1f44bdbccabb4c6d6df1bb3feac360357cf2536d
parentd86b07a8ffd852138f6a6a35658ca470aaab322f (diff)
downloadskia-47eda52e8fb88f0725b401762a3e0bddc98e9fb3.tar.gz
With https://chromium.googlesource.com/skia/+/43b8b36b20ae00e2d78421c4cda1f3f922983a20 blink_perf.layout regressed. It appears that the typeface cache is being missed. This is a partial revert of the Skia change which reverts the smallest amount of code to restore performance.
BUG=chromium:425566 Review URL: https://codereview.chromium.org/693213002
-rwxr-xr-xsrc/ports/SkFontHost_mac.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index a63152817..4d346e636 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;
}