summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 23:45:28 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-29 23:45:28 +0000
commit84683f0a267ff5f9396321a546615a64566ff444 (patch)
treeb9b21f7e24b3f7d92e5e6933551d3bdd23a855ff /base
parent42b80efc8d8588bf369f428129333c7447070ebd (diff)
downloadchromium_src-84683f0a267ff5f9396321a546615a64566ff444.zip
chromium_src-84683f0a267ff5f9396321a546615a64566ff444.tar.gz
chromium_src-84683f0a267ff5f9396321a546615a64566ff444.tar.bz2
Make RenderTextMac more efficient by caching fonts and taking advantage of toll-free bridging of CT/NSFont.
BUG=312436 TEST=no console spew as in bug R=asvitkine@chromium.org, mark@chromium.org, shess@chromium.org Review URL: https://codereview.chromium.org/49503003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/mac/foundation_util.h10
-rw-r--r--base/mac/foundation_util.mm60
2 files changed, 69 insertions, 1 deletions
diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h
index 447f7bf..46ea3c3 100644
--- a/base/mac/foundation_util.h
+++ b/base/mac/foundation_util.h
@@ -16,10 +16,14 @@
#if defined(__OBJC__)
#import <Foundation/Foundation.h>
+@class NSFont;
+@class UIFont;
#else // __OBJC__
#include <CoreFoundation/CoreFoundation.h>
class NSBundle;
+class NSFont;
class NSString;
+class UIFont;
#endif // __OBJC__
#if defined(OS_IOS)
@@ -225,6 +229,12 @@ CF_TO_NS_CAST_DECL(CFWriteStream, NSOutputStream);
CF_TO_NS_MUTABLE_CAST_DECL(String);
CF_TO_NS_CAST_DECL(CFURL, NSURL);
+#if defined(OS_IOS)
+CF_TO_NS_CAST_DECL(CTFont, UIFont);
+#else
+CF_TO_NS_CAST_DECL(CTFont, NSFont);
+#endif
+
#undef CF_TO_NS_CAST_DECL
#undef CF_TO_NS_MUTABLE_CAST_DECL
#undef OBJC_CPP_CLASS_DECL
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 5f8f694..1c75349 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -17,6 +17,7 @@
extern "C" {
CFTypeID SecACLGetTypeID();
CFTypeID SecTrustedApplicationGetTypeID();
+Boolean _CFIsObjC(CFTypeID typeID, CFTypeRef obj);
} // extern "C"
#endif
@@ -312,6 +313,31 @@ CF_TO_NS_CAST_DEFN(CFWriteStream, NSOutputStream);
CF_TO_NS_MUTABLE_CAST_DEFN(String);
CF_TO_NS_CAST_DEFN(CFURL, NSURL);
+#if defined(OS_IOS)
+CF_TO_NS_CAST_DEFN(CTFont, UIFont);
+#else
+// The NSFont/CTFont toll-free bridging is broken when it comes to type
+// checking, so do some special-casing.
+// http://www.openradar.me/15341349 rdar://15341349
+NSFont* CFToNSCast(CTFontRef cf_val) {
+ NSFont* ns_val =
+ const_cast<NSFont*>(reinterpret_cast<const NSFont*>(cf_val));
+ DCHECK(!cf_val ||
+ CTFontGetTypeID() == CFGetTypeID(cf_val) ||
+ (_CFIsObjC(CTFontGetTypeID(), cf_val) &&
+ [ns_val isKindOfClass:NSClassFromString(@"NSFont")]));
+ return ns_val;
+}
+
+CTFontRef NSToCFCast(NSFont* ns_val) {
+ CTFontRef cf_val = reinterpret_cast<CTFontRef>(ns_val);
+ DCHECK(!cf_val ||
+ CTFontGetTypeID() == CFGetTypeID(cf_val) ||
+ [ns_val isKindOfClass:NSClassFromString(@"NSFont")]);
+ return cf_val;
+}
+#endif
+
#undef CF_TO_NS_CAST_DEFN
#undef CF_TO_NS_MUTABLE_CAST_DEFN
@@ -349,9 +375,41 @@ CF_CAST_DEFN(CFUUID);
CF_CAST_DEFN(CGColor);
-CF_CAST_DEFN(CTFont);
CF_CAST_DEFN(CTRun);
+#if defined(OS_IOS)
+CF_CAST_DEFN(CTFont);
+#else
+// The NSFont/CTFont toll-free bridging is broken when it comes to type
+// checking, so do some special-casing.
+// http://www.openradar.me/15341349 rdar://15341349
+template<> CTFontRef
+CFCast<CTFontRef>(const CFTypeRef& cf_val) {
+ if (cf_val == NULL) {
+ return NULL;
+ }
+ if (CFGetTypeID(cf_val) == CTFontGetTypeID()) {
+ return (CTFontRef)(cf_val);
+ }
+
+ if (!_CFIsObjC(CTFontGetTypeID(), cf_val))
+ return NULL;
+
+ id<NSObject> ns_val = reinterpret_cast<id>(const_cast<void*>(cf_val));
+ if ([ns_val isKindOfClass:NSClassFromString(@"NSFont")]) {
+ return (CTFontRef)(cf_val);
+ }
+ return NULL;
+}
+
+template<> CTFontRef
+CFCastStrict<CTFontRef>(const CFTypeRef& cf_val) {
+ CTFontRef rv = CFCast<CTFontRef>(cf_val);
+ DCHECK(cf_val == NULL || rv);
+ return rv;
+}
+#endif
+
#if !defined(OS_IOS)
CF_CAST_DEFN(SecACL);
CF_CAST_DEFN(SecTrustedApplication);