b=374272, browser crashes when viewing page with many animated gifs, r=stuart

This commit is contained in:
vladimir@pobox.com 2007-04-02 12:57:58 -07:00
parent 110d3b36d6
commit 59d304bf29
2 changed files with 38 additions and 2 deletions

View File

@ -98,8 +98,10 @@ nsThebesImage::Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequi
mFormat = format;
#ifdef XP_WIN
mWinSurface = new gfxWindowsSurface(gfxIntSize(mWidth, mHeight), format);
mImageSurface = mWinSurface->GetImageSurface();
if (!ShouldUseImageSurfaces()) {
mWinSurface = new gfxWindowsSurface(gfxIntSize(mWidth, mHeight), format);
mImageSurface = mWinSurface->GetImageSurface();
}
if (!mImageSurface) {
mWinSurface = nsnull;
@ -218,6 +220,11 @@ nsThebesImage::Optimize(nsIDeviceContext* aContext)
// never hit this.
}
// if we're being forced to use image surfaces due to
// resource constraints, don't try to optimize beyond single-pixel.
if (ShouldUseImageSurfaces())
return NS_OK;
#ifdef XP_WIN
// we need to special-case windows here, because windows has
// a distinction between DIB and DDB and we want to use DDBs as much
@ -542,3 +549,26 @@ nsThebesImage::DrawToImage(nsIImage* aDstImage, PRInt32 aDX, PRInt32 aDY, PRInt3
return NS_OK;
}
PRBool
nsThebesImage::ShouldUseImageSurfaces()
{
#ifdef XP_WIN
static const DWORD kGDIObjectsHighWaterMark = 7000;
// at 7000 GDI objects, stop allocating normal images to make sure
// we never hit the 10k hard limit.
// GetCurrentProcess() just returns (HANDLE)-1, it's inlined afaik
DWORD count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
if (count == 0 ||
count > kGDIObjectsHighWaterMark)
{
// either something's broken (count == 0),
// or we hit our high water mark; disable
// image allocations for a bit.
return PR_TRUE;
}
#endif
return PR_FALSE;
}

View File

@ -157,6 +157,12 @@ protected:
#endif
PRUint8 mAlphaDepth;
// this function should return true if
// we should (temporarily) not allocate any
// platform native surfaces and instead use
// image surfaces for everything.
static PRBool ShouldUseImageSurfaces();
};
#endif /* _NSTHEBESIMAGE_H_ */