Title: [94936] trunk/Source
Revision
94936
Author
[email protected]
Date
2011-09-11 20:14:42 -0700 (Sun, 11 Sep 2011)

Log Message

[Chromium] Change OOP Font loading code to use CGFont*() APIs.
https://bugs.webkit.org/show_bug.cgi?id=66935

This change is necessary due a bug in ATSFontDeactivate() on 10.7.
See crbug.com/93191 for details.

Reviewed by Eric Seidel.

Source/WebCore:

No new tests - covered by existing tests.

* platform/chromium/PlatformBridge.h:
* platform/graphics/chromium/CrossProcessFontLoading.h:
* platform/graphics/chromium/CrossProcessFontLoading.mm:
(WebCore::MemoryActivatedFont::create):
(WebCore::MemoryActivatedFont::MemoryActivatedFont):
(WebCore::MemoryActivatedFont::~MemoryActivatedFont):

Source/WebKit/chromium:

* public/mac/WebSandboxSupport.h:
* src/PlatformBridge.cpp:
(WebCore::PlatformBridge::loadFont):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (94935 => 94936)


--- trunk/Source/WebCore/ChangeLog	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebCore/ChangeLog	2011-09-12 03:14:42 UTC (rev 94936)
@@ -1,3 +1,22 @@
+2011-09-11  Jeremy Moskovich  <[email protected]>
+
+        [Chromium] Change OOP Font loading code to use CGFont*() APIs.
+        https://bugs.webkit.org/show_bug.cgi?id=66935
+
+        This change is necessary due a bug in ATSFontDeactivate() on 10.7.
+        See crbug.com/93191 for details.
+
+        Reviewed by Eric Seidel.
+
+        No new tests - covered by existing tests.
+
+        * platform/chromium/PlatformBridge.h:
+        * platform/graphics/chromium/CrossProcessFontLoading.h:
+        * platform/graphics/chromium/CrossProcessFontLoading.mm:
+        (WebCore::MemoryActivatedFont::create):
+        (WebCore::MemoryActivatedFont::MemoryActivatedFont):
+        (WebCore::MemoryActivatedFont::~MemoryActivatedFont):
+
 2011-09-09  Oliver Hunt  <[email protected]>
 
         Remove support for anonymous storage from jsobjects

Modified: trunk/Source/WebCore/platform/chromium/PlatformSupport.h (94935 => 94936)


--- trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebCore/platform/chromium/PlatformSupport.h	2011-09-12 03:14:42 UTC (rev 94936)
@@ -152,7 +152,7 @@
     static bool ensureFontLoaded(HFONT);
 #endif
 #if OS(DARWIN)
-    static bool loadFont(NSFont* srcFont, ATSFontContainerRef*, uint32_t* fontID);
+    static bool loadFont(NSFont* srcFont, CGFontRef*, uint32_t* fontID);
 #elif OS(UNIX)
     static void getRenderStyleForStrike(const char* family, int sizeAndStyle, FontRenderStyle* result);
     static String getFontFamilyForCharacters(const UChar*, size_t numCharacters, const char* preferredLocale);

Modified: trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h (94935 => 94936)


--- trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h	2011-09-12 03:14:42 UTC (rev 94936)
@@ -36,8 +36,6 @@
 #import <wtf/text/WTFString.h>
 
 typedef struct CGFont* CGFontRef;
