summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-10 01:27:12 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-10 01:27:12 +0000
commit1bab1a4fd39ce327c402fe6e952f8ad1d4e31c30 (patch)
tree27eb1755beeaef6140cda3723ec8908cde083ced /chrome/browser/renderer_host
parenta2fc47729a697e5a87f5f503388b08e981132a70 (diff)
downloadchromium_src-1bab1a4fd39ce327c402fe6e952f8ad1d4e31c30.zip
chromium_src-1bab1a4fd39ce327c402fe6e952f8ad1d4e31c30.tar.gz
chromium_src-1bab1a4fd39ce327c402fe6e952f8ad1d4e31c30.tar.bz2
[Mac] Do not schedule more than one delayed call to setNeedsDisplayInRect. Turns out queuing up a million of these is a bad bad thing.
BUG=40970 TEST=See test in bug. Review URL: http://codereview.chromium.org/1568027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.h10
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm26
2 files changed, 30 insertions, 6 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h
index 5ebedbb..157fa96 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h
@@ -174,6 +174,16 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
// paint requests by expanding the invalid rect rather than actually painting.
bool about_to_validate_and_paint_;
+ // This is true when we have already scheduled a call to
+ // |-callSetNeedsDisplayInRect:| but it has not been fulfilled yet. Used to
+ // prevent us from scheduling multiple calls.
+ bool call_set_needs_display_in_rect_pending_;
+
+ // The invalid rect that needs to be painted by callSetNeedsDisplayInRect.
+ // This value is only meaningful when
+ // |call_set_needs_display_in_rect_pending_| is true.
+ NSRect invalid_rect_;
+
// The time at which this view started displaying white pixels as a result of
// not having anything to paint (empty backing store from renderer). This
// value returns true for is_null() if we are not recording whiteout times.
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index 7c3f5d1..95b7ed9 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -48,7 +48,6 @@ static inline int ToWebKitModifiers(NSUInteger flags) {
- (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r;
- (void)keyEvent:(NSEvent *)theEvent wasKeyEquivalent:(BOOL)equiv;
- (void)cancelChildPopups;
-- (void)callSetNeedsDisplayInRect:(NSValue*)rect;
- (void)attachPluginLayer;
@end
@@ -127,6 +126,7 @@ RenderWidgetHostView* RenderWidgetHostView::
RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget)
: render_widget_host_(widget),
about_to_validate_and_paint_(false),
+ call_set_needs_display_in_rect_pending_(false),
im_attributes_(nil),
im_composing_(false),
is_loading_(false),
@@ -343,9 +343,19 @@ void RenderWidgetHostViewMac::DidPaintBackingStoreRects(
// returns Cocoa will clear its record of what needs display. We instead
// use |performSelector:| to call |setNeedsDisplayInRect:| after returning
// to the main loop, at which point |drawRect:| is no longer on the stack.
- [cocoa_view_ performSelector:@selector(callSetNeedsDisplayInRect:)
- withObject:[NSValue valueWithRect:ns_rect]
- afterDelay:0];
+ DCHECK([NSThread isMainThread]);
+ if (!call_set_needs_display_in_rect_pending_) {
+ [cocoa_view_ performSelector:@selector(callSetNeedsDisplayInRect)
+ withObject:nil
+ afterDelay:0];
+ call_set_needs_display_in_rect_pending_ = true;
+ invalid_rect_ = ns_rect;
+ } else {
+ // The old invalid rect is probably invalid now, since the view has most
+ // likely been resized, but there's no harm in dirtying the union. In
+ // the limit, this becomes equivalent to dirtying the whole view.
+ invalid_rect_ = NSUnionRect(invalid_rect_, ns_rect);
+ }
} else {
[cocoa_view_ setNeedsDisplayInRect:ns_rect];
}
@@ -960,8 +970,12 @@ bool RenderWidgetHostViewMac::ContainsNativeView(
renderWidgetHostView_->render_widget_host_->WasResized();
}
-- (void)callSetNeedsDisplayInRect:(NSValue*)rect {
- [self setNeedsDisplayInRect:[rect rectValue]];
+- (void)callSetNeedsDisplayInRect {
+ DCHECK([NSThread isMainThread]);
+ DCHECK(renderWidgetHostView_->call_set_needs_display_in_rect_pending_);
+ [self setNeedsDisplayInRect:renderWidgetHostView_->invalid_rect_];
+ renderWidgetHostView_->call_set_needs_display_in_rect_pending_ = false;
+ renderWidgetHostView_->invalid_rect_ = NSZeroRect;
}
- (void)drawRect:(NSRect)dirtyRect {