Title: [270725] trunk/Source
Revision
270725
Author
[email protected]
Date
2020-12-11 18:12:50 -0800 (Fri, 11 Dec 2020)

Log Message

[GPU Process] Cache Font objects
https://bugs.webkit.org/show_bug.cgi?id=219672

Reviewed by Wenson Hsieh.

Source/WebCore:

Partially based on the patch made by Said Abou-Hallawa.

This patch introduces a mechanism to cache Font objects in the GPU process much the same way
NativeImage objects are cached in the GPU process.

* platform/graphics/Font.cpp:
(WebCore::Font::Font): Restore the same rendering resource identifier when Font object
is decoded in the GPU process.
(WebCore::Font::renderingResourceIdentifier const): Added. Lazily creates an identifier.
This never happens in the GPU process as we set it in the constructor above.
* platform/graphics/Font.h:
(WebCore::Font::create): Ditto as Font::Font.
* platform/graphics/displaylists/DisplayList.h:
(WebCore::DisplayList::DisplayList::fonts const): Added.
(WebCore::DisplayList::DisplayList::cacheFont): Added.
* platform/graphics/displaylists/DisplayListDrawGlyphsRecorderCoreText.cpp:
(WebCore::DisplayList::DrawGlyphsRecorder::recordDrawGlyphs): Call the newly introduced
appendDrawGraphsItemWithCachedFont instead of appending DrawGlyphs directly.
(WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
* platform/graphics/displaylists/DisplayListDrawGlyphsRecorderHarfBuzz.cpp: Ditto.
(WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
* platform/graphics/displaylists/DisplayListDrawGlyphsRecorderWin.cpp: Ditto.
(WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
* platform/graphics/displaylists/DisplayListItemBuffer.cpp:
(WebCore::DisplayList::ItemHandle::apply): Replaced call to DrawGlyphs::apply with
ASSERT_NOT_REACHED since Replayer::applyItem should handle it now.
* platform/graphics/displaylists/DisplayListItems.cpp:
(WebCore::DisplayList::DrawGlyphs::DrawGlyphs): The one used in decode function in GPU
process now takes RenderingResourceIdentifier instead of Font and the glyph bounds instead
of computing it again here. The one used in WebContent will continue to take Font
to copmute the bounds but encodes RenderingResourceIdentifier instead.
(WebCore::DisplayList::DrawGlyphs::generateGlyphBuffer const): Takes Font.
(WebCore::DisplayList::DrawGlyphs::apply const): Takes Font.
(WebCore::DisplayList::DrawGlyphs::computeBounds): Takes Font.
* platform/graphics/displaylists/DisplayListItems.h:
(WebCore::DisplayList::DrawGlyphs::fontIdentifier): Added.
(WebCore::DisplayList::DrawGlyphs): No longer retains Font object.
(WebCore::DisplayList::DrawGlyphs::encode const): Encodes the bounding rect.
(WebCore::DisplayList::DrawGlyphs::decode): Ditto for decoding.
* platform/graphics/displaylists/DisplayListRecorder.cpp:
(WebCore::DisplayList::Recorder::appendDrawGraphsItemWithCachedFont): Added.
* platform/graphics/displaylists/DisplayListRecorder.h:
(WebCore::DisplayList::Recorder::Delegate::cacheFont): Added.
* platform/graphics/displaylists/DisplayListReplayer.cpp:
(WebCore::DisplayList::Replayer::Replayer): Now takes FontRenderingResourceMap.
(WebCore::DisplayList::applyFontItem): Added.
(WebCore::DisplayList::Replayer::applyItem): Applies DrawGlyphs with Font in m_fonts.
* platform/graphics/displaylists/DisplayListReplayer.h:

Source/WebKit:

Partially based on the patch made by Said Abou-Hallawa.

This patch introduces a mechanism to cache Font objects in the GPU process much the same way
NativeImage objects are cached in the GPU process, and re-enables Web Fonts.

Fonts are removed from the GPU process when either they hadn't been used for 4 rendering updates
or a memory warning has been issued.

* GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::submit): Added the font cache.
(WebKit::RemoteRenderingBackend::cacheFont): Added.
(WebKit::RemoteRenderingBackend::deleteAllFonts): Added.
* GPUProcess/graphics/RemoteRenderingBackend.h:
* GPUProcess/graphics/RemoteRenderingBackend.messages.in: Added CacheFont and DeleteAllFonts
as new IPC messages.
* GPUProcess/graphics/RemoteResourceCache.cpp:
(WebKit::RemoteResourceCache::cacheFont): Added.
(WebKit::RemoteResourceCache::deleteAllFonts): Added. Used when a memory warning is issued.
* GPUProcess/graphics/RemoteResourceCache.h:
(WebKit::RemoteResourceCache::fonts const): Added.
* Platform/IPC/FontReference.h: Added.
(IPC::FontReference): Added.
* Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared): Added FontReference.
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<Ref<Font>>::encode): Encode the rendering resource identifier of Font.
(IPC::ArgumentCoder<Ref<Font>>::decode): Ditto for decoding.
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
(WebKit::RemoteImageBufferProxy::cacheFont): Added.
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::cacheFont): Added.
(WebKit::RemoteRenderingBackendProxy::deleteAllFonts): Added.
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
* WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
(WebKit::RemoteResourceCacheProxy::cacheFont): Added. It updates the total number of fonts
being used since the last rendering update and records the self assigned identifier for
the next rendering update.
(WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate): Added. Called at the end of
each rendering update. It removes all fonts unused in the lsat 4 rendering updates if at least
1/4 of the fonts in the GPU process were not used in this rendering update.
(WebKit::RemoteResourceCacheProxy::releaseMemory): Added. Removes all the fonts to free up
memory when a memory warning is issued.
* WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
(WebKit::RemoteResourceCacheProxy): Added m_fontLastRenderingUpdateMap which keeps track of
the rendering resource identifiers of the fonts cached in the GPU process.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences): Re-enables the Web Fonts.
(WebKit::WebPage::finalizeRenderingUpdate): Added the call to RemoteRenderingBackendProxy's
didFinalizeRenderingUpdate.
(WebKit::WebPage::releaseMemory): Added. Calls RemoteRenderingBackendProxy's function.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess): Added the call to WebPage::releaseMemory in
the memory pressure handler.
(WebKit::WebProcess::prepareToSuspend): Ditto for the process suspension.

Source/WTF:

Specify the width of enum classes so that they can be forward declared.

* wtf/MemoryPressureHandler.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (270724 => 270725)


--- trunk/Source/WTF/ChangeLog	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WTF/ChangeLog	2020-12-12 02:12:50 UTC (rev 270725)
@@ -1,3 +1,14 @@
+2020-12-11  Ryosuke Niwa  <[email protected]>
+
+        [GPU Process] Cache Font objects
+        https://bugs.webkit.org/show_bug.cgi?id=219672
+
+        Reviewed by Wenson Hsieh.
+
+        Specify the width of enum classes so that they can be forward declared.
+
+        * wtf/MemoryPressureHandler.h:
+
 2020-12-11  Eric Carlson  <[email protected]>
 
         [Cocoa] Add Experimental Vorbis support

