зеркало из https://github.com/mozilla/gecko-dev.git
Avoid crashes and performance problems with large cells (relanded). b=444864,444260,449111 r=josh sr=roc
This commit is contained in:
Родитель
e0c45dbe56
Коммит
b83d7c6b4e
|
@ -198,6 +198,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.
|
||||
*
|
||||
|
@ -265,6 +274,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);
|
||||
|
@ -273,6 +286,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 {
|
||||
|
@ -300,6 +315,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];
|
||||
|
|
Загрузка…
Ссылка в новой задаче