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:
parent
4bcef5c505
commit
d4d90c43e9
@ -184,6 +184,15 @@ nsNativeThemeCocoa::DrawCheckbox(CGContextRef cgContext, ThemeButtonKind inKind,
|
|||||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
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.
|
* Draw the given NSCell into the given cgContext.
|
||||||
*
|
*
|
||||||
@ -251,6 +260,10 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
|
|||||||
if (doSaveCTM)
|
if (doSaveCTM)
|
||||||
savedCTM = CGContextGetCTM(cgContext);
|
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) {
|
if (xscale == 1.0f && yscale == 1.0f) {
|
||||||
// Inflate the rect Gecko gave us by the margin for the control.
|
// Inflate the rect Gecko gave us by the margin for the control.
|
||||||
InflateControlRect(&drawRect, controlSize, marginSet);
|
InflateControlRect(&drawRect, controlSize, marginSet);
|
||||||
@ -259,6 +272,8 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
|
|||||||
savedContext = [NSGraphicsContext currentContext];
|
savedContext = [NSGraphicsContext currentContext];
|
||||||
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:cgContext flipped:YES]];
|
[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]];
|
[cell drawWithFrame:drawRect inView:[NSView focusView]];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -286,6 +301,8 @@ nsNativeThemeCocoa::DrawCellWithScaling(NSCell *cell,
|
|||||||
savedContext = [NSGraphicsContext currentContext];
|
savedContext = [NSGraphicsContext currentContext];
|
||||||
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]];
|
[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]];
|
[cell drawWithFrame:tmpRect inView:[NSView focusView]];
|
||||||
|
|
||||||
[NSGraphicsContext setCurrentContext:savedContext];
|
[NSGraphicsContext setCurrentContext:savedContext];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user