Modified: trunk/Source/WTF/wtf/MemoryPressureHandler.h (270724 => 270725)


--- trunk/Source/WTF/wtf/MemoryPressureHandler.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WTF/wtf/MemoryPressureHandler.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -51,8 +51,8 @@
     Inactive,
 };
 
-enum class Critical { No, Yes };
-enum class Synchronous { No, Yes };
+enum class Critical : uint8_t { No, Yes };
+enum class Synchronous : uint8_t { No, Yes };
 
 typedef WTF::Function<void(Critical, Synchronous)> LowMemoryHandler;
 

Modified: trunk/Source/WebCore/ChangeLog (270724 => 270725)


--- trunk/Source/WebCore/ChangeLog	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/ChangeLog	2020-12-12 02:12:50 UTC (rev 270725)
@@ -1,3 +1,59 @@
+2020-12-11  Ryosuke Niwa  <[email protected]>
+
+        [GPU Process] Cache Font objects
+        https://bugs.webkit.org/show_bug.cgi?id=219672
+
+        Reviewed by Wenson Hsieh.
+
+        Partially based on the patch made by Said Abou-Hallawa.
+
+        This patch introduces a mechanism to cache Font objects in the GPU process much the same way
+        NativeImage objects are cached in the GPU process.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::Font): Restore the same rendering resource identifier when Font object
+        is decoded in the GPU process.
+        (WebCore::Font::renderingResourceIdentifier const): Added. Lazily creates an identifier.
+        This never happens in the GPU process as we set it in the constructor above.
+        * platform/graphics/Font.h:
+        (WebCore::Font::create): Ditto as Font::Font.
+        * platform/graphics/displaylists/DisplayList.h:
+        (WebCore::DisplayList::DisplayList::fonts const): Added.
+        (WebCore::DisplayList::DisplayList::cacheFont): Added.
+        * platform/graphics/displaylists/DisplayListDrawGlyphsRecorderCoreText.cpp:
+        (WebCore::DisplayList::DrawGlyphsRecorder::recordDrawGlyphs): Call the newly introduced
+        appendDrawGraphsItemWithCachedFont instead of appending DrawGlyphs directly.
+        (WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
+        * platform/graphics/displaylists/DisplayListDrawGlyphsRecorderHarfBuzz.cpp: Ditto.
+        (WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
+        * platform/graphics/displaylists/DisplayListDrawGlyphsRecorderWin.cpp: Ditto.
+        (WebCore::DisplayList::DrawGlyphsRecorder::drawGlyphs):
+        * platform/graphics/displaylists/DisplayListItemBuffer.cpp:
+        (WebCore::DisplayList::ItemHandle::apply): Replaced call to DrawGlyphs::apply with
+        ASSERT_NOT_REACHED since Replayer::applyItem should handle it now.  
+        * platform/graphics/displaylists/DisplayListItems.cpp:
+        (WebCore::DisplayList::DrawGlyphs::DrawGlyphs): The one used in decode function in GPU
+        process now takes RenderingResourceIdentifier instead of Font and the glyph bounds instead
+        of computing it again here. The one used in WebContent will continue to take Font
+        to copmute the bounds but encodes RenderingResourceIdentifier instead.
+        (WebCore::DisplayList::DrawGlyphs::generateGlyphBuffer const): Takes Font.
+        (WebCore::DisplayList::DrawGlyphs::apply const): Takes Font.
+        (WebCore::DisplayList::DrawGlyphs::computeBounds): Takes Font.
+        * platform/graphics/displaylists/DisplayListItems.h:
+        (WebCore::DisplayList::DrawGlyphs::fontIdentifier): Added.
+        (WebCore::DisplayList::DrawGlyphs): No longer retains Font object.
+        (WebCore::DisplayList::DrawGlyphs::encode const): Encodes the bounding rect.
+        (WebCore::DisplayList::DrawGlyphs::decode): Ditto for decoding.
+        * platform/graphics/displaylists/DisplayListRecorder.cpp:
+        (WebCore::DisplayList::Recorder::appendDrawGraphsItemWithCachedFont): Added.
+        * platform/graphics/displaylists/DisplayListRecorder.h:
+        (WebCore::DisplayList::Recorder::Delegate::cacheFont): Added.
+        * platform/graphics/displaylists/DisplayListReplayer.cpp:
+        (WebCore::DisplayList::Replayer::Replayer): Now takes FontRenderingResourceMap.
+        (WebCore::DisplayList::applyFontItem): Added.
+        (WebCore::DisplayList::Replayer::applyItem): Applies DrawGlyphs with Font in m_fonts.
+        * platform/graphics/displaylists/DisplayListReplayer.h:
+
 2020-12-11  Eric Carlson  <[email protected]>
 
         [Cocoa] Add Experimental Vorbis support

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -66,8 +66,9 @@
     return Font::create(CachedFont::platformDataFromCustomData(*customFontData, description, syntheticBold, syntheticItalic, { }, { }), origin);
 }
 
-Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback)
+Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, Visibility visibility, OrientationFallback orientationFallback, Optional<RenderingResourceIdentifier> renderingResourceIdentifier)
     : m_platformData(platformData)
+    , m_renderingResourceIdentifier(renderingResourceIdentifier)
     , m_origin(origin)
     , m_visibility(visibility)
     , m_treatAsFixedPitch(false)
@@ -158,6 +159,13 @@
     removeFromSystemFallbackCache();
 }
 
+RenderingResourceIdentifier Font::renderingResourceIdentifier() const
+{
+    if (!m_renderingResourceIdentifier)
+        m_renderingResourceIdentifier = RenderingResourceIdentifier::generate();
+    return *m_renderingResourceIdentifier;
+}
+
 static bool fillGlyphPage(GlyphPage& pageToFill, UChar* buffer, unsigned bufferLength, const Font& font)
 {
     bool hasGlyphs = pageToFill.fill(buffer, bufferLength);

Modified: trunk/Source/WebCore/platform/graphics/Font.h (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/Font.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -34,6 +34,7 @@
 #if ENABLE(OPENTYPE_VERTICAL)
 #include "OpenTypeVerticalData.h"
 #endif
+#include "RenderingResourceIdentifier.h"
 #include <wtf/BitVector.h>
 #include <wtf/Hasher.h>
 #include <wtf/Optional.h>
@@ -90,9 +91,10 @@
         Yes,
         No
     };
-    static Ref<Font> create(const FontPlatformData& platformData, Origin origin = Origin::Local, Interstitial interstitial = Interstitial::No, Visibility visibility = Visibility::Visible, OrientationFallback orientationFallback = OrientationFallback::No)
+    static Ref<Font> create(const FontPlatformData& platformData, Origin origin = Origin::Local, Interstitial interstitial = Interstitial::No,
+        Visibility visibility = Visibility::Visible, OrientationFallback orientationFallback = OrientationFallback::No, Optional<RenderingResourceIdentifier> identifier = WTF::nullopt)
     {
-        return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback));
+        return adoptRef(*new Font(platformData, origin, interstitial, visibility, orientationFallback, identifier));
     }
     WEBCORE_EXPORT static Ref<Font> create(Ref<SharedBuffer>&& fontFaceData, Font::Origin, float fontSize, bool syntheticBold, bool syntheticItalic);
 
