Commit 9d18ebb6 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Delete an (expensive) unused code path to draw window backgrounds.

Any view that implements drawRect: and/or sets needsDisplay on itself
gets a view-sized backing store. This was costing ~100MB per large
window on my MBP, and nothing was using it: 10.9 is no longer supported
and menu backgrounds are no longer blurred (and if they were, it'd be a
different way).

Bug: 832197
Change-Id: I2aeaa53a19c12f23a2e05d33883eabf76e318f1c
Reviewed-on: https://chromium-review.googlesource.com/1011022Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550429}
parent 9ef2aa86
......@@ -44,13 +44,6 @@ class View;
// The last tooltip text, used to limit updates.
base::string16 lastTooltipText_;
// Whether to draw an almost-transparent background with rounded corners so
// that OSX correctly blurs the background showing through.
BOOL drawMenuBackgroundForBlur_;
// The cached window mask. Only used for non-rectangular windows on 10.9.
base::scoped_nsobject<NSBezierPath> windowMask_;
}
@property(readonly, nonatomic) views::View* hostedView;
......@@ -72,9 +65,6 @@ class View;
// contentRect (also this NSView's frame), as given by a ui::LocatedEvent.
- (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent;
// Update windowMask_ depending on the current view bounds.
- (void)updateWindowMask;
// Notifies the associated FocusManager whether full keyboard access is enabled
// or not.
- (void)updateFullKeyboardAccess;
......
......@@ -48,17 +48,6 @@ namespace {
NSString* const kFullKeyboardAccessChangedNotification =
@"com.apple.KeyboardUIModeDidChange";
// Returns true if all four corners of |rect| are contained inside |path|.
bool IsRectInsidePath(NSRect rect, NSBezierPath* path) {
return [path containsPoint:rect.origin] &&
[path containsPoint:NSMakePoint(rect.origin.x + rect.size.width,
rect.origin.y)] &&
[path containsPoint:NSMakePoint(rect.origin.x,
rect.origin.y + rect.size.height)] &&
[path containsPoint:NSMakePoint(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height)];
}
// Convert a |point| in |source_window|'s AppKit coordinate system (origin at
// the bottom left of the window) to |target_window|'s content rect, with the
// origin at the top left of the content area.
......@@ -369,30 +358,6 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
}
}
- (void)updateWindowMask {
DCHECK(![self inLiveResize]);
DCHECK(base::mac::IsOS10_9());
DCHECK(hostedView_);
views::Widget* widget = hostedView_->GetWidget();
if (!widget->non_client_view())
return;
const NSRect frameRect = [self bounds];
gfx::Path mask;
widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask);
if (mask.isEmpty())
return;
windowMask_.reset([gfx::CreateNSBezierPathFromSkPath(mask) retain]);
// Convert to AppKit coordinate system.
NSAffineTransform* flipTransform = [NSAffineTransform transform];
[flipTransform translateXBy:0.0 yBy:frameRect.size.height];
[flipTransform scaleXBy:1.0 yBy:-1.0];
[windowMask_ transformUsingAffineTransform:flipTransform];
}
- (void)updateFullKeyboardAccess {
if (!hostedView_)
return;
......@@ -675,67 +640,6 @@ ui::TextEditCommand GetTextEditCommandForMenuAction(SEL action) {
hostedView_->SetSize(gfx::Size(newSize.width, newSize.height));
}
- (void)viewDidEndLiveResize {
[super viewDidEndLiveResize];
// We prevent updating the window mask and clipping the border around the
// view, during a live resize. Hence update the window mask and redraw the
// view after resize has completed.
if (base::mac::IsOS10_9()) {
[self updateWindowMask];
[self setNeedsDisplay:YES];
}
}
- (void)drawRect:(NSRect)dirtyRect {
// Note that BridgedNativeWidget uses -[NSWindow setAutodisplay:NO] to
// suppress calls to this when the window is known to be hidden.
if (!hostedView_)
return;
if (drawMenuBackgroundForBlur_) {
const CGFloat radius = views::MenuConfig::instance().corner_radius;
[skia::SkColorToSRGBNSColor(0x01000000) set];
[[NSBezierPath bezierPathWithRoundedRect:[self bounds]
xRadius:radius
yRadius:radius] fill];
}
// On OS versions earlier than Yosemite, to generate a drop shadow, we set an
// opaque background. This causes windows with non rectangular shapes to have
// square corners. To get around this, fill the path outside the window
// boundary with clearColor and tell Cococa to regenerate drop shadow. See
// crbug.com/543671.
if (windowMask_ && ![self inLiveResize] &&
!IsRectInsidePath(dirtyRect, windowMask_)) {
DCHECK(base::mac::IsOS10_9());
gfx::ScopedNSGraphicsContextSaveGState state;
// The outer rectangular path corresponding to the window.
NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:[self bounds]];
[outerPath appendBezierPath:windowMask_];
[outerPath setWindingRule:NSEvenOddWindingRule];
[[NSGraphicsContext currentContext]
setCompositingOperation:NSCompositeCopy];
[[NSColor clearColor] set];
// Fill the region between windowMask_ and its outer rectangular path
// with clear color. This causes the window to have the shape described
// by windowMask_.
[outerPath fill];
// Regerate drop shadow around the window boundary.
[[self window] invalidateShadow];
}
// If there's a layer, painting occurs in BridgedNativeWidget::OnPaintLayer().
if (hostedView_->GetWidget()->GetLayer())
return;
// TODO(tapted): Add a NOTREACHED() here. At the moment, low-level
// BridgedNativeWidget unit tests may not have a ui::Layer.
}
- (BOOL)isOpaque {
if (!hostedView_)
return NO;
......
......@@ -723,14 +723,6 @@ void BridgedNativeWidget::OnSizeChanged() {
if ([window_ inLiveResize])
MaybeWaitForFrame(new_size);
}
// 10.9 is unable to generate a window shadow from the composited CALayer, so
// use Quartz.
// We don't update the window mask during a live resize, instead it is done
// after the resize is completed in viewDidEndLiveResize: in
// BridgedContentView.
if (base::mac::IsOS10_9() && ![window_ inLiveResize])
[bridged_view_ updateWindowMask];
}
void BridgedNativeWidget::OnPositionChanged() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment