From ee85b339087cfb95d090e33c124dde23b9266498 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Tue, 28 Nov 2006 00:11:42 +0000 Subject: [PATCH] bug 362015. r=vlad. makes us use a region for drawing to avoid painting too much. --- widget/src/cocoa/nsChildView.mm | 40 ++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 7d4d8a31fb30..eeb4408827fc 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -2515,33 +2515,43 @@ NSEvent* globalDragEvent = nil; nsRefPtr targetContext = new gfxContext(targetSurface); + nsCOMPtr rc; + mGeckoChild->GetDeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc)); + rc->Init(mGeckoChild->GetDeviceContext(), targetContext); + + /* clip and build a region */ + nsCOMPtr rgn(do_CreateInstance(kRegionCID)); + if (rgn) + rgn->Init(); + const NSRect *rects; int count, i; [self getRectsBeingDrawn:&rects count:&count]; for (i = 0; i < count; ++i) { - targetContext->Rectangle(gfxRect(rects[i].origin.x, rects[i].origin.y, - rects[i].size.width, rects[i].size.height)); + const NSRect& r = rects[i]; + + /* add to the region */ + if (rgn) + rgn->Union(r.origin.x, r.origin.y, r.size.width, r.size.height); + + /* to the context for clipping */ + targetContext->Rectangle(gfxRect(r.origin.x, r.origin.y, r.size.width, r.size.height)); } targetContext->Clip(); - - nsCOMPtr rc; - mGeckoChild->GetDeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc)); - rc->Init (mGeckoChild->GetDeviceContext(), targetContext); - nsRect r, tr; - NSRectToGeckoRect(aRect, r); - tr = r; - - mGeckoChild->LocalToWindowCoordinate(tr); - //targetContext->Translate(gfxPoint(tr.x, tr.y)); + /* bounding box of the dirty area */ + nsRect fullRect; + NSRectToGeckoRect(aRect, fullRect); nsPaintEvent paintEvent(PR_TRUE, NS_PAINT, mGeckoChild); paintEvent.renderingContext = rc; - paintEvent.rect = &r; + paintEvent.rect = &fullRect; + paintEvent.region = rgn; mGeckoChild->DispatchWindowEvent(paintEvent); paintEvent.renderingContext = nsnull; + paintEvent.region = nsnull; targetContext = nsnull; targetSurface = nsnull; @@ -2564,8 +2574,8 @@ NSEvent* globalDragEvent = nil; CGRectMake(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height)); #endif -#else - +#else + /* non-MOZ_CAIRO_GFX */ nsCOMPtr rgn(do_CreateInstance(kRegionCID)); if (rgn) { rgn->Init();