@@ -106,6 +108,8 @@
     const OpenTypeVerticalData* verticalData() const { return m_verticalData.get(); }
 #endif
 
+    WEBCORE_EXPORT RenderingResourceIdentifier renderingResourceIdentifier() const;
+
     const Font* smallCapsFont(const FontDescription&) const;
     const Font& noSynthesizableFeaturesFont() const;
     const Font* emphasisMarkFont(const FontDescription&) const;
@@ -224,7 +228,7 @@
 #endif
 
 private:
-    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback);
+    WEBCORE_EXPORT Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback, Optional<RenderingResourceIdentifier>);
 
     void platformInit();
     void platformGlyphInit();
@@ -267,6 +271,8 @@
     RefPtr<OpenTypeVerticalData> m_verticalData;
 #endif
 
+    mutable Optional<RenderingResourceIdentifier> m_renderingResourceIdentifier;
+
     struct DerivedFonts {
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
     public:
@@ -377,6 +383,8 @@
     return width;
 }
 
+using FontRenderingResourceMap = HashMap<RenderingResourceIdentifier, Ref<Font>>;
+
 } // namespace WebCore
 
 namespace WTF {

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayList.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -28,6 +28,7 @@
 #include "DisplayListItemBuffer.h"
 #include "DisplayListItemType.h"
 #include "FloatRect.h"
+#include "Font.h"
 #include "GraphicsContext.h"
 #include "ImageBuffer.h"
 #include <wtf/FastMalloc.h>
@@ -74,6 +75,7 @@
 
     const ImageBufferHashMap& imageBuffers() const { return m_imageBuffers; }
     const NativeImageHashMap& nativeImages() const { return m_nativeImages; }
+    const FontRenderingResourceMap& fonts() const { return m_fonts; }
 
     WEBCORE_EXPORT void setItemBufferClient(ItemBufferReadingClient*);
     WEBCORE_EXPORT void setItemBufferClient(ItemBufferWritingClient*);
@@ -177,11 +179,19 @@
             return makeRef(image);
         });
     }
-    
+
+    void cacheFont(Font& font)
+    {
+        m_fonts.ensure(font.renderingResourceIdentifier(), [&]() {
+            return makeRef(font);
+        });
+    }
+
     static bool shouldDumpForFlags(AsTextFlags, ItemHandle);
 
     ImageBufferHashMap m_imageBuffers;
     NativeImageHashMap m_nativeImages;
+    FontRenderingResourceMap m_fonts;
     std::unique_ptr<ItemBuffer> m_items;
     Vector<Optional<FloatRect>> m_drawingItemExtents;
     bool m_tracksDrawingItemExtents { true };

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderCoreText.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderCoreText.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderCoreText.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -334,7 +334,7 @@
     updateStrokeColor(CGGStateGetStrokeColor(gstate));
     updateShadow(CGGStateGetStyle(gstate));
 
-    m_owner.append<DrawGlyphs>(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
+    m_owner.appendDrawGraphsItemWithCachedFont(*m_originalFont, glyphs, computeAdvancesFromPositions(positions, count, currentTextMatrix).data(), count, currentTextMatrix.mapPoint(positions[0]), m_smoothingMode);
 
     m_owner.concatCTM(inverseCTMFixup);
 }
@@ -363,7 +363,7 @@
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
     if (m_drawGlyphsDeconstruction == DrawGlyphsDeconstruction::DontDeconstruct) {
-        m_owner.append<DrawGlyphs>(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, smoothingMode);
+        m_owner.appendDrawGraphsItemWithCachedFont(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, smoothingMode);
         return;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderHarfBuzz.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderHarfBuzz.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderHarfBuzz.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -43,7 +43,7 @@
 
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
-    m_owner.append<DrawGlyphs>(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, smoothingMode);
+    m_owner.appendDrawGraphsItemWithCachedFont(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, smoothingMode);
 }
 
 } // namespace DisplayList

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderWin.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderWin.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListDrawGlyphsRecorderWin.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -43,7 +43,7 @@
 
 void DrawGlyphsRecorder::drawGlyphs(const Font& font, const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, const FloatPoint& startPoint, FontSmoothingMode smoothingMode)
 {
-    m_owner.append<DrawGlyphs>(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, smoothingMode);
+    m_owner.appendDrawGraphsItemWithCachedFont(font, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs, startPoint, m_smoothingMode);
 }
 
 } // namespace DisplayList

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItemBuffer.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItemBuffer.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItemBuffer.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -136,10 +136,9 @@
         get<ClipToDrawingCommands>().apply(context);
         return;
     }
-    case ItemType::DrawGlyphs: {
-        get<DrawGlyphs>().apply(context);
+    case ItemType::DrawGlyphs:
+        ASSERT_NOT_REACHED();
         return;
-    }
     case ItemType::DrawImageBuffer: {
         get<DrawImageBuffer>().apply(context);
         return;

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -357,18 +357,18 @@
     return ts;
 }
 
-DrawGlyphs::DrawGlyphs(const Font& font, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
-    : m_font(makeRefPtr(const_cast<Font&>(font)))
+DrawGlyphs::DrawGlyphs(RenderingResourceIdentifier fontIdentifier, Vector<GlyphBufferGlyph, 128>&& glyphs, Vector<GlyphBufferAdvance, 128>&& advances, const FloatRect& bounds, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
+    : m_fontIdentifier(fontIdentifier)
     , m_glyphs(WTFMove(glyphs))
     , m_advances(WTFMove(advances))
+    , m_bounds(bounds)
     , m_localAnchor(localAnchor)
     , m_smoothingMode(smoothingMode)
 {
-    computeBounds();
 }
 
 DrawGlyphs::DrawGlyphs(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
-    : m_font(makeRefPtr(const_cast<Font&>(font)))
+    : m_fontIdentifier(font.renderingResourceIdentifier())
     , m_localAnchor(localAnchor)
     , m_smoothingMode(smoothingMode)
 {
@@ -378,28 +378,28 @@
         m_glyphs.uncheckedAppend(glyphs[i]);
         m_advances.uncheckedAppend(advances[i]);
     }
-    computeBounds();
+    computeBounds(font);
 }
 
-inline GlyphBuffer DrawGlyphs::generateGlyphBuffer() const
+inline GlyphBuffer DrawGlyphs::generateGlyphBuffer(const Font& font) const
 {
     GlyphBuffer result;
     for (size_t i = 0; i < m_glyphs.size(); ++i)
-        result.add(m_glyphs[i], *m_font, m_advances[i], GlyphBuffer::noOffset);
+        result.add(m_glyphs[i], font, m_advances[i], GlyphBuffer::noOffset);
     return result;
 }
 
-void DrawGlyphs::apply(GraphicsContext& context) const
+void DrawGlyphs::apply(GraphicsContext& context, const Font& font) const
 {
-    context.drawGlyphs(*m_font, generateGlyphBuffer(), 0, m_glyphs.size(), anchorPoint(), m_smoothingMode);
+    context.drawGlyphs(font, generateGlyphBuffer(font), 0, m_glyphs.size(), anchorPoint(), m_smoothingMode);
 }
 
-void DrawGlyphs::computeBounds()
+void DrawGlyphs::computeBounds(const Font& font)
 {
     // FIXME: This code doesn't actually take the extents of the glyphs into consideration. It assumes that
     // the glyph lies entirely within its [(ascent + descent), advance] rect.
-    float ascent = m_font->fontMetrics().floatAscent();
-    float descent = m_font->fontMetrics().floatDescent();
+    float ascent = font.fontMetrics().floatAscent();
+    float descent = font.fontMetrics().floatDescent();
     FloatPoint current = localAnchor();
     size_t numGlyphs = m_glyphs.size();
     for (size_t i = 0; i < numGlyphs; ++i) {

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListItems.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -937,10 +937,9 @@
     static constexpr bool isInlineItem = false;
     static constexpr bool isDrawingItem = true;
 
+    RenderingResourceIdentifier fontIdentifier() { return m_fontIdentifier; }
     const FloatPoint& localAnchor() const { return m_localAnchor; }
-
     FloatPoint anchorPoint() const { return m_localAnchor; }
-
     const Vector<GlyphBufferGlyph, 128>& glyphs() const { return m_glyphs; }
 
     template<class Encoder> void encode(Encoder&) const;
@@ -947,18 +946,19 @@
     template<class Decoder> static Optional<DrawGlyphs> decode(Decoder&);
 
     DrawGlyphs(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
-    WEBCORE_EXPORT DrawGlyphs(const Font&, Vector<GlyphBufferGlyph, 128>&&, Vector<GlyphBufferAdvance, 128>&&, const FloatPoint& localAnchor, FontSmoothingMode);
+    WEBCORE_EXPORT DrawGlyphs(RenderingResourceIdentifier, Vector<GlyphBufferGlyph, 128>&&, Vector<GlyphBufferAdvance, 128>&&, const FloatRect&, const FloatPoint& localAnchor, FontSmoothingMode);
 
-    void apply(GraphicsContext&) const;
+    void apply(GraphicsContext&, const Font&) const;
 
     Optional<FloatRect> globalBounds() const { return WTF::nullopt; }
     Optional<FloatRect> localBounds(const GraphicsContext&) const { return m_bounds; }
 
 private:
-    void computeBounds();
-    GlyphBuffer generateGlyphBuffer() const;
+    void computeBounds(const Font&);
 
-    RefPtr<Font> m_font;
+    GlyphBuffer generateGlyphBuffer(const Font&) const;
+
+    RenderingResourceIdentifier m_fontIdentifier;
     Vector<GlyphBufferGlyph, 128> m_glyphs;
     Vector<GlyphBufferAdvance, 128> m_advances;
     FloatRect m_bounds;
@@ -969,9 +969,10 @@
 template<class Encoder>
 void DrawGlyphs::encode(Encoder& encoder) const
 {
-    encoder << makeRef(*m_font);
+    encoder << m_fontIdentifier;
     encoder << m_glyphs;
     encoder << m_advances;
+    encoder << m_bounds;
     encoder << m_localAnchor;
     encoder << m_smoothingMode;
 }
@@ -979,9 +980,9 @@
 template<class Decoder>
 Optional<DrawGlyphs> DrawGlyphs::decode(Decoder& decoder)
 {
-    Optional<Ref<Font>> font;
-    decoder >> font;
-    if (!font)
+    Optional<RenderingResourceIdentifier> fontIdentifier;
+    decoder >> fontIdentifier;
+    if (!fontIdentifier)
         return WTF::nullopt;
 
     Optional<Vector<GlyphBufferGlyph, 128>> glyphs;
@@ -997,6 +998,11 @@
     if (glyphs->size() != advances->size())
         return WTF::nullopt;
 
+    Optional<FloatRect> bounds;
+    decoder >> bounds;
+    if (!bounds)
+        return WTF::nullopt;
+
     Optional<FloatPoint> localAnchor;
     decoder >> localAnchor;
     if (!localAnchor)
@@ -1007,7 +1013,7 @@
     if (!smoothingMode)
         return WTF::nullopt;
 
-    return {{ font->get(), WTFMove(*glyphs), WTFMove(*advances), *localAnchor, *smoothingMode }};
+    return {{ *fontIdentifier, WTFMove(*glyphs), WTFMove(*advances), *bounds, *localAnchor, *smoothingMode }};
 }
 
 class DrawImageBuffer {

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -172,6 +172,14 @@
     m_drawGlyphsRecorder.drawGlyphs(font, glyphBuffer, from, numGlyphs, startPoint, smoothingMode);
 }
 
+void Recorder::appendDrawGraphsItemWithCachedFont(const Font& font, const GlyphBufferGlyph* glyphs, const GlyphBufferAdvance* advances, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode smoothingMode)
+{
+    if (m_delegate)
+        m_delegate->cacheFont(const_cast<Font&>(font));
+    m_displayList.cacheFont(const_cast<Font&>(font));
+    append<DrawGlyphs>(font, glyphs, advances, count, localAnchor, smoothingMode);
+}
+
 void Recorder::drawImageBuffer(WebCore::ImageBuffer& imageBuffer, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions& options)
 {
     imageBuffer.flushDrawingContext();

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListRecorder.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -68,6 +68,7 @@
         virtual void didAppendItemOfType(ItemType) { }
         virtual void cacheNativeImage(NativeImage&) { }
         virtual bool isCachedImageBuffer(const ImageBuffer&) const { return false; }
+        virtual void cacheFont(Font&) { }
     };
 
     void flushContext(FlushIdentifier identifier) { append<FlushContext>(identifier); }
@@ -106,6 +107,8 @@
 
     void drawGlyphs(const Font&, const GlyphBuffer&, unsigned from, unsigned numGlyphs, const FloatPoint& anchorPoint, FontSmoothingMode) override;
 
+    void appendDrawGraphsItemWithCachedFont(const Font&, const GlyphBufferGlyph*, const GlyphBufferAdvance*, unsigned count, const FloatPoint& localAnchor, FontSmoothingMode);
+
     void drawImageBuffer(WebCore::ImageBuffer&, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions&) override;
     void drawNativeImage(NativeImage&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const ImagePaintingOptions&) override;
     void drawPattern(NativeImage&, const FloatSize& imageSize, const FloatRect& destRect, const FloatRect& srcRect, const AffineTransform&, const FloatPoint& phase, const FloatSize& spacing, const ImagePaintingOptions&) override;

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -34,11 +34,12 @@
 namespace WebCore {
 namespace DisplayList {
 
-Replayer::Replayer(GraphicsContext& context, const DisplayList& displayList, const ImageBufferHashMap* imageBuffers, const NativeImageHashMap* nativeImages, Delegate* delegate)
+Replayer::Replayer(GraphicsContext& context, const DisplayList& displayList, const ImageBufferHashMap* imageBuffers, const NativeImageHashMap* nativeImages, const FontRenderingResourceMap* fonts, Delegate* delegate)
     : m_context(context)
     , m_displayList(displayList)
     , m_imageBuffers(imageBuffers ? *imageBuffers : m_displayList.imageBuffers())
     , m_nativeImages(nativeImages ? *nativeImages : m_displayList.nativeImages())
+    , m_fonts(fonts ? *fonts : m_displayList.fonts())
     , m_delegate(delegate)
 {
 }
@@ -69,6 +70,18 @@
     return resourceIdentifier;
 }
 
+template<class T>
+inline static Optional<RenderingResourceIdentifier> applyFontItem(GraphicsContext& context, const FontRenderingResourceMap& fonts, ItemHandle item)
+{
+    auto& fontItem = item.get<T>();
+    auto resourceIdentifier = fontItem.fontIdentifier();
+    if (auto* font = fonts.get(resourceIdentifier)) {
+        fontItem.apply(context, *font);
+        return WTF::nullopt;
+    }
+    return resourceIdentifier;
+}
+
 std::pair<Optional<StopReplayReason>, Optional<RenderingResourceIdentifier>> Replayer::applyItem(ItemHandle item)
 {
     if (m_delegate && m_delegate->apply(item, m_context))
@@ -92,6 +105,12 @@
         return { WTF::nullopt, WTF::nullopt };
     }
 
+    if (item.is<DrawGlyphs>()) {
+        if (auto missingCachedResourceIdentifier = applyFontItem<DrawGlyphs>(m_context, m_fonts, item))
+            return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };
+        return { WTF::nullopt, WTF::nullopt };
+    }
+
     if (item.is<DrawPattern>()) {
         if (auto missingCachedResourceIdentifier = applyNativeImageItem<DrawPattern>(m_context, m_nativeImages, item))
             return { StopReplayReason::MissingCachedResource, WTFMove(missingCachedResourceIdentifier) };

Modified: trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.h (270724 => 270725)


--- trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebCore/platform/graphics/displaylists/DisplayListReplayer.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -57,7 +57,7 @@
     WTF_MAKE_NONCOPYABLE(Replayer);
 public:
     class Delegate;
-    WEBCORE_EXPORT Replayer(GraphicsContext&, const DisplayList&, const ImageBufferHashMap* = nullptr, const NativeImageHashMap* = nullptr, Delegate* = nullptr);
+    WEBCORE_EXPORT Replayer(GraphicsContext&, const DisplayList&, const ImageBufferHashMap* = nullptr, const NativeImageHashMap* = nullptr, const FontRenderingResourceMap* = nullptr, Delegate* = nullptr);
     WEBCORE_EXPORT ~Replayer();
 
     WEBCORE_EXPORT ReplayResult replay(const FloatRect& initialClip = { }, bool trackReplayList = false);
@@ -75,6 +75,7 @@
     const DisplayList& m_displayList;
     const ImageBufferHashMap& m_imageBuffers;
     const NativeImageHashMap& m_nativeImages;
+    const FontRenderingResourceMap& m_fonts;
     Delegate* m_delegate;
 };
 

Modified: trunk/Source/WebKit/ChangeLog (270724 => 270725)


--- trunk/Source/WebKit/ChangeLog	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/ChangeLog	2020-12-12 02:12:50 UTC (rev 270725)
@@ -1,3 +1,67 @@
+2020-12-11  Ryosuke Niwa  <[email protected]>
+
+        [GPU Process] Cache Font objects
+        https://bugs.webkit.org/show_bug.cgi?id=219672
+
+        Reviewed by Wenson Hsieh.
+
+        Partially based on the patch made by Said Abou-Hallawa.
+
+        This patch introduces a mechanism to cache Font objects in the GPU process much the same way
+        NativeImage objects are cached in the GPU process, and re-enables Web Fonts.
+
+        Fonts are removed from the GPU process when either they hadn't been used for 4 rendering updates
+        or a memory warning has been issued.
+
+        * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+        (WebKit::RemoteRenderingBackend::submit): Added the font cache.
+        (WebKit::RemoteRenderingBackend::cacheFont): Added.
+        (WebKit::RemoteRenderingBackend::deleteAllFonts): Added.
+        * GPUProcess/graphics/RemoteRenderingBackend.h:
+        * GPUProcess/graphics/RemoteRenderingBackend.messages.in: Added CacheFont and DeleteAllFonts
+        as new IPC messages.
+        * GPUProcess/graphics/RemoteResourceCache.cpp:
+        (WebKit::RemoteResourceCache::cacheFont): Added.
+        (WebKit::RemoteResourceCache::deleteAllFonts): Added. Used when a memory warning is issued.
+        * GPUProcess/graphics/RemoteResourceCache.h:
+        (WebKit::RemoteResourceCache::fonts const): Added.
+        * Platform/IPC/FontReference.h: Added.
+        (IPC::FontReference): Added.
+        * Scripts/webkit/messages.py:
+        (types_that_cannot_be_forward_declared): Added FontReference.
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::ArgumentCoder<Ref<Font>>::encode): Encode the rendering resource identifier of Font.
+        (IPC::ArgumentCoder<Ref<Font>>::decode): Ditto for decoding.
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
+        (WebKit::RemoteImageBufferProxy::cacheFont): Added.
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::cacheFont): Added.
+        (WebKit::RemoteRenderingBackendProxy::deleteAllFonts): Added.
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
+        (WebKit::RemoteResourceCacheProxy::cacheFont): Added. It updates the total number of fonts
+        being used since the last rendering update and records the self assigned identifier for
+        the next rendering update. 
+        (WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate): Added. Called at the end of
+        each rendering update. It removes all fonts unused in the lsat 4 rendering updates if at least
+        1/4 of the fonts in the GPU process were not used in this rendering update.
+        (WebKit::RemoteResourceCacheProxy::releaseMemory): Added. Removes all the fonts to free up
+        memory when a memory warning is issued.
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
+        (WebKit::RemoteResourceCacheProxy): Added m_fontLastRenderingUpdateMap which keeps track of
+        the rendering resource identifiers of the fonts cached in the GPU process.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences): Re-enables the Web Fonts.
+        (WebKit::WebPage::finalizeRenderingUpdate): Added the call to RemoteRenderingBackendProxy's
+        didFinalizeRenderingUpdate.
+        (WebKit::WebPage::releaseMemory): Added. Calls RemoteRenderingBackendProxy's function.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess): Added the call to WebPage::releaseMemory in
+        the memory pressure handler.
+        (WebKit::WebProcess::prepareToSuspend): Ditto for the process suspension.
+
 2020-12-11  Jiewen Tan  <[email protected]>
 
         [WebAuthn] Adopt new UI for the Security Key getAssertion flow

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (270724 => 270725)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -148,6 +148,7 @@
         displayList,
         &remoteResourceCache().imageBuffers(),
         &remoteResourceCache().nativeImages(),
+        &remoteResourceCache().fonts(),
         replayerDelegate
     }.replay();
 }
