Title: [279806] trunk/Source/WebKit
Revision
279806
Author
[email protected]
Date
2021-07-10 09:56:37 -0700 (Sat, 10 Jul 2021)

Log Message

[GPU Process] Canvas drawing never releases any fonts
https://bugs.webkit.org/show_bug.cgi?id=227376
<rdar://problem/79741186>

Reviewed by Said Abou-Hallawa.

We have a frame counter which makes sure that fonts which haven't been used in n frames get released.
However, we currently only update the frame counter when we release fonts.
This means that the frame counter stays 0 forever. And we never release any fonts.

The fix is just to increment the frame counter even if we don't release any fonts.

No new tests because there is no architectural behavior change.

* WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
(WebKit::RemoteResourceCacheProxy::prepareForNextRenderingUpdate):
(WebKit::RemoteResourceCacheProxy::clearFontMap):
(WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate):
(WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):
(WebKit::RemoteResourceCacheProxy::releaseMemory):
* WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (279805 => 279806)


--- trunk/Source/WebKit/ChangeLog	2021-07-10 16:48:42 UTC (rev 279805)
+++ trunk/Source/WebKit/ChangeLog	2021-07-10 16:56:37 UTC (rev 279806)
@@ -1,3 +1,27 @@
+2021-07-10  Myles C. Maxfield  <[email protected]>
+
+        [GPU Process] Canvas drawing never releases any fonts
+        https://bugs.webkit.org/show_bug.cgi?id=227376
+        <rdar://problem/79741186>
+
+        Reviewed by Said Abou-Hallawa.
+
+        We have a frame counter which makes sure that fonts which haven't been used in n frames get released.
+        However, we currently only update the frame counter when we release fonts.
+        This means that the frame counter stays 0 forever. And we never release any fonts.
+
+        The fix is just to increment the frame counter even if we don't release any fonts.
+
+        No new tests because there is no architectural behavior change.
+
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
+        (WebKit::RemoteResourceCacheProxy::prepareForNextRenderingUpdate):
+        (WebKit::RemoteResourceCacheProxy::clearFontMap):
+        (WebKit::RemoteResourceCacheProxy::didFinalizeRenderingUpdate):
+        (WebKit::RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed):
+        (WebKit::RemoteResourceCacheProxy::releaseMemory):
+        * WebProcess/GPU/graphics/RemoteResourceCacheProxy.h:
+
 2021-07-10  Chris Dumez  <[email protected]>
 
         Unreviewed follow-up to r279802 to address review feedback from Sam Weinig.

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


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-07-10 16:48:42 UTC (rev 279805)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp	2021-07-10 16:56:37 UTC (rev 279806)
@@ -125,27 +125,48 @@
     m_remoteRenderingBackendProxy.releaseRemoteResource(renderingResourceIdentifier);
 }
 
-void RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
+void RemoteResourceCacheProxy::prepareForNextRenderingUpdate()
 {
+    ++m_currentRenderingUpdateVersion;
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+}
+
+void RemoteResourceCacheProxy::clearFontMap()
+{
+    for (auto& item : m_fontIdentifierToLastRenderingUpdateVersionMap)
+        m_remoteRenderingBackendProxy.releaseRemoteResource(item.key);
+    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
+    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+}
+
+void RemoteResourceCacheProxy::finalizeRenderingUpdateForFonts()
+{
     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)
+    if (totalFontCount == m_numberOfFontsUsedInCurrentRenderingUpdate)
         return;
 
+    HashSet<WebCore::RenderingResourceIdentifier> toRemove;
     for (auto& item : m_fontIdentifierToLastRenderingUpdateVersionMap) {
-        if (m_currentRenderingUpdateVersion - item.value >= minimumRenderingUpdateCountToKeepFontAlive)
+        if (m_currentRenderingUpdateVersion - item.value >= minimumRenderingUpdateCountToKeepFontAlive) {
+            toRemove.add(item.key);
             m_remoteRenderingBackendProxy.releaseRemoteResource(item.key);
+        }
     }
 
-    ++m_currentRenderingUpdateVersion;
-    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    m_fontIdentifierToLastRenderingUpdateVersionMap.removeIf([&](const auto& bucket) {
+        return toRemove.contains(bucket.key);
+    });
 }
 
+void RemoteResourceCacheProxy::didFinalizeRenderingUpdate()
+{
+    finalizeRenderingUpdateForFonts();
+    prepareForNextRenderingUpdate();
+}
+
 void RemoteResourceCacheProxy::remoteResourceCacheWasDestroyed()
 {
     for (auto& imageBuffer : m_imageBuffers.values()) {
@@ -155,14 +176,12 @@
         imageBuffer->clearBackend();
     }
     m_nativeImages.clear();
-    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
-    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    clearFontMap();
 }
 
 void RemoteResourceCacheProxy::releaseMemory()
 {
-    m_fontIdentifierToLastRenderingUpdateVersionMap.clear();
-    m_numberOfFontsUsedInCurrentRenderingUpdate = 0;
+    clearFontMap();
     m_remoteRenderingBackendProxy.deleteAllFonts();
 }
 

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


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-07-10 16:48:42 UTC (rev 279805)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteResourceCacheProxy.h	2021-07-10 16:56:37 UTC (rev 279806)
@@ -62,6 +62,9 @@
     using NativeImageHashMap = HashMap<WebCore::RenderingResourceIdentifier, WeakPtr<WebCore::NativeImage>>;
     
     void releaseNativeImage(WebCore::RenderingResourceIdentifier) override;
+    void finalizeRenderingUpdateForFonts();
+    void prepareForNextRenderingUpdate();
+    void clearFontMap();
 
     ImageBufferHashMap m_imageBuffers;
     NativeImageHashMap m_nativeImages;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to