Fix for bug 659580 (Flush CanvasImageCache on shutdown). r=roc.

--HG--
extra : rebase_source : 9752189ce8c9bd13795979cfa8d50311b5bf5b56
This commit is contained in:
Peter Van der Beken 2011-04-13 17:34:06 -07:00
parent 11fd2bc973
commit a6322dcbd6
3 changed files with 22 additions and 8 deletions

View File

@ -133,6 +133,13 @@ public:
static ImageCache* gImageCache = nsnull;
class CanvasImageCacheShutdownObserver : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
};
void
CanvasImageCache::NotifyDrawImage(nsIDOMElement* aImage,
nsHTMLCanvasElement* aCanvas,
@ -142,6 +149,7 @@ CanvasImageCache::NotifyDrawImage(nsIDOMElement* aImage,
{
if (!gImageCache) {
gImageCache = new ImageCache();
nsContentUtils::RegisterShutdownObserver(new CanvasImageCacheShutdownObserver());
}
ImageCacheEntry* entry = gImageCache->mCache.PutEntry(ImageCacheKey(aImage, aCanvas));
@ -186,11 +194,21 @@ CanvasImageCache::Lookup(nsIDOMElement* aImage,
return entry->mData->mSurface;
}
void
CanvasImageCache::Shutdown()
NS_IMPL_ISUPPORTS1(CanvasImageCacheShutdownObserver, nsIObserver)
NS_IMETHODIMP
CanvasImageCacheShutdownObserver::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
delete gImageCache;
gImageCache = nsnull;
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
delete gImageCache;
gImageCache = nsnull;
nsContentUtils::UnregisterShutdownObserver(this);
}
return NS_OK;
}
}

View File

@ -69,8 +69,6 @@ public:
static gfxASurface* Lookup(nsIDOMElement* aImage,
nsHTMLCanvasElement* aCanvas,
gfxIntSize* aSize);
static void Shutdown();
};
}

View File

@ -121,7 +121,6 @@
#include "nsContentSink.h"
#include "nsFrameMessageManager.h"
#include "nsRefreshDriver.h"
#include "CanvasImageCache.h"
#include "nsHyphenationManager.h"
@ -281,7 +280,6 @@ nsLayoutStatics::Initialize()
void
nsLayoutStatics::Shutdown()
{
CanvasImageCache::Shutdown();
nsFrameScriptExecutor::Shutdown();
nsFocusManager::Shutdown();
#ifdef MOZ_XUL