@@ -293,6 +294,19 @@
         wakeUpAndApplyDisplayList(std::exchange(m_pendingWakeupInfo, WTF::nullopt)->arguments);
 }
 
+void RemoteRenderingBackend::cacheFont(Ref<Font>&& font)
+{
+    auto identifier = font->renderingResourceIdentifier();
+    m_remoteResourceCache.cacheFont(WTFMove(font));
+    if (m_pendingWakeupInfo && m_pendingWakeupInfo->shouldPerformWakeup(identifier))
+        wakeUpAndApplyDisplayList(std::exchange(m_pendingWakeupInfo, WTF::nullopt)->arguments);
+}
+
+void RemoteRenderingBackend::deleteAllFonts()
+{
+    m_remoteResourceCache.deleteAllFonts();
+}
+
 void RemoteRenderingBackend::releaseRemoteResource(RenderingResourceIdentifier renderingResourceIdentifier)
 {
     m_remoteResourceCache.releaseRemoteResource(renderingResourceIdentifier);

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h (270724 => 270725)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -110,6 +110,8 @@
     void wakeUpAndApplyDisplayList(const GPUProcessWakeupMessageArguments&);
     void getImageData(WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebCore::RenderingResourceIdentifier, CompletionHandler<void(IPC::ImageDataReference&&)>&&);
     void cacheNativeImage(const ShareableBitmap::Handle&, WebCore::RenderingResourceIdentifier);
+    void cacheFont(Ref<WebCore::Font>&&);
+    void deleteAllFonts();
     void releaseRemoteResource(WebCore::RenderingResourceIdentifier);
     void didCreateSharedDisplayListHandle(WebCore::DisplayList::ItemBufferIdentifier, const SharedMemory::IPCHandle&, WebCore::RenderingResourceIdentifier destinationBufferIdentifier);
 

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in (270724 => 270725)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.messages.in	2020-12-12 02:12:50 UTC (rev 270725)
@@ -27,6 +27,8 @@
     WakeUpAndApplyDisplayList(struct WebKit::GPUProcessWakeupMessageArguments arguments)
     GetImageData(enum:uint8_t WebCore::AlphaPremultiplication outputFormat, WebCore::IntRect srcRect, WebCore::RenderingResourceIdentifier renderingResourceIdentifier) -> (IPC::ImageDataReference imageData) Synchronous
     CacheNativeImage(WebKit::ShareableBitmap::Handle handle, WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
+    CacheFont(IPC::FontReference font)
+    DeleteAllFonts()
     DidCreateSharedDisplayListHandle(WebCore::DisplayList::ItemBufferIdentifier identifier, WebKit::SharedMemory::IPCHandle handle, WebCore::RenderingResourceIdentifier destinationBufferIdentifier)
     ReleaseRemoteResource(WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
 }

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp (270724 => 270725)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -48,6 +48,17 @@
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
 }
 
+void RemoteResourceCache::cacheFont(Ref<Font>&& font)
+{
+    auto addResult = m_fonts.add(font->renderingResourceIdentifier(), WTFMove(font));
+    ASSERT_UNUSED(addResult, addResult.isNewEntry);
+}
+
+void RemoteResourceCache::deleteAllFonts()
+{
+    m_fonts.clear();
+}
+
 void RemoteResourceCache::releaseRemoteResource(RenderingResourceIdentifier renderingResourceIdentifier)
 {
     if (m_imageBuffers.remove(renderingResourceIdentifier))
@@ -54,6 +65,8 @@
         return;
     if (m_nativeImages.remove(renderingResourceIdentifier))
         return;
+    if (m_fonts.remove(renderingResourceIdentifier))
+        return;
     // Caching the remote resource should have happened before releasing it.
     ASSERT_NOT_REACHED();
 }

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h (270724 => 270725)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -27,6 +27,7 @@
 
 #if ENABLE(GPU_PROCESS)
 
+#include <WebCore/Font.h>
 #include <WebCore/ImageBuffer.h>
 #include <WebCore/NativeImage.h>
 #include <WebCore/RenderingResourceIdentifier.h>
@@ -43,14 +44,18 @@
     void cacheImageBuffer(Ref<WebCore::ImageBuffer>&&);
     WebCore::ImageBuffer* cachedImageBuffer(WebCore::RenderingResourceIdentifier);
     void cacheNativeImage(Ref<WebCore::NativeImage>&&);
+    void cacheFont(Ref<WebCore::Font>&&);
+    void deleteAllFonts();
     void releaseRemoteResource(WebCore::RenderingResourceIdentifier);
-    
+
     const WebCore::ImageBufferHashMap& imageBuffers() const { return m_imageBuffers; }
     const WebCore::NativeImageHashMap& nativeImages() const { return m_nativeImages; }
+    const WebCore::FontRenderingResourceMap& fonts() const { return m_fonts; }
 
 private:
     WebCore::ImageBufferHashMap m_imageBuffers;
     WebCore::NativeImageHashMap m_nativeImages;
+    WebCore::FontRenderingResourceMap m_fonts;
 };
 
 } // namespace WebKit

