diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 5a632215103f..14d22f2c554b 100644 --- a/image/public/imgIContainer.idl +++ b/image/public/imgIContainer.idl @@ -93,7 +93,7 @@ native gfxGraphicsFilter(gfxPattern::GraphicsFilter); * * Internally, imgIContainer also manages animation of images. */ -[scriptable, uuid(2506249c-e0a1-4d8f-846c-2d478247f8d8)] +[scriptable, uuid(8bf87433-be67-413b-9497-00071c5002bd)] interface imgIContainer : nsISupports { /** @@ -283,6 +283,12 @@ interface imgIContainer : nsISupports */ void unlockImage(); + /** + * If this image is unlocked, discard its decoded data. If the image is + * locked or has already been discarded, do nothing. + */ + void requestDiscard(); + /** * Indicates that this imgIContainer has been triggered to update * its internal animation state. Likely this should only be called diff --git a/image/public/imgIRequest.idl b/image/public/imgIRequest.idl index 9d3cfb75b925..080e2f9661ba 100644 --- a/image/public/imgIRequest.idl +++ b/image/public/imgIRequest.idl @@ -52,7 +52,7 @@ interface nsIPrincipal; * @version 0.1 * @see imagelib2 */ -[scriptable, uuid(c3bf4e2a-f64b-4ac1-a84e-18631b1802ab)] +[scriptable, uuid(d35a9adb-8328-4b64-b06f-72a165acd080)] interface imgIRequest : nsIRequest { /** @@ -194,6 +194,12 @@ interface imgIRequest : nsIRequest */ void unlockImage(); + /** + * If this image is unlocked, discard the image's decoded data. If the image + * is locked or is already discarded, do nothing. + */ + void requestDiscard(); + /** * If this request is for an animated image, the method creates a new * request which contains the current frame of the image. diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index c591d117a19e..d7df5408b477 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -2181,8 +2181,7 @@ RasterImage::Discard(bool force) if (observer) observer->OnDiscard(nsnull); - if (force) - DiscardTracker::Remove(&mDiscardTrackerNode); + DiscardTracker::Remove(&mDiscardTrackerNode); // Log PR_LOG(gCompressedImageAccountingLog, PR_LOG_DEBUG, @@ -2695,6 +2694,18 @@ RasterImage::UnlockImage() return NS_OK; } +//****************************************************************************** +/* void requestDiscard() */ +NS_IMETHODIMP +RasterImage::RequestDiscard() +{ + if (CanDiscard()) { + Discard(); + } + + return NS_OK; +} + // Flushes up to aMaxBytes to the decoder. nsresult RasterImage::DecodeSomeData(PRUint32 aMaxBytes) diff --git a/image/src/RasterImage.h b/image/src/RasterImage.h index 95baaa8bef0a..a3f9a5c41b2f 100644 --- a/image/src/RasterImage.h +++ b/image/src/RasterImage.h @@ -198,6 +198,7 @@ public: NS_SCRIPTABLE NS_IMETHOD RequestDecode(void); NS_SCRIPTABLE NS_IMETHOD LockImage(void); NS_SCRIPTABLE NS_IMETHOD UnlockImage(void); + NS_SCRIPTABLE NS_IMETHOD RequestDiscard(void); NS_SCRIPTABLE NS_IMETHOD ResetAnimation(void); NS_IMETHOD_(void) RequestRefresh(const mozilla::TimeStamp& aTime); // END NS_DECL_IMGICONTAINER diff --git a/image/src/VectorImage.cpp b/image/src/VectorImage.cpp index f263f29d5034..530602d1b085 100644 --- a/image/src/VectorImage.cpp +++ b/image/src/VectorImage.cpp @@ -626,6 +626,15 @@ VectorImage::UnlockImage() return NS_OK; } +//****************************************************************************** +/* void requestDiscard() */ +NS_IMETHODIMP +VectorImage::RequestDiscard() +{ + // This method is for image-discarding, which only applies to RasterImages. + return NS_OK; +} + //****************************************************************************** /* void resetAnimation (); */ NS_IMETHODIMP diff --git a/image/src/VectorImage.h b/image/src/VectorImage.h index bd1e9b4ad497..a10a347eacc7 100644 --- a/image/src/VectorImage.h +++ b/image/src/VectorImage.h @@ -81,6 +81,7 @@ public: NS_SCRIPTABLE NS_IMETHOD RequestDecode(void); NS_SCRIPTABLE NS_IMETHOD LockImage(void); NS_SCRIPTABLE NS_IMETHOD UnlockImage(void); + NS_SCRIPTABLE NS_IMETHOD RequestDiscard(void); NS_SCRIPTABLE NS_IMETHOD ResetAnimation(void); NS_IMETHOD_(void) RequestRefresh(const mozilla::TimeStamp& aTime); // END NS_DECL_IMGICONTAINER diff --git a/image/src/imgRequestProxy.cpp b/image/src/imgRequestProxy.cpp index 477ee29343a6..32edcc9360a4 100644 --- a/image/src/imgRequestProxy.cpp +++ b/image/src/imgRequestProxy.cpp @@ -370,6 +370,16 @@ imgRequestProxy::UnlockImage() return NS_OK; } +/* void requestDiscard (); */ +NS_IMETHODIMP +imgRequestProxy::RequestDiscard() +{ + if (mImage) { + return mImage->RequestDiscard(); + } + return NS_OK; +} + NS_IMETHODIMP imgRequestProxy::IncrementAnimationConsumers() {