Title: [186328] releases/WebKitGTK/webkit-2.8/Source/WebCore
Revision
186328
Author
[email protected]
Date
2015-07-06 02:30:14 -0700 (Mon, 06 Jul 2015)

Log Message

Merge r184793 - [CG] Regression(r78652): Partially decoded images are not properly removed from MemoryCache when pruning
https://bugs.webkit.org/show_bug.cgi?id=145310

Reviewed by Antti Koivisto.

r78652 added partially decoded images to the MemoryCache's list of live
decoded resources so that they can be pruned on memory pressure. This
was needed because CG decodes part of the image to determine its
properties (e.g. its size). On memory pressure, we call
BitmapImage::destroyDecodedData() which clears the ImageSource and
frees up this extra decoded data.

However, we would fail to remove such partially decoded images from the
MemoryCache's list of live resources when pruning. This is because
BitmapImage::destroyMetadataAndNotify() fails to take into account the
decoded properties size when no frame has been cleared. We would thus
fail to detect a decoded size change and not call
CachedImage::decodedSizeChanged(). As a result, the CachedImage's
decoded size is not reset to 0 and we don't remove it from live decoded
resources.

This patch updates BitmapImage::destroyMetadataAndNotify() to account
for m_decodedPropertiesSize even if frameBytesCleared is 0. This way,
images for which we have't decoded any frames yet will correctly report
that we cleared the decoded data used to determine the image properties
and their decoded size will be properly reset to 0. As a result, these
will be removed from the MemoryCache's list of live decoded resources.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::destroyDecodedData):
(WebCore::BitmapImage::destroyMetadataAndNotify):
(WebCore::BitmapImage::dataChanged):
* platform/graphics/BitmapImage.h:

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog (186327 => 186328)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-07-06 09:27:31 UTC (rev 186327)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/ChangeLog	2015-07-06 09:30:14 UTC (rev 186328)
@@ -1,3 +1,39 @@
+2015-05-22  Chris Dumez  <[email protected]>
+
+        [CG] Regression(r78652): Partially decoded images are not properly removed from MemoryCache when pruning
+        https://bugs.webkit.org/show_bug.cgi?id=145310
+
+        Reviewed by Antti Koivisto.
+
+        r78652 added partially decoded images to the MemoryCache's list of live
+        decoded resources so that they can be pruned on memory pressure. This
+        was needed because CG decodes part of the image to determine its
+        properties (e.g. its size). On memory pressure, we call
+        BitmapImage::destroyDecodedData() which clears the ImageSource and
+        frees up this extra decoded data.
+
+        However, we would fail to remove such partially decoded images from the
+        MemoryCache's list of live resources when pruning. This is because
+        BitmapImage::destroyMetadataAndNotify() fails to take into account the
+        decoded properties size when no frame has been cleared. We would thus
+        fail to detect a decoded size change and not call
+        CachedImage::decodedSizeChanged(). As a result, the CachedImage's
+        decoded size is not reset to 0 and we don't remove it from live decoded
+        resources.
+
+        This patch updates BitmapImage::destroyMetadataAndNotify() to account
+        for m_decodedPropertiesSize even if frameBytesCleared is 0. This way,
+        images for which we have't decoded any frames yet will correctly report
+        that we cleared the decoded data used to determine the image properties
+        and their decoded size will be properly reset to 0. As a result, these
+        will be removed from the MemoryCache's list of live decoded resources.
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::destroyDecodedData):
+        (WebCore::BitmapImage::destroyMetadataAndNotify):
+        (WebCore::BitmapImage::dataChanged):
+        * platform/graphics/BitmapImage.h:
+
 2015-05-21  Said Abou-Hallawa  <[email protected]>
 
         SVG as image uses very tiny default font-size

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.cpp (186327 => 186328)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.cpp	2015-07-06 09:27:31 UTC (rev 186327)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.cpp	2015-07-06 09:30:14 UTC (rev 186328)
@@ -123,10 +123,8 @@
             frameBytesCleared += frameBytes;
     }
 
-    destroyMetadataAndNotify(frameBytesCleared);
-
     m_source.clear(destroyAll, clearBeforeFrame, data(), m_allDataReceived);
-    return;
+    destroyMetadataAndNotify(frameBytesCleared, ClearedSource::Yes);
 }
 
 void BitmapImage::destroyDecodedDataIfNecessary(bool destroyAll)
@@ -157,7 +155,7 @@
         destroyDecodedData(destroyAll);
 }
 
-void BitmapImage::destroyMetadataAndNotify(unsigned frameBytesCleared)
+void BitmapImage::destroyMetadataAndNotify(unsigned frameBytesCleared, ClearedSource clearedSource)
 {
     m_isSolidColor = false;
     m_checkedForSolidColor = false;
@@ -165,10 +163,13 @@
 
     ASSERT(m_decodedSize >= frameBytesCleared);
     m_decodedSize -= frameBytesCleared;
-    if (frameBytesCleared > 0) {
+
+    // Clearing the ImageSource destroys the extra decoded data used for determining image properties.
+    if (clearedSource == ClearedSource::Yes) {
         frameBytesCleared += m_decodedPropertiesSize;
         m_decodedPropertiesSize = 0;
     }
+
     if (frameBytesCleared && imageObserver())
         imageObserver()->decodedSizeChanged(this, -safeCast<int>(frameBytesCleared));
 }
@@ -301,7 +302,7 @@
         if (m_frames[i].m_haveMetadata && !m_frames[i].m_isComplete)
             frameBytesCleared += (m_frames[i].clear(true) ? frameBytes : 0);
     }
-    destroyMetadataAndNotify(frameBytesCleared);
+    destroyMetadataAndNotify(frameBytesCleared, ClearedSource::No);
 #else
     // FIXME: why is this different for iOS?
     int deltaBytes = 0;
@@ -313,7 +314,7 @@
             m_decodedPropertiesSize = 0;
         }
     }
-    destroyMetadataAndNotify(deltaBytes);
+    destroyMetadataAndNotify(deltaBytes, ClearedSource::No);
 #endif
     
     // Feed all the data we've seen so far to the image decoder.

Modified: releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.h (186327 => 186328)


--- releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.h	2015-07-06 09:27:31 UTC (rev 186327)
+++ releases/WebKitGTK/webkit-2.8/Source/WebCore/platform/graphics/BitmapImage.h	2015-07-06 09:30:14 UTC (rev 186328)
@@ -243,7 +243,8 @@
     // Generally called by destroyDecodedData(), destroys whole-image metadata
     // and notifies observers that the memory footprint has (hopefully)
     // decreased by |frameBytesCleared|.
-    void destroyMetadataAndNotify(unsigned frameBytesCleared);
+    enum class ClearedSource { No, Yes };
+    void destroyMetadataAndNotify(unsigned frameBytesCleared, ClearedSource);
 
     // Whether or not size is available yet.
     bool isSizeAvailable();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to