-typedef UInt32 ATSFontContainerRef;
-typedef UInt32 ATSFontRef;
 
 namespace WebCore {
 
@@ -74,25 +72,20 @@
 class MemoryActivatedFont : public RefCounted<MemoryActivatedFont> {
 public:
     // Use to create a new object, see docs on constructor below.
-    static PassRefPtr<MemoryActivatedFont> create(uint32_t fontID, NSFont*, ATSFontContainerRef);
+    static PassRefPtr<MemoryActivatedFont> create(uint32_t fontID, NSFont*, CGFontRef);
     ~MemoryActivatedFont();
     
     // Get cached CGFontRef corresponding to the in-memory font.
     CGFontRef cgFont() { return m_cgFont.get(); }
-    
-    // Get cached ATSFontRef corresponding to the in-memory font.
-    ATSFontRef atsFontRef() { return m_atsFontRef; }
 
 private:
     // srcFontRef - ATSFontRef belonging to the NSFont object that failed to
     // load in-process.
     // container - a font container corresponding to an identical font that
     // we loaded cross-process.
-    MemoryActivatedFont(uint32_t fontID, NSFont*, ATSFontContainerRef);
+    MemoryActivatedFont(uint32_t fontID, NSFont*, CGFontRef);
 
-    ATSFontContainerRef m_fontContainer;
     WTF::RetainPtr<CGFontRef> m_cgFont;
-    ATSFontRef m_atsFontRef;
     uint32_t m_fontID;
     WTF::String m_inSandboxHashKey;
 };

Modified: trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm (94935 => 94936)


--- trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm	2011-09-12 03:14:42 UTC (rev 94936)
@@ -132,68 +132,36 @@
     if (font)
         return font;
 
-    ATSFontContainerRef container;
+    CGFontRef tmpCGFont;
     uint32_t fontID;
     // Send cross-process request to load font.
-    if (!PlatformSupport::loadFont(nsFont, &container, &fontID))
+    if (!PlatformSupport::loadFont(nsFont, &tmpCGFont, &fontID))
         return 0;
 
+    RetainPtr<CGFontRef> cgFont(tmpCGFont);
     // Now that we have the fontID from the browser process, we can consult
     // the ID cache.
     font = fontCacheByFontID().get(fontID);
-    if (font) {
-        // We can safely discard the new container since we already have the
-        // font in our cache.
+    if (font)
         // FIXME: PlatformSupport::loadFont() should consult the id cache
-        // before activating the font.  Then we can save this activate/deactive
-        // dance altogether.
-        ATSFontDeactivate(container, 0, kATSOptionFlagsDefault);
+        // before activating the font.
         return font;
-    }
 
-    return MemoryActivatedFont::create(fontID, nsFont, container);
+    return MemoryActivatedFont::create(fontID, nsFont, cgFont.get());
 }
 
 } // namespace
 
-PassRefPtr<MemoryActivatedFont> MemoryActivatedFont::create(uint32_t fontID, NSFont* nsFont, ATSFontContainerRef container)
+PassRefPtr<MemoryActivatedFont> MemoryActivatedFont::create(uint32_t fontID, NSFont* nsFont, CGFontRef cgFont)
 {
-  MemoryActivatedFont* font = new MemoryActivatedFont(fontID, nsFont, container);
-  if (!font->cgFont())  // Object construction failed.
-  {
-      delete font;
-      return 0;
-  }
-  return adoptRef(font);
+  return adoptRef(new MemoryActivatedFont(fontID, nsFont, cgFont));
 }
 
-MemoryActivatedFont::MemoryActivatedFont(uint32_t fontID, NSFont* nsFont, ATSFontContainerRef container)
-    : m_fontContainer(container)
-    , m_atsFontRef(kATSFontRefUnspecified)
+MemoryActivatedFont::MemoryActivatedFont(uint32_t fontID, NSFont* nsFont, CGFontRef cgFont)
+    : m_cgFont(cgFont)
     , m_fontID(fontID)
     , m_inSandboxHashKey(hashKeyFromNSFont(nsFont))
 {
-    if (!container)
-        return;
-    
-    // Count the number of fonts in the container.
-    ItemCount fontCount = 0;
-    OSStatus err = ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 0, 0, &fontCount);
-    if (err != noErr || fontCount < 1)
-        return;
-
-    // For now always assume that we want the first font in the container.
-    ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 1, &m_atsFontRef, 0);
-
-    if (!m_atsFontRef)
-        return;
-
-    // Cache CGFont representation of the font.
-    m_cgFont.adoptCF(CGFontCreateWithPlatformFont(&m_atsFontRef));
-    
-    if (!m_cgFont)
-        return;
-    
     // Add ourselves to caches.
     fontCacheByFontID().add(fontID, this);
     fontCacheByFontName().add(m_inSandboxHashKey, this);