Copied: trunk/Source/WebKit/Platform/IPC/FontReference.h (from rev 270724, trunk/Source/WebKit/GPUProcess/graphics/RemoteResourceCache.cpp) (0 => 270725)


--- trunk/Source/WebKit/Platform/IPC/FontReference.h	                        (rev 0)
+++ trunk/Source/WebKit/Platform/IPC/FontReference.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Ref.h>
+
+namespace WebCore {
+
+class Font;
+
+} // namespace WebCore
+
+namespace IPC {
+
+using FontReference = Ref<WebCore::Font>;
+
+} // namespace IPC

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (270724 => 270725)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2020-12-12 02:12:50 UTC (rev 270725)
@@ -204,6 +204,7 @@
 def types_that_cannot_be_forward_declared():
     return frozenset([
         'IPC::DataReference',
+        'IPC::FontReference',
         'MachSendRight',
         'MediaTime',
         'String',

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (270724 => 270725)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -1105,6 +1105,7 @@
     encoder << (font->isInterstitial() ? Font::Interstitial::Yes : Font::Interstitial::No);
     encoder << font->visibility();
     encoder << (font->isTextOrientationFallback() ? Font::OrientationFallback::Yes : Font::OrientationFallback::No);
+    encoder << font->renderingResourceIdentifier();
     // Intentionally don't encode m_isBrokenIdeographFallback because it doesn't affect drawGlyphs().
 
     encodePlatformData(encoder, font);
@@ -1132,11 +1133,16 @@
     if (!isTextOrientationFallback.hasValue())
         return WTF::nullopt;
 
+    Optional<RenderingResourceIdentifier> renderingRersouceIdentifier;
+    decoder >> renderingRersouceIdentifier;
+    if (!renderingRersouceIdentifier.hasValue())
+        return WTF::nullopt;
+
     auto platformData = decodePlatformData(decoder);
     if (!platformData.hasValue())
         return WTF::nullopt;
 
-    return Font::create(platformData.value(), origin.value(), isInterstitial.value(), visibility.value(), isTextOrientationFallback.value());
+    return Font::create(platformData.value(), origin.value(), isInterstitial.value(), visibility.value(), isTextOrientationFallback.value(), renderingRersouceIdentifier);
 }
 
 void ArgumentCoder<Cursor>::encode(Encoder& encoder, const Cursor& cursor)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (270724 => 270725)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2020-12-12 02:12:50 UTC (rev 270725)
@@ -1532,6 +1532,7 @@
 		9B5499B22362A7EC00DF8BA5 /* _WKTextManipulationExclusionRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B5499B02362A7EC00DF8BA5 /* _WKTextManipulationExclusionRule.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		9B5BEC262400F4A90070C6EF /* WebMediaStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B5BEC242400F4A90070C6EF /* WebMediaStrategy.h */; };
 		9B5BEC2A240101580070C6EF /* RemoteAudioDestinationProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 9B5BEC28240101580070C6EF /* RemoteAudioDestinationProxy.h */; };
