[Mac] BitmapImage::decodedDataIsPurgeable() is telling lies and causing massive memor...
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Feb 2016 18:34:57 +0000 (18:34 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 12 Feb 2016 18:34:57 +0000 (18:34 +0000)
<https://webkit.org/b/154172>

Reviewed by Antti Koivisto.

The underlying mechanism in CoreAnimation that made this work is no longer in place.

Instead of keeping purgeable frames and juggling volatility bits, we were simply caching
every single frame of large GIF animations, sometimes leading to monstrous memory usage.

Remove the code from WebCore since it's not doing at all what it means to.

Now iOS and Mac will behave the same again, and frame caching decisions will be
made by WebKit, based on total pixel byte size.

* loader/cache/CachedImage.h:
* loader/cache/CachedResource.h:
(WebCore::CachedResource::decodedDataIsPurgeable): Deleted.
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::pruneLiveResourcesToSize): Deleted.
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::decodedDataIsPurgeable): Deleted.
(WebCore::BitmapImage::destroyDecodedDataIfNecessary): Deleted.
* platform/graphics/BitmapImage.h:
* platform/graphics/Image.h:
(WebCore::Image::decodedDataIsPurgeable): Deleted.
* platform/graphics/cg/BitmapImageCG.cpp:
(WebCore::BitmapImage::decodedDataIsPurgeable): Deleted.
* platform/graphics/cg/ImageSourceCG.cpp:
(WebCore::ImageSource::createFrameAtIndex): Deleted.

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

Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedImage.h
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/MemoryCache.cpp
Source/WebCore/platform/graphics/BitmapImage.cpp
Source/WebCore/platform/graphics/BitmapImage.h
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp
Source/WebCore/platform/graphics/cg/ImageSourceCG.cpp

index 36e0595..f3f6135 100644 (file)
@@ -1,3 +1,36 @@
+2016-02-12  Andreas Kling  <akling@apple.com>
+
+        [Mac] BitmapImage::decodedDataIsPurgeable() is telling lies and causing massive memory usage.
+        <https://webkit.org/b/154172>
+
+        Reviewed by Antti Koivisto.
+
+        The underlying mechanism in CoreAnimation that made this work is no longer in place.
+
+        Instead of keeping purgeable frames and juggling volatility bits, we were simply caching
+        every single frame of large GIF animations, sometimes leading to monstrous memory usage.
+
+        Remove the code from WebCore since it's not doing at all what it means to.
+
+        Now iOS and Mac will behave the same again, and frame caching decisions will be
+        made by WebKit, based on total pixel byte size.
+
+        * loader/cache/CachedImage.h:
+        * loader/cache/CachedResource.h:
+        (WebCore::CachedResource::decodedDataIsPurgeable): Deleted.
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::pruneLiveResourcesToSize): Deleted.
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::decodedDataIsPurgeable): Deleted.
+        (WebCore::BitmapImage::destroyDecodedDataIfNecessary): Deleted.
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Image.h:
+        (WebCore::Image::decodedDataIsPurgeable): Deleted.
+        * platform/graphics/cg/BitmapImageCG.cpp:
+        (WebCore::BitmapImage::decodedDataIsPurgeable): Deleted.
+        * platform/graphics/cg/ImageSourceCG.cpp:
+        (WebCore::ImageSource::createFrameAtIndex): Deleted.
+
 2016-02-12  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Ref cycle between IDBObjectStore and IDBIndex.
index 47d09f8..5a8e837 100644 (file)
@@ -116,8 +116,6 @@ private:
 
     virtual bool stillNeedsLoad() const override { return !errorOccurred() && status() == Unknown && !isLoading(); }
 
-    virtual bool decodedDataIsPurgeable() const override { return m_image && m_image->decodedDataIsPurgeable(); }
-
     // ImageObserver
     virtual void decodedSizeChanged(const Image*, int delta) override;
     virtual void didDraw(const Image*) override;
index 5466be6..b9bd47a 100644 (file)
@@ -147,8 +147,6 @@ public:
     unsigned encodedSize() const { return m_encodedSize; }
     unsigned decodedSize() const { return m_decodedSize; }
     unsigned overheadSize() const;
-
-    virtual bool decodedDataIsPurgeable() const { return false; }
     
     bool isLoaded() const { return !m_loading; } // FIXME. Method name is inaccurate. Loading might not have started yet.
 
index 8bf34c9..8bc0688 100644 (file)
@@ -314,9 +314,6 @@ void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize, bool shouldDestr
             if (!shouldDestroyDecodedDataForAllLiveResources && elapsedTime < cMinDelayBeforeLiveDecodedPrune)
                 return;
 
-            if (current->decodedDataIsPurgeable())
-                continue;
-
             // Destroy our decoded data. This will remove us from m_liveDecodedResources, and possibly move us
             // to a different LRU list in m_allResources.
             current->destroyDecodedData();
index 3ea1b5f..faf0f86 100644 (file)
@@ -96,13 +96,6 @@ void BitmapImage::startTimer(double delay)
     m_frameTimer->startOneShot(delay);
 }
 
-#if !USE(CG)
-bool BitmapImage::decodedDataIsPurgeable() const
-{
-    return false;
-}
-#endif
-
 bool BitmapImage::haveFrameAtIndex(size_t index)
 {
     if (index >= frameCount())
@@ -150,11 +143,6 @@ void BitmapImage::destroyDecodedDataIfNecessary(bool destroyAll)
     const unsigned largeAnimationCutoff = 5242880;
 #endif
 
-    // If decoded data is purgeable, the operating system will
-    // take care of throwing it away when the system is under pressure.
-    if (decodedDataIsPurgeable())
-        return;
-
     // If we have decoded frames but there is no encoded data, we shouldn't destroy
     // the decoded image since we won't be able to reconstruct it later.
     if (!data() && m_frames.size())
index 9efd221..cf5b4c8 100644 (file)
@@ -288,7 +288,6 @@ protected:
 #endif
 
 private:
-    virtual bool decodedDataIsPurgeable() const override;
     void clearTimer();
     void startTimer(double delay);
 
index 47379b3..41fef2a 100644 (file)
@@ -119,7 +119,6 @@ public:
     virtual String filenameExtension() const { return String(); } // null string if unknown
 
     virtual void destroyDecodedData(bool destroyAll = true) = 0;
-    virtual bool decodedDataIsPurgeable() const { return false; }
 
     SharedBuffer* data() { return m_encodedImageData.get(); }
 
index a53af36..01b7d69 100644 (file)
@@ -265,13 +265,6 @@ PassNativeImagePtr BitmapImage::copyUnscaledFrameAtIndex(size_t index)
     return m_source.createFrameAtIndex(index);
 }
 
-bool BitmapImage::decodedDataIsPurgeable() const
-{
-    return m_frames.size() >= 1
-        && m_frames[0].m_frame
-        && CGImageGetCachingFlags(m_frames[0].m_frame) & kCGImageCachingTransient;
-}
-
 }
 
 #endif // USE(CG)
index 9252d8e..d4a012b 100644 (file)
@@ -368,13 +368,6 @@ CGImageRef ImageSource::createFrameAtIndex(size_t index, SubsamplingLevel subsam
     if (!imageUTI)
         return image.leakRef();
 
-#if PLATFORM(MAC)
-    if (CFEqual(imageUTI, kUTTypeGIF)) {
-        CGImageSetCachingFlags(image.get(), kCGImageCachingTransient);
-        return image.leakRef();
-    }
-#endif
-
     if (!CFEqual(imageUTI, xbmUTI))
         return image.leakRef();