Avoid crashes and performance problems with large cells. b=444864 r=josh sr=roc a=dveditz

git-svn-id: svn://10.0.0.236/trunk@254578 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
smichaud%pobox.com 2008-10-09 23:23:04 +00:00
parent 4bcef5c505
commit d4d90c43e9

View File

@ -184,6 +184,15 @@ nsNativeThemeCocoa::DrawCheckbox(CGContextRef cgContext, ThemeButtonKind inKind,
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// Limit on the area of destRect (in pixels^2) in DrawCellWithScaling(),
// above which we don't do any scaling. This is to avoid crashes in
// [NSGraphicsContext graphicsContextWithGraphicsPort:flipped:] and
// CGContextDrawImage(), and also to avoid very poor drawing performance in
// CGContextDrawImage() (particularly if xscale or yscale is less than but
// near 1 -- e.g. 0.9). This value was determined by trial and error, on
// OS X 10.4.11 and 10.5.4, and on systems with different amounts of RAM.
#define CELL_SCALING_MAX_AREA 500000
/*
* Draw the given NSCell into the given cgContext.
*
@ -251,6 +260,10 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
if (doSaveCTM)
savedCTM = CGContextGetCTM(cgContext);
// Fall back to no scaling if the area of our cell (in pixels^2) is too large.
if (drawRect.size.width * drawRect.size.height > CELL_SCALING_MAX_AREA)
xscale = yscale = 1.0f;
if (xscale == 1.0f && yscale == 1.0f) {
// Inflate the rect Gecko gave us by the margin for the control.
InflateControlRect(&drawRect, controlSize, marginSet);
@ -259,6 +272,8 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
savedContext = [NSGraphicsContext currentContext];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
// [NSView focusView] may return nil here, but
// [NSCell drawWithFrame:inView:] can deal with that.
[cell drawWithFrame:drawRect inView:[NSView focusView]];
}
else {
@ -286,6 +301,8 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
savedContext = [NSGraphicsContext currentContext];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]];
// [NSView focusView] may return nil here, but
// [NSCell drawWithFrame:inView:] can deal with that.
[cell drawWithFrame:tmpRect inView:[NSView focusView]];
[NSGraphicsContext setCurrentContext:savedContext];