Allow mmap encoded data replacement for WOFF fonts.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2014 01:59:20 +0000 (01:59 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2014 01:59:20 +0000 (01:59 +0000)
<https://webkit.org/b/127737>

We always have to convert WOFF fonts to SFNT format. This happens
in a separate buffer from the CachedFont's internal resource buffer.
Because of this, there's no need to protect the original buffer from
mmap replacement.

With this change, WOFF web fonts are no longer duplicated between
the network and web processes.

Reviewed by Brady Eidson.

* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::CachedFont):
(WebCore::CachedFont::ensureCustomFontData):
(WebCore::CachedFont::mayTryReplaceEncodedData):
* loader/cache/CachedFont.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162897 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/loader/cache/CachedFont.h

index bedc5b1163b8011fdf75f3e19d8cae677863fd5d..461c3e3397761d7614e8b2f1aed639ad67a463fe 100644 (file)
@@ -1,3 +1,24 @@
+2014-01-27  Andreas Kling  <akling@apple.com>
+
+        Allow mmap encoded data replacement for WOFF fonts.
+        <https://webkit.org/b/127737>
+
+        We always have to convert WOFF fonts to SFNT format. This happens
+        in a separate buffer from the CachedFont's internal resource buffer.
+        Because of this, there's no need to protect the original buffer from
+        mmap replacement.
+
+        With this change, WOFF web fonts are no longer duplicated between
+        the network and web processes.
+
+        Reviewed by Brady Eidson.
+
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::CachedFont):
+        (WebCore::CachedFont::ensureCustomFontData):
+        (WebCore::CachedFont::mayTryReplaceEncodedData):
+        * loader/cache/CachedFont.h:
+
 2014-01-27  David Hyatt  <hyatt@apple.com>
 
         [New Multicolumn] Add support for block progression axis and reverse direction
 2014-01-27  David Hyatt  <hyatt@apple.com>
 
         [New Multicolumn] Add support for block progression axis and reverse direction
index b89d16c863e95b2384e13e544a9516215e91b027..fbf658cc0285da843c40db1b570310f1620d8170 100644 (file)
@@ -53,7 +53,7 @@ namespace WebCore {
 CachedFont::CachedFont(const ResourceRequest& resourceRequest)
     : CachedResource(resourceRequest, FontResource)
     , m_loadInitiated(false)
 CachedFont::CachedFont(const ResourceRequest& resourceRequest)
     : CachedResource(resourceRequest, FontResource)
     , m_loadInitiated(false)
-    , m_hasCreatedFontData(false)
+    , m_hasCreatedFontDataWrappingResource(false)
 {
 }
 
 {
 }
 
@@ -98,7 +98,9 @@ bool CachedFont::ensureCustomFontData()
         ASSERT(buffer);
 
         RefPtr<SharedBuffer> sfntBuffer;
         ASSERT(buffer);
 
         RefPtr<SharedBuffer> sfntBuffer;
-        if (isWOFF(buffer)) {
+
+        bool fontIsWOFF = isWOFF(buffer);
+        if (fontIsWOFF) {
             Vector<char> sfnt;
             if (convertWOFFToSfnt(buffer, sfnt)) {
                 sfntBuffer = SharedBuffer::adoptVector(sfnt);
             Vector<char> sfnt;
             if (convertWOFFToSfnt(buffer, sfnt)) {
                 sfntBuffer = SharedBuffer::adoptVector(sfnt);
@@ -109,7 +111,7 @@ bool CachedFont::ensureCustomFontData()
 
         m_fontData = buffer ? createFontCustomPlatformData(*buffer) : nullptr;
         if (m_fontData)
 
         m_fontData = buffer ? createFontCustomPlatformData(*buffer) : nullptr;
         if (m_fontData)
-            m_hasCreatedFontData = true;
+            m_hasCreatedFontDataWrappingResource = !fontIsWOFF;
         else
             setStatus(DecodeError);
     }
         else
             setStatus(DecodeError);
     }
@@ -192,11 +194,11 @@ void CachedFont::checkNotify()
 
 bool CachedFont::mayTryReplaceEncodedData() const
 {
 
 bool CachedFont::mayTryReplaceEncodedData() const
 {
-    // If the FontCustomPlatformData has ever been constructed then it still might be in use somewhere.
+    // If a FontCustomPlatformData has ever been constructed to wrap the internal resource buffer then it still might be in use somewhere.
     // That platform font object might directly reference the encoded data buffer behind this CachedFont,
     // so replacing it is unsafe.
 
     // That platform font object might directly reference the encoded data buffer behind this CachedFont,
     // so replacing it is unsafe.
 
-    return !m_hasCreatedFontData;
+    return !m_hasCreatedFontDataWrappingResource;
 }
 
 }
 }
 
 }
index efbcdca7c90b9a735c75628259dbfbf7c14fa462..f19582b96eec0f292bee1eb0c88265cb93bdbf48 100644 (file)
@@ -69,7 +69,7 @@ private:
 
     std::unique_ptr<FontCustomPlatformData> m_fontData;
     bool m_loadInitiated;
 
     std::unique_ptr<FontCustomPlatformData> m_fontData;
     bool m_loadInitiated;
-    bool m_hasCreatedFontData;
+    bool m_hasCreatedFontDataWrappingResource;
 
 #if ENABLE(SVG_FONTS)
     RefPtr<SVGDocument> m_externalSVGDocument;
 
 #if ENABLE(SVG_FONTS)
     RefPtr<SVGDocument> m_externalSVGDocument;