@@ -203,20 +171,12 @@
 // from cache.
 MemoryActivatedFont::~MemoryActivatedFont()
 {
-    if (m_cgFont) {
-        // First remove ourselves from the caches.
-        ASSERT(fontCacheByFontID().contains(m_fontID));
-        ASSERT(fontCacheByFontName().contains(m_inSandboxHashKey));
-        
-        fontCacheByFontID().remove(m_fontID);
-        fontCacheByFontName().remove(m_inSandboxHashKey);
-        
-        // Make sure the CGFont is destroyed before its font container.
-        m_cgFont.releaseRef();
-    }
-    
-    if (m_fontContainer != kATSFontContainerRefUnspecified)
-        ATSFontDeactivate(m_fontContainer, 0, kATSOptionFlagsDefault);
+    // First remove ourselves from the caches.
+    ASSERT(fontCacheByFontID().contains(m_fontID));
+    ASSERT(fontCacheByFontName().contains(m_inSandboxHashKey));
+
+    fontCacheByFontID().remove(m_fontID);
+    fontCacheByFontName().remove(m_inSandboxHashKey);
 }
 
 // Given an NSFont, try to load a representation of that font into the cgFont

Modified: trunk/Source/WebKit/chromium/ChangeLog (94935 => 94936)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-09-12 03:14:42 UTC (rev 94936)
@@ -1,3 +1,17 @@
+2011-09-11  Jeremy Moskovich  <[email protected]>
+
+        [Chromium] Change OOP Font loading code to use CGFont*() APIs.
+        https://bugs.webkit.org/show_bug.cgi?id=66935
+
+        This change is necessary due a bug in ATSFontDeactivate() on 10.7.
+        See crbug.com/93191 for details.
+
+        Reviewed by Eric Seidel.
+
+        * public/mac/WebSandboxSupport.h:
+        * src/PlatformBridge.cpp:
+        (WebCore::PlatformBridge::loadFont):
+
 2011-09-11  Adam Barth  <[email protected]>
 
         [Chromium] Add more key codes to WebInputEvent for Android

Modified: trunk/Source/WebKit/chromium/public/mac/WebSandboxSupport.h (94935 => 94936)


--- trunk/Source/WebKit/chromium/public/mac/WebSandboxSupport.h	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebKit/chromium/public/mac/WebSandboxSupport.h	2011-09-12 03:14:42 UTC (rev 94936)
@@ -31,7 +31,7 @@
 #ifndef WebSandboxSupport_h
 #define WebSandboxSupport_h
 
-typedef uintptr_t ATSFontContainerRef;
+typedef struct CGFont* CGFontRef;
 
 #ifdef __OBJC__
 @class NSFont;
@@ -45,18 +45,15 @@
 class WebSandboxSupport {
 public:
     // Given an input font - |srcFont| [which can't be loaded due to sandbox
-    // restrictions].  Return a font container belonging to an equivalent
-    // font file that can be used to access the font and a unique identifier
-    // corresponding to the on-disk font file.
+    // restrictions]. Return a font belonging to an equivalent font file
+    // that can be used to access the font and a unique identifier corresponding
+    // to the on-disk font file.
     //
-    // Note that a font container may contain multiple fonts, the caller is
-    // responsible for retreiving the appropriate font from the container.
-    //
     // If this function succeeds, the caller assumes ownership of the |out|
-    // parameter and must call ATSFontDeactivate() to unload it when done.
+    // parameter and must call CGFontRelease() to unload it when done.
     //
     // Returns: true on success, false on error.
-    virtual bool loadFont(NSFont* srcFont, ATSFontContainerRef*, uint32_t* fontID) = 0;
+    virtual bool loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID) = 0;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/PlatformSupport.cpp (94935 => 94936)


--- trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2011-09-12 02:22:54 UTC (rev 94935)
+++ trunk/Source/WebKit/chromium/src/PlatformSupport.cpp	2011-09-12 03:14:42 UTC (rev 94936)
@@ -446,17 +446,17 @@
 #endif
 
 #if OS(DARWIN)
-bool PlatformSupport::loadFont(NSFont* srcFont, ATSFontContainerRef* container, uint32_t* fontID)
+bool PlatformSupport::loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID)
 {
     WebSandboxSupport* ss = webKitPlatformSupport()->sandboxSupport();
     if (ss)
-        return ss->loadFont(srcFont, container, fontID);
+        return ss->loadFont(srcFont, out, fontID);
 
     // This function should only be called in response to an error loading a
     // font due to being blocked by the sandbox.
     // This by definition shouldn't happen if there is no sandbox support.
     ASSERT_NOT_REACHED();
-    *container = 0;
+    *out = 0;
     *fontID = 0;
     return false;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to