Bug 875335 - Call NotifyDirtyRegion during viewWillDraw. r=mattwoodrow

This commit is contained in:
Markus Stange 2013-06-20 14:59:16 +02:00
parent f647b53fd1
commit e36fb39fa8

View File

@ -140,7 +140,7 @@ uint32_t nsChildView::sLastInputEventCount = 0;
- (void)processPendingRedraws;
- (void)drawRect:(NSRect)aRect inContext:(CGContextRef)aContext;
- (nsIntRegion)nativeDirtyRegionWithBoundingRect:(NSRect)aRect;
- (BOOL)isUsingMainThreadOpenGL;
- (BOOL)isUsingOpenGL;
- (void)drawUsingOpenGL;
@ -2946,6 +2946,27 @@ NSEvent* gLastDragMouseDownEvent = nil;
[(BaseWindow*)[self window] drawsContentsIntoWindowFrame];
}
- (nsIntRegion)nativeDirtyRegionWithBoundingRect:(NSRect)aRect
{
nsIntRect boundingRect = mGeckoChild->CocoaPointsToDevPixels(aRect);
const NSRect *rects;
NSInteger count;
[[NSView focusView] getRectsBeingDrawn:&rects count:&count];
if (count > MAX_RECTS_IN_REGION) {
return boundingRect;
}
nsIntRegion region;
for (NSInteger i = 0; i < count; ++i) {
// Add the rect to the region.
NSRect r = [self convertRect:rects[i] fromView:[NSView focusView]];
region.Or(region, mGeckoChild->CocoaPointsToDevPixels(r));
}
region.And(region, boundingRect);
return region;
}
// The display system has told us that a portion of our view is dirty. Tell
// gecko to paint it
- (void)drawRect:(NSRect)aRect
@ -2982,25 +3003,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
fprintf (stderr, " xform in: [%f %f %f %f %f %f]\n", xform.a, xform.b, xform.c, xform.d, xform.tx, xform.ty);
#endif
nsIntRegion region;
nsIntRect boundingRect = mGeckoChild->CocoaPointsToDevPixels(aRect);
const NSRect *rects;
NSInteger count, i;
[[NSView focusView] getRectsBeingDrawn:&rects count:&count];
CGContextClipToRects(aContext, (CGRect*)rects, count);
if (count < MAX_RECTS_IN_REGION) {
for (i = 0; i < count; ++i) {
// Add the rect to the region.
NSRect r = [self convertRect:rects[i] fromView:[NSView focusView]];
region.Or(region, mGeckoChild->CocoaPointsToDevPixels(r));
}
region.And(region, boundingRect);
} else {
region = boundingRect;
}
if ([self isUsingOpenGL]) {
// For Gecko-initiated repaints in OpenGL mode, drawUsingOpenGL is
// directly called from a delayed perform callback - without going through
@ -3016,11 +3018,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
// So we need to clear the pixel buffer contents in the corners.
[self clearCorners];
// When our view covers the titlebar, we need to repaint the titlebar
// texture buffer when, for example, the window buttons are hovered.
// So we notify our nsChildView about any areas needing repainting.
mGeckoChild->NotifyDirtyRegion(region);
// Do GL composition and return.
[self drawUsingOpenGL];
return;
@ -3028,6 +3025,12 @@ NSEvent* gLastDragMouseDownEvent = nil;
PROFILER_LABEL("widget", "ChildView::drawRect");
// Clip to the dirty region.
const NSRect *rects;
NSInteger count;
[[NSView focusView] getRectsBeingDrawn:&rects count:&count];
CGContextClipToRects(aContext, (CGRect*)rects, count);
// The CGContext that drawRect supplies us with comes with a transform that
// scales one user space unit to one Cocoa point, which can consist of
// multiple dev pixels. But Gecko expects its supplied context to be scaled
@ -3041,6 +3044,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
CGContextSaveGState(aContext);
nsIntRegion region = [self nativeDirtyRegionWithBoundingRect:aRect];
// Create Cairo objects.
nsRefPtr<gfxQuartzSurface> targetSurface =
new gfxQuartzSurface(aContext, backingSize);
@ -3307,6 +3312,13 @@ NSEvent* gLastDragMouseDownEvent = nil;
afterDelay:0];
}
if ([self isUsingOpenGL]) {
// When our view covers the titlebar, we need to repaint the titlebar
// texture buffer when, for example, the window buttons are hovered.
// So we notify our nsChildView about any areas needing repainting.
mGeckoChild->NotifyDirtyRegion([self nativeDirtyRegionWithBoundingRect:[self bounds]]);
}
mGeckoChild->WillPaintWindow();
}
[super viewWillDraw];