Changeset 94936 in webkit


Ignore:
Timestamp:
Sep 11, 2011 8:14:42 PM (13 years ago)
Author:
jeremy@chromium.org
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):

Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r94929 r94936  
     12011-09-11  Jeremy Moskovich  <jeremy@chromium.org>
     2
     3        [Chromium] Change OOP Font loading code to use CGFont*() APIs.
     4        https://bugs.webkit.org/show_bug.cgi?id=66935
     5
     6        This change is necessary due a bug in ATSFontDeactivate() on 10.7.
     7        See crbug.com/93191 for details.
     8
     9        Reviewed by Eric Seidel.
     10
     11        No new tests - covered by existing tests.
     12
     13        * platform/chromium/PlatformBridge.h:
     14        * platform/graphics/chromium/CrossProcessFontLoading.h:
     15        * platform/graphics/chromium/CrossProcessFontLoading.mm:
     16        (WebCore::MemoryActivatedFont::create):
     17        (WebCore::MemoryActivatedFont::MemoryActivatedFont):
     18        (WebCore::MemoryActivatedFont::~MemoryActivatedFont):
     19
    1202011-09-09  Oliver Hunt  <oliver@apple.com>
    221
  • trunk/Source/WebCore/platform/chromium/PlatformSupport.h

    r94504 r94936  
    153153#endif
    154154#if OS(DARWIN)
    155     static bool loadFont(NSFont* srcFont, ATSFontContainerRef*, uint32_t* fontID);
     155    static bool loadFont(NSFont* srcFont, CGFontRef*, uint32_t* fontID);
    156156#elif OS(UNIX)
    157157    static void getRenderStyleForStrike(const char* family, int sizeAndStyle, FontRenderStyle* result);
  • trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.h

    r92269 r94936  
    3737
    3838typedef struct CGFont* CGFontRef;
    39 typedef UInt32 ATSFontContainerRef;
    40 typedef UInt32 ATSFontRef;
    4139
    4240namespace WebCore {
     
    7573public:
    7674    // Use to create a new object, see docs on constructor below.
    77     static PassRefPtr<MemoryActivatedFont> create(uint32_t fontID, NSFont*, ATSFontContainerRef);
     75    static PassRefPtr<MemoryActivatedFont> create(uint32_t fontID, NSFont*, CGFontRef);
    7876    ~MemoryActivatedFont();
    7977   
    8078    // Get cached CGFontRef corresponding to the in-memory font.
    8179    CGFontRef cgFont() { return m_cgFont.get(); }
    82    
    83     // Get cached ATSFontRef corresponding to the in-memory font.
    84     ATSFontRef atsFontRef() { return m_atsFontRef; }
    8580
    8681private:
     
    8984    // container - a font container corresponding to an identical font that
    9085    // we loaded cross-process.
    91     MemoryActivatedFont(uint32_t fontID, NSFont*, ATSFontContainerRef);
     86    MemoryActivatedFont(uint32_t fontID, NSFont*, CGFontRef);
    9287
    93     ATSFontContainerRef m_fontContainer;
    9488    WTF::RetainPtr<CGFontRef> m_cgFont;
    95     ATSFontRef m_atsFontRef;
    9689    uint32_t m_fontID;
    9790    WTF::String m_inSandboxHashKey;
  • trunk/Source/WebCore/platform/graphics/chromium/CrossProcessFontLoading.mm

    r94275 r94936  
    133133        return font;
    134134
    135     ATSFontContainerRef container;
     135    CGFontRef tmpCGFont;
    136136    uint32_t fontID;
    137137    // Send cross-process request to load font.
    138     if (!PlatformSupport::loadFont(nsFont, &container, &fontID))
     138    if (!PlatformSupport::loadFont(nsFont, &tmpCGFont, &fontID))
    139139        return 0;
    140140
     141    RetainPtr<CGFontRef> cgFont(tmpCGFont);
    141142    // Now that we have the fontID from the browser process, we can consult
    142143    // the ID cache.
    143144    font = fontCacheByFontID().get(fontID);
    144     if (font) {
    145         // We can safely discard the new container since we already have the
    146         // font in our cache.
     145    if (font)
    147146        // FIXME: PlatformSupport::loadFont() should consult the id cache
    148         // before activating the font.  Then we can save this activate/deactive
    149         // dance altogether.
    150         ATSFontDeactivate(container, 0, kATSOptionFlagsDefault);
     147        // before activating the font.
    151148        return font;
    152     }
    153 
    154     return MemoryActivatedFont::create(fontID, nsFont, container);
     149
     150    return MemoryActivatedFont::create(fontID, nsFont, cgFont.get());
    155151}
    156152
    157153} // namespace
    158154
    159 PassRefPtr<MemoryActivatedFont> MemoryActivatedFont::create(uint32_t fontID, NSFont* nsFont, ATSFontContainerRef container)
    160 {
    161   MemoryActivatedFont* font = new MemoryActivatedFont(fontID, nsFont, container);
    162   if (!font->cgFont())  // Object construction failed.
    163   {
    164       delete font;
    165       return 0;
    166   }
    167   return adoptRef(font);
    168 }
    169 
    170 MemoryActivatedFont::MemoryActivatedFont(uint32_t fontID, NSFont* nsFont, ATSFontContainerRef container)
    171     : m_fontContainer(container)
    172     , m_atsFontRef(kATSFontRefUnspecified)
     155PassRefPtr<MemoryActivatedFont> MemoryActivatedFont::create(uint32_t fontID, NSFont* nsFont, CGFontRef cgFont)
     156{
     157  return adoptRef(new MemoryActivatedFont(fontID, nsFont, cgFont));
     158}
     159
     160MemoryActivatedFont::MemoryActivatedFont(uint32_t fontID, NSFont* nsFont, CGFontRef cgFont)
     161    : m_cgFont(cgFont)
    173162    , m_fontID(fontID)
    174163    , m_inSandboxHashKey(hashKeyFromNSFont(nsFont))
    175164{
    176     if (!container)
    177         return;
    178    
    179     // Count the number of fonts in the container.
    180     ItemCount fontCount = 0;
    181     OSStatus err = ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 0, 0, &fontCount);
    182     if (err != noErr || fontCount < 1)
    183         return;
    184 
    185     // For now always assume that we want the first font in the container.
    186     ATSFontFindFromContainer(container, kATSOptionFlagsDefault, 1, &m_atsFontRef, 0);
    187 
    188     if (!m_atsFontRef)
    189         return;
    190 
    191     // Cache CGFont representation of the font.
    192     m_cgFont.adoptCF(CGFontCreateWithPlatformFont(&m_atsFontRef));
    193    
    194     if (!m_cgFont)
    195         return;
    196    
    197165    // Add ourselves to caches.
    198166    fontCacheByFontID().add(fontID, this);
     
    204172MemoryActivatedFont::~MemoryActivatedFont()
    205173{
    206     if (m_cgFont) {
    207         // First remove ourselves from the caches.
    208         ASSERT(fontCacheByFontID().contains(m_fontID));
    209         ASSERT(fontCacheByFontName().contains(m_inSandboxHashKey));
    210        
    211         fontCacheByFontID().remove(m_fontID);
    212         fontCacheByFontName().remove(m_inSandboxHashKey);
    213        
    214         // Make sure the CGFont is destroyed before its font container.
    215         m_cgFont.releaseRef();
    216     }
    217    
    218     if (m_fontContainer != kATSFontContainerRefUnspecified)
    219         ATSFontDeactivate(m_fontContainer, 0, kATSOptionFlagsDefault);
     174    // First remove ourselves from the caches.
     175    ASSERT(fontCacheByFontID().contains(m_fontID));
     176    ASSERT(fontCacheByFontName().contains(m_inSandboxHashKey));
     177
     178    fontCacheByFontID().remove(m_fontID);
     179    fontCacheByFontName().remove(m_inSandboxHashKey);
    220180}
    221181
  • trunk/Source/WebKit/chromium/ChangeLog

    r94935 r94936  
     12011-09-11  Jeremy Moskovich  <jeremy@chromium.org>
     2
     3        [Chromium] Change OOP Font loading code to use CGFont*() APIs.
     4        https://bugs.webkit.org/show_bug.cgi?id=66935
     5
     6        This change is necessary due a bug in ATSFontDeactivate() on 10.7.
     7        See crbug.com/93191 for details.
     8
     9        Reviewed by Eric Seidel.
     10
     11        * public/mac/WebSandboxSupport.h:
     12        * src/PlatformBridge.cpp:
     13        (WebCore::PlatformBridge::loadFont):
     14
    1152011-09-11  Adam Barth  <abarth@webkit.org>
    216
  • trunk/Source/WebKit/chromium/public/mac/WebSandboxSupport.h

    r92269 r94936  
    3232#define WebSandboxSupport_h
    3333
    34 typedef uintptr_t ATSFontContainerRef;
     34typedef struct CGFont* CGFontRef;
    3535
    3636#ifdef __OBJC__
     
    4646public:
    4747    // Given an input font - |srcFont| [which can't be loaded due to sandbox
    48     // restrictions].  Return a font container belonging to an equivalent
    49     // font file that can be used to access the font and a unique identifier
    50     // corresponding to the on-disk font file.
    51     //
    52     // Note that a font container may contain multiple fonts, the caller is
    53     // responsible for retreiving the appropriate font from the container.
     48    // restrictions]. Return a font belonging to an equivalent font file
     49    // that can be used to access the font and a unique identifier corresponding
     50    // to the on-disk font file.
    5451    //
    5552    // If this function succeeds, the caller assumes ownership of the |out|
    56     // parameter and must call ATSFontDeactivate() to unload it when done.
     53    // parameter and must call CGFontRelease() to unload it when done.
    5754    //
    5855    // Returns: true on success, false on error.
    59     virtual bool loadFont(NSFont* srcFont, ATSFontContainerRef*, uint32_t* fontID) = 0;
     56    virtual bool loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID) = 0;
    6057};
    6158
  • trunk/Source/WebKit/chromium/src/PlatformSupport.cpp

    r94859 r94936  
    447447
    448448#if OS(DARWIN)
    449 bool PlatformSupport::loadFont(NSFont* srcFont, ATSFontContainerRef* container, uint32_t* fontID)
     449bool PlatformSupport::loadFont(NSFont* srcFont, CGFontRef* out, uint32_t* fontID)
    450450{
    451451    WebSandboxSupport* ss = webKitPlatformSupport()->sandboxSupport();
    452452    if (ss)
    453         return ss->loadFont(srcFont, container, fontID);
     453        return ss->loadFont(srcFont, out, fontID);
    454454
    455455    // This function should only be called in response to an error loading a
     
    457457    // This by definition shouldn't happen if there is no sandbox support.
    458458    ASSERT_NOT_REACHED();
    459     *container = 0;
     459    *out = 0;
    460460    *fontID = 0;
    461461    return false;
Note: See TracChangeset for help on using the changeset viewer.