+		9BD8AB4A25820E53005386F8 /* FontReference.h in Headers */ = {isa = PBXBuildFile; fileRef = 9BD8AB4925820E52005386F8 /* FontReference.h */; };
 		9BF5EC642541145600984E77 /* JSIPCBinding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9BF5EC6325410E9900984E77 /* JSIPCBinding.cpp */; };
 		9EC532A32447FBAD00215216 /* GeolocationIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 9EC532A22447FBAD00215216 /* GeolocationIdentifier.h */; };
 		9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 9FB5F393169E6A80002C25BF /* WKContextPrivateMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -4876,6 +4877,7 @@
 		9B5BEC2E2401018C0070C6EF /* RemoteAudioDestinationProxy.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = RemoteAudioDestinationProxy.messages.in; sourceTree = "<group>"; };
 		9BC59D6C1EFCCCB6001E8D09 /* CallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackID.h; sourceTree = "<group>"; };
 		9BC59D6D1EFCDC6D001E8D09 /* OptionalCallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionalCallbackID.h; sourceTree = "<group>"; };
+		9BD8AB4925820E52005386F8 /* FontReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontReference.h; sourceTree = "<group>"; };
 		9BF5EC6325410E9900984E77 /* JSIPCBinding.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIPCBinding.cpp; sourceTree = "<group>"; };
 		9EC532A22447FBAD00215216 /* GeolocationIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeolocationIdentifier.h; sourceTree = "<group>"; };
 		9F54F88E16488E87007DF81A /* AuxiliaryProcessMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AuxiliaryProcessMac.mm; sourceTree = "<group>"; };
@@ -6864,6 +6866,7 @@
 				BC032D9E10F437D10058C15A /* Decoder.h */,
 				BC032D9F10F437D10058C15A /* Encoder.cpp */,
 				BC032DA010F437D10058C15A /* Encoder.h */,
+				9BD8AB4925820E52005386F8 /* FontReference.h */,
 				4151E5C31FBB90A900E47E2D /* FormDataReference.h */,
 				C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */,
 				1C9AF36124134D2300D3EC02 /* ImageDataReference.h */,
@@ -11534,6 +11537,7 @@
 				1A90C1F41264FD71003E44D4 /* FindController.h in Headers */,
 				C59C4A5918B81174007BDCB6 /* FocusedElementInformation.h in Headers */,
 				BCE81D8D1319F7EF00241910 /* FontInfo.h in Headers */,
+				9BD8AB4A25820E53005386F8 /* FontReference.h in Headers */,
 				1A14F8E21D74C834006CBEC6 /* FrameInfoData.h in Headers */,
 				1AE00D611831792100087DD7 /* FrameLoadState.h in Headers */,
 				5C121E842410208D00486F9B /* FrameTreeNodeData.h in Headers */,

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteImageBufferProxy.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -229,6 +229,12 @@
             flushDrawingContext();
     }
 
+    void cacheFont(WebCore::Font& font) override
+    {
+        if (m_remoteRenderingBackendProxy)
+            m_remoteRenderingBackendProxy->remoteResourceCacheProxy().cacheFont(font);
+    }
+
     WebCore::DisplayList::ItemBufferHandle createItemBuffer(size_t capacity) override
     {
         if (LIKELY(m_remoteRenderingBackendProxy))

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -154,6 +154,16 @@
     send(Messages::RemoteRenderingBackend::CacheNativeImage(handle, renderingResourceIdentifier), m_renderingBackendIdentifier);
 }
 
+void RemoteRenderingBackendProxy::cacheFont(Ref<WebCore::Font>&& font)
+{
+    send(Messages::RemoteRenderingBackend::CacheFont(WTFMove(font)), m_renderingBackendIdentifier);
+}
+
+void RemoteRenderingBackendProxy::deleteAllFonts()
+{
+    send(Messages::RemoteRenderingBackend::DeleteAllFonts(), m_renderingBackendIdentifier);
+}
+
 void RemoteRenderingBackendProxy::releaseRemoteResource(RenderingResourceIdentifier renderingResourceIdentifier)
 {
     if (renderingResourceIdentifier == m_currentDestinationImageBufferIdentifier)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -83,6 +83,8 @@
     RefPtr<WebCore::ImageData> getImageData(WebCore::AlphaPremultiplication outputFormat, const WebCore::IntRect& srcRect, WebCore::RenderingResourceIdentifier);
     WebCore::DisplayList::FlushIdentifier flushDisplayListAndCommit(const WebCore::DisplayList::DisplayList&, WebCore::RenderingResourceIdentifier);
     void cacheNativeImage(const ShareableBitmap::Handle&, WebCore::RenderingResourceIdentifier);
+    void cacheFont(Ref<WebCore::Font>&&);
+    void deleteAllFonts();
     void releaseRemoteResource(WebCore::RenderingResourceIdentifier);
 
     bool waitForDidCreateImageBufferBackend();

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -101,6 +101,20 @@
     m_remoteRenderingBackendProxy.cacheNativeImage(handle, image.renderingResourceIdentifier());
 }
 
+void RemoteResourceCacheProxy::cacheFont(Font& font)
+{
+    auto result = m_fontIdentifierToLastRenderingUpdateVersionMap.ensure(font.renderingResourceIdentifier(), [&] {
+        return 0;
+    });
+    auto& lastVersion = result.iterator->value;
+    if (lastVersion != m_currentRenderingUpdateVersion) {
+        lastVersion = m_currentRenderingUpdateVersion;
+        ++m_numberOfFontsUsedInCurrentRenderingUpdate;
+    }
+    if (result.isNewEntry)
+        m_remoteRenderingBackendProxy.cacheFont(makeRef(font));
+}
+
 void RemoteResourceCacheProxy::releaseNativeImage(RenderingResourceIdentifier renderingResourceIdentifier)
 {
     if (!m_nativeImages.remove(renderingResourceIdentifier))
@@ -110,6 +124,34 @@
     m_remoteRenderingBackendProxy.releaseRemoteResource(renderingResourceIdentifier);
 }
 
+void RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
+{
+    static constexpr unsigned minimumRenderingUpdateCountToKeepFontAlive = 4;
+    static constexpr double minimumFractionOfUnusedFontCountToTriggerRemoval = 0.25;
+    static constexpr unsigned maximumUnusedFontCountToSkipRemoval = 0;
+
+    unsigned totalFontCount = m_fontIdentifierToLastRenderingUpdateVersionMap.size();
+    RELEASE_ASSERT(m_numberOfFontsUsedInCurrentRenderingUpdate <= totalFontCount);
+    unsigned unusedFontCount = totalFontCount - m_numberOfFontsUsedInCurrentRenderingUpdate;
+    if (unusedFontCount < minimumFractionOfUnusedFontCountToTriggerRemoval * totalFontCount && unusedFontCount <= maximumUnusedFontCountToSkipRemoval)
+        return;
+
+    for (auto& item : m_fontIdentifierToLastRenderingUpdateVersionMap) {
+        if (m_currentRenderingUpdateVersion - item.value >= minimumRenderingUpdateCountToKeepFontAlive)
+            m_remoteRenderingBackendProxy.releaseRemoteResource(item.key);
+    }
+
+    ++m_currentRenderingUpdateVersion;
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+}
+
+void RemoteResourceCacheProxy::releaseMemory()
+{
+    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    m_remoteRenderingBackendProxy.deleteAllFonts();
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(GPU_PROCESS)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -32,6 +32,7 @@
 #include <wtf/HashMap.h>
 
 namespace WebCore {
+class Font;
 class ImageBuffer;
 }
 
@@ -53,6 +54,10 @@
     using ImageBufferHashMap = HashMap<WebCore::RenderingResourceIdentifier, WeakPtr<WebCore::ImageBuffer>>;
     const ImageBufferHashMap& imageBuffers() const { return m_imageBuffers; }
 
+    void cacheFont(WebCore::Font&);
+    void didFinalizeRenderingUpdate();
+    void releaseMemory();
+
 private:
     using NativeImageHashMap = HashMap<WebCore::RenderingResourceIdentifier, WeakPtr<WebCore::NativeImage>>;
     
@@ -60,6 +65,11 @@
 
     ImageBufferHashMap m_imageBuffers;
     NativeImageHashMap m_nativeImages;
+
+    HashMap<WebCore::RenderingResourceIdentifier, uint64_t> m_fontIdentifierToLastRenderingUpdateVersionMap;
+    unsigned m_numberOfFontsUsedInCurrentRenderingUpdate { 0 };
+    uint64_t m_currentRenderingUpdateVersion { 1 };
+
     RemoteRenderingBackendProxy& m_remoteRenderingBackendProxy;
 };
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -3825,9 +3825,6 @@
     WebProcess::singleton().setUseGPUProcessForCanvasRendering(m_shouldRenderCanvasInGPUProcess);
     WebProcess::singleton().setUseGPUProcessForDOMRendering(m_shouldRenderDOMInGPUProcess && DrawingArea::supportsGPUProcessRendering(m_drawingAreaType));
     WebProcess::singleton().setUseGPUProcessForMedia(m_shouldPlayMediaInGPUProcess);
-    // FIXME: We should support web fonts in the GPU process.
-    if (m_shouldRenderDOMInGPUProcess)
-        settings.setDownloadableBinaryFontsEnabled(false);
 #if ENABLE(WEBGL)
     WebProcess::singleton().setUseGPUProcessForWebGL(m_shouldRenderWebGLInGPUProcess);
 #endif
@@ -3950,8 +3947,20 @@
 void WebPage::finalizeRenderingUpdate(OptionSet<FinalizeRenderingUpdateFlags> flags)
 {
     m_page->finalizeRenderingUpdate(flags);
+#if ENABLE(GPU_PROCESS)
+    if (m_remoteRenderingBackendProxy)
+        m_remoteRenderingBackendProxy->remoteResourceCacheProxy().didFinalizeRenderingUpdate();
+#endif
 }
 
+void WebPage::releaseMemory(Critical)
+{
+#if ENABLE(GPU_PROCESS)
+    if (m_remoteRenderingBackendProxy)
+        m_remoteRenderingBackendProxy->remoteResourceCacheProxy().releaseMemory();
+#endif
+}
+
 WebInspector* WebPage::inspector(LazyCreationPolicy behavior)
 {
     if (m_isClosed)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2020-12-12 02:12:50 UTC (rev 270725)
@@ -156,6 +156,10 @@
 
 #define ENABLE_VIEWPORT_RESIZING PLATFORM(IOS_FAMILY)
 
+namespace WTF {
+enum class Critical : uint8_t;
+}
+
 namespace API {
 class Array;
 }
@@ -370,6 +374,8 @@
     void updateRendering();
     void finalizeRenderingUpdate(OptionSet<WebCore::FinalizeRenderingUpdateFlags>);
 
+    void releaseMemory(WTF::Critical);
+
     enum class LazyCreationPolicy { UseExistingOnly, CreateIfNeeded };
 
     WebInspector* inspector(LazyCreationPolicy = LazyCreationPolicy::CreateIfNeeded);

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (270724 => 270725)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-12-12 02:03:32 UTC (rev 270724)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-12-12 02:12:50 UTC (rev 270725)
@@ -377,6 +377,8 @@
             auto maintainBackForwardCache = m_isSuspending ? WebCore::MaintainBackForwardCache::Yes : WebCore::MaintainBackForwardCache::No;
             auto maintainMemoryCache = m_isSuspending && m_hasSuspendedPageProxy ? WebCore::MaintainMemoryCache::Yes : WebCore::MaintainMemoryCache::No;
             WebCore::releaseMemory(critical, synchronous, maintainBackForwardCache, maintainMemoryCache);
+            for (auto& page : m_pageMap.values())
+                page->releaseMemory(critical);
         });
 #if ENABLE(PERIODIC_MEMORY_MONITOR)
         memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
@@ -1384,8 +1386,11 @@
         platformMediaSessionManager->processWillSuspend();
 #endif
 
-    if (!m_suppressMemoryPressureHandler)
+    if (!m_suppressMemoryPressureHandler) {
         MemoryPressureHandler::singleton().releaseMemory(Critical::Yes, Synchronous::Yes);
+        for (auto& page : m_pageMap.values())
+            page->releaseMemory(Critical::Yes);
+    }
 
     freezeAllLayerTrees();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to