From d125c715f4d39e75b8c31349cf3ecb2212d950cc Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Sat, 10 Mar 2012 01:29:28 -0500 Subject: [PATCH] Bug 731419 - Part 1: Discard image data immediately on tab close, imagelib changes. r=joe --HG-- extra : rebase_source : 5e08cc235f1a9cb7b63d83df13760f2f2a4de0a4 --- image/public/imgIContainer.idl | 8 +++++++- image/public/imgIRequest.idl | 8 +++++++- image/src/RasterImage.cpp | 12 ++++++++++++ image/src/RasterImage.h | 1 + image/src/VectorImage.cpp | 9 +++++++++ image/src/VectorImage.h | 1 + image/src/imgRequestProxy.cpp | 10 ++++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 5a632215103..14d22f2c554 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 9d3cfb75b92..080e2f9661b 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 6f778745580..e3669f72333 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -2696,6 +2696,18 @@ RasterImage::UnlockImage() return NS_OK; } +//****************************************************************************** +/* void requestDiscard() */ +NS_IMETHODIMP +RasterImage::RequestDiscard() +{ + if (CanDiscard()) { + ForceDiscard(); + } + + 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 16d86344a0e..8b61f170628 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 f263f29d503..530602d1b08 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 bd1e9b4ad49..a10a347eacc 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 477ee29343a..32edcc9360a 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() {