#include "wtf/StdLibExtras.h"
#include "wtf/Vector.h"
-using namespace std;
-
namespace WebCore {
ImageResource::ImageResource(const ResourceRequest& resourceRequest)
Resource::switchClientsToRevalidatedResource();
}
+bool ImageResource::isSafeToUnlock() const
+{
+ return !m_image || (m_image->hasOneRef() && m_image->isBitmapImage());
+}
+
+void ImageResource::destroyDecodedDataIfPossible()
+{
+ if (isSafeToUnlock() && !hasClients() && !isLoading()) {
+ m_image = 0;
+ setDecodedSize(0);
+ } else if (m_image && !errorOccurred()) {
+ m_image->destroyDecodedData(true);
+ }
+}
+
void ImageResource::allClientsRemoved()
{
m_pendingContainerSizeRequests.clear();
void ImageResource::clear()
{
- destroyDecodedData();
+ prune();
clearImage();
m_pendingContainerSizeRequests.clear();
setEncodedSize(0);
Resource::responseReceived(response);
}
-void ImageResource::destroyDecodedData()
-{
- bool canDeleteImage = !m_image || (m_image->hasOneRef() && m_image->isBitmapImage());
- if (isSafeToMakePurgeable() && canDeleteImage && !isLoading()) {
- // Image refs the data buffer so we should not make it purgeable while the image is alive.
- // Invoking addClient() will reconstruct the image object.
- m_image = 0;
- setDecodedSize(0);
- makePurgeable(true);
- } else if (m_image && !errorOccurred()) {
- m_image->destroyDecodedData(true);
- }
-}
-
void ImageResource::decodedSizeChanged(const WebCore::Image* image, int delta)
{
if (!image || image != m_image)