Bug 190311. Make nsImageGTK UpdateGC() when it needs to change the clip rect; make it set the correct clip rect. In the view system, make sure VIEW_CLIPPED is set only when needed.

This commit is contained in:
roc+%cs.cmu.edu 2003-02-25 02:38:38 +00:00
parent 33f7fd71de
commit 6fc98b9e15
4 changed files with 30 additions and 22 deletions

View File

@ -39,12 +39,12 @@
// Defining this will trace the allocation of images. This includes
// ctor, dtor and update.
//#define TRACE_IMAGE_ALLOCATION
// #define TRACE_IMAGE_ALLOCATION
//#define CHEAP_PERFORMANCE_MEASURMENT 1
// Define this to see tiling debug output
//#define DEBUG_TILING
// #define DEBUG_TILING
/* XXX we are simply creating a GC and setting its function to Copy.
we shouldn't be doing this every time this method is called. this creates
@ -269,9 +269,8 @@ void nsImageGTK::ImageUpdated(nsIDeviceContext *aContext,
void nsImageGTK::UpdateCachedImage()
{
#ifdef TRACE_IMAGE_ALLOCATION
printf("nsImageGTK::ImageUpdated(this=%p,%d)\n",
this,
aFlags);
printf("nsImageGTK::ImageUpdated(this=%p)\n",
this);
#endif
nsRegionRectIterator ri(mUpdateRegion);
@ -1576,7 +1575,6 @@ NS_IMETHODIMP nsImageGTK::DrawTile(nsIRenderingContext &aContext,
aTileRect.x, aTileRect.y,
aTileRect.width, aTileRect.height, this);
#endif
if (mPendingUpdate)
UpdateCachedImage();
@ -1627,8 +1625,9 @@ NS_IMETHODIMP nsImageGTK::DrawTile(nsIRenderingContext &aContext,
// Set up clipping and call Draw().
PRBool clipState;
aContext.PushState();
aContext.SetClipRect(aTileRect, nsClipCombine_kIntersect,
clipState);
((nsRenderingContextGTK&)aContext).SetClipRectInPixels(
aTileRect, nsClipCombine_kIntersect, clipState);
((nsRenderingContextGTK&)aContext).UpdateGC();
if (mAlphaDepth==8) {
DrawCompositeTile(aContext, aSurface,

View File

@ -458,9 +458,17 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
nsRect trect = aRect;
mTranMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height);
SetClipRectInPixels(trect, aCombine, aClipEmpty);
return NS_OK;
}
void nsRenderingContextGTK::SetClipRectInPixels(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
PRUint32 cnt = mStateCache.Count();
nsGraphicsState *state = nsnull;
@ -480,29 +488,24 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
CreateClipRegion();
nsRect trect = aRect;
#ifdef TRACE_SET_CLIP
printf("nsRenderingContextGTK::SetClipRect(%s)\n",
nsClipCombine_to_string(aCombine));
#endif // TRACE_SET_CLIP
mTranMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height);
switch(aCombine)
{
case nsClipCombine_kIntersect:
mClipRegion->Intersect(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Intersect(aRect.x,aRect.y,aRect.width,aRect.height);
break;
case nsClipCombine_kUnion:
mClipRegion->Union(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Union(aRect.x,aRect.y,aRect.width,aRect.height);
break;
case nsClipCombine_kSubtract:
mClipRegion->Subtract(trect.x,trect.y,trect.width,trect.height);
mClipRegion->Subtract(aRect.x,aRect.y,aRect.width,aRect.height);
break;
case nsClipCombine_kReplace:
mClipRegion->SetTo(trect.x,trect.y,trect.width,trect.height);
mClipRegion->SetTo(aRect.x,aRect.y,aRect.width,aRect.height);
break;
}
#if 0
@ -512,8 +515,6 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
SetColor(color);
#endif
aClipEmpty = mClipRegion->IsEmpty();
return NS_OK;
}
void nsRenderingContextGTK::UpdateGC()

View File

@ -242,6 +242,8 @@ public:
return gdk_gc_ref(mGC);
}
void SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
// cause the GC to be updated
void UpdateGC();

View File

@ -1041,18 +1041,24 @@ NS_IMETHODIMP nsView::GetClippedRect(nsRect& aClippedRect, PRBool& aIsClipped, P
}
if (parentView->GetClipChildren()) {
aIsClipped = PR_TRUE;
// Adjust for clip specified by ancestor
nsRect clipRect;
parentView->GetChildClip(clipRect);
//Offset the cliprect by the amount the child offsets from the parent
clipRect.x -= ancestorX;
clipRect.y -= ancestorY;
nsRect oldClippedRect = aClippedRect;
PRBool overlap = aClippedRect.IntersectRect(clipRect, aClippedRect);
if (!overlap) {
aIsClipped = PR_TRUE;
aEmpty = PR_TRUE; // Does not intersect so the rect is empty.
return NS_OK;
}
if (oldClippedRect != aClippedRect) {
aIsClipped = PR_TRUE;
}
}
parentView->ConvertToParentCoords(&ancestorX, &ancestorY);