redo the entire region handling in nsRenderingContext -- not quite finished

This commit is contained in:
pavlov%pavlov.net 1999-02-04 19:17:40 +00:00
Родитель 4fc165016c
Коммит 83d4111203
4 изменённых файлов: 98 добавлений и 173 удалений

Просмотреть файл

@ -58,7 +58,6 @@ void nsRegionGTK::SetTo(const nsIRegion &aRegion)
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
@ -77,8 +76,6 @@ void nsRegionGTK::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
GdkRegion *nRegion = ::gdk_region_union_with_rect(mRegion, &grect);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Intersect(const nsIRegion &aRegion)
@ -88,8 +85,6 @@ void nsRegionGTK::Intersect(const nsIRegion &aRegion)
GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
@ -101,8 +96,6 @@ void nsRegionGTK::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHei
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Union(const nsIRegion &aRegion)
@ -112,8 +105,6 @@ void nsRegionGTK::Union(const nsIRegion &aRegion)
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
@ -125,9 +116,6 @@ void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
::gdk_region_destroy(mRegion);
::gdk_region_destroy(tRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Subtract(const nsIRegion &aRegion)
@ -137,9 +125,6 @@ void nsRegionGTK::Subtract(const nsIRegion &aRegion)
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
SetRegionType();
}
void nsRegionGTK::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
@ -150,22 +135,16 @@ void nsRegionGTK::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeig
::gdk_region_destroy(mRegion);
::gdk_region_destroy(tRegion);
mRegion = nRegion;
SetRegionType();
}
PRBool nsRegionGTK::IsEmpty(void)
{
if (mRegionType == eRegionComplexity_empty)
return PR_TRUE;
return PR_FALSE;
return (::gdk_region_empty(mRegion));
}
PRBool nsRegionGTK::IsEqual(const nsIRegion &aRegion)
{
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
return(::gdk_region_equal(mRegion, pRegion->mRegion));
@ -220,16 +199,12 @@ NS_IMETHODIMP nsRegionGTK::GetNativeRegion(void *&aRegion) const
NS_IMETHODIMP nsRegionGTK::GetRegionComplexity(nsRegionComplexity &aComplexity) const
{
aComplexity = mRegionType;
return NS_OK;
}
void nsRegionGTK::SetRegionType()
{
if (::gdk_region_empty(mRegion) == TRUE)
mRegionType = eRegionComplexity_empty;
if (IsEmpty())
aComplexity = eRegionComplexity_empty;
else
mRegionType = eRegionComplexity_rect ;
aComplexity = eRegionComplexity_rect;
return NS_OK;
}
void nsRegionGTK::SetRegionEmpty()
@ -238,7 +213,10 @@ void nsRegionGTK::SetRegionEmpty()
mRegion = ::gdk_region_new();
}
GdkRegion * nsRegionGTK::CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
GdkRegion *nsRegionGTK::CreateRectRegion(PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight)
{
GdkRegion *tRegion = ::gdk_region_new();
GdkRectangle rect;

Просмотреть файл

@ -48,14 +48,13 @@ public:
NS_IMETHOD GetNativeRegion(void *&aRegion) const;
NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
GdkRegion *CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
private:
GdkRegion *mRegion;
nsRegionComplexity mRegionType;
private:
virtual void SetRegionType();
virtual void SetRegionEmpty();
virtual GdkRegion *CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
};

Просмотреть файл

@ -42,7 +42,7 @@ public:
nsTransform2D *mMatrix;
nsRect mLocalClip;
GdkRegion *mClipRegion;
nsRegionGTK *mClipRegion;
nscolor mColor;
nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics;
@ -79,16 +79,15 @@ nsRenderingContextGTK::nsRenderingContextGTK()
mTMatrix = nsnull;
mP2T = 1.0f;
mStateCache = new nsVoidArray();
mRegion = nsnull;
mRegion = new nsRegionGTK();
mRegion->Init();
PushState();
}
nsRenderingContextGTK::~nsRenderingContextGTK()
{
if (mRegion) {
::gdk_region_destroy(mRegion);
mRegion = nsnull;
}
delete mRegion;
mTMatrix = nsnull;
@ -220,18 +219,13 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(void)
state->mClipRegion = mRegion;
if (nsnull != state->mClipRegion) {
GdkRegion *tRegion = ::gdk_region_new ();
GdkRectangle gdk_rect;
gdk_rect.x = state->mLocalClip.x;
gdk_rect.y = state->mLocalClip.y;
gdk_rect.width = state->mLocalClip.width;
gdk_rect.height = state->mLocalClip.height;
mRegion = ::gdk_region_union_with_rect (tRegion, &gdk_rect);
gdk_region_destroy (tRegion);
mRegion = new nsRegionGTK();
mRegion->Init();
mRegion->SetTo(state->mLocalClip.x,
state->mLocalClip.y,
state->mLocalClip.width,
state->mLocalClip.height);
}
state->mColor = mCurrentColor;
@ -257,19 +251,24 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty)
mTMatrix = state->mMatrix;
if (nsnull != mRegion)
::gdk_region_destroy(mRegion);
delete mRegion;
mRegion = state->mClipRegion;
if (nsnull != mRegion && ::gdk_region_empty(mRegion) == True){
if (nsnull != mRegion && mRegion->IsEmpty() == PR_TRUE) {
bEmpty = PR_TRUE;
}else{
// Select in the old region. We probably want to set a dirty flag and only
// do this IFF we need to draw before the next Pop. We'd need to check the
// state flag on every draw operation.
// Select in the old region. We probably want to set a dirty flag and only
// do this IFF we need to draw before the next Pop. We'd need to check the
// state flag on every draw operation.
if (nsnull != mRegion)
::gdk_gc_set_clip_region (mRenderingSurface->gc, mRegion);
{
GdkRegion *rgn;
mRegion->GetNativeRegion((void*&)rgn);
::gdk_gc_set_clip_region (mRenderingSurface->gc, rgn);
// can we destroy rgn now?
}
}
if (state->mColor != mCurrentColor)
@ -295,23 +294,13 @@ NS_IMETHODIMP nsRenderingContextGTK::IsVisibleRect(const nsRect& aRect,
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
nsRect trect = aRect;
mTMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height);
return SetClipRectInPixels(trect, aCombine, aClipEmpty);
}
NS_IMETHODIMP nsRenderingContextGTK::GetClipRect(nsRect &aRect, PRBool &aClipValid)
{
if (mRegion != nsnull) {
GdkRectangle gdk_rect;
::gdk_region_get_clipbox(mRegion, &gdk_rect);
aRect.SetRect(gdk_rect.x, gdk_rect.y, gdk_rect.width, gdk_rect.height);
PRInt32 x, y, w, h;
if (!mRegion->IsEmpty())
{
mRegion->GetBoundingBox(&x,&y,&w,&h);
aRect.SetRect(x,y,w,h);
aClipValid = PR_TRUE;
} else {
aRect.SetRect(0,0,0,0);
@ -319,65 +308,77 @@ NS_IMETHODIMP nsRenderingContextGTK::GetClipRect(nsRect &aRect, PRBool &aClipVal
}
return NS_OK;
/*
if (::gdk_region_empty (mRegion))
aClipValid = PR_TRUE;
else
aClipValid = PR_FALSE;
}
NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
nsRect trect = aRect;
GdkRegion *rgn;
// mStates->mLocalClip = aRect;
mTMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height);
switch(aCombine)
{
case nsClipCombine_kIntersect:
mRegion->Intersect(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kUnion:
mRegion->Union(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kSubtract:
mRegion->Subtract(trect.x,trect.y,trect.width,trect.height);
break;
case nsClipCombine_kReplace:
mRegion->SetTo(trect.x,trect.y,trect.width,trect.height);
break;
}
aClipEmpty = mRegion->IsEmpty();
mRegion->GetNativeRegion((void*&)rgn);
gdk_gc_set_clip_region(mRenderingSurface->gc,rgn);
return NS_OK;
*/
}
NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
nsRect rect;
GdkRectangle gdk_rect;
GdkRegion *gdk_region;
GdkRegion *rgn;
switch(aCombine)
{
case nsClipCombine_kIntersect:
mRegion->Intersect(aRegion);
break;
case nsClipCombine_kUnion:
mRegion->Union(aRegion);
break;
case nsClipCombine_kSubtract:
mRegion->Subtract(aRegion);
break;
case nsClipCombine_kReplace:
mRegion->SetTo(aRegion);
break;
}
aRegion.GetNativeRegion((void *&)gdk_region);
::gdk_region_get_clipbox (gdk_region, &gdk_rect);
rect.x = gdk_rect.x;
rect.y = gdk_rect.y;
rect.width = gdk_rect.width;
rect.height = gdk_rect.height;
SetClipRectInPixels(rect, aCombine, aClipEmpty);
if (::gdk_region_empty(mRegion))
aClipEmpty = PR_TRUE;
else
aClipEmpty = PR_FALSE;
aClipEmpty = mRegion->IsEmpty();
mRegion->GetNativeRegion((void*&)rgn);
gdk_gc_set_clip_region(mRenderingSurface->gc,rgn);
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::GetClipRegion(nsIRegion **aRegion)
{
nsIRegion * pRegion ;
static NS_DEFINE_IID(kCRegionCID, NS_REGION_CID);
static NS_DEFINE_IID(kIRegionIID, NS_IREGION_IID);
nsresult rv = nsRepository::CreateInstance(kCRegionCID,
nsnull,
kIRegionIID,
(void **)aRegion);
// XXX this just gets the ClipRect as a region...
if (NS_OK == rv) {
nsRect rect;
PRBool clipState;
pRegion = (nsIRegion *)&aRegion;
pRegion->Init();
GetClipRect(rect, clipState);
pRegion->Union(rect.x,rect.y,rect.width,rect.height);
}
NS_IF_ADDREF(mRegion);
*aRegion = (nsIRegion*)&mRegion;
return NS_OK;
}
@ -1058,56 +1059,3 @@ nsRenderingContextGTK::CopyOffScreenBits(nsDrawingSurface aSrcSurf,
return NS_OK;
}
NS_IMETHODIMP
nsRenderingContextGTK::SetClipRectInPixels(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
g_return_val_if_fail(mTMatrix != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->drawable != NULL, NS_ERROR_FAILURE);
g_return_val_if_fail(mRenderingSurface->gc != NULL, NS_ERROR_FAILURE);
if (mRegion == nsnull)
mRegion = ::gdk_region_new();
GdkRectangle gdk_rect;
gdk_rect.x = aRect.x;
gdk_rect.y = aRect.y;
gdk_rect.width = aRect.width;
gdk_rect.height = aRect.height;
GdkRegion *a = ::gdk_region_union_with_rect(mRegion, &gdk_rect);
GdkRegion *nrgn=nsnull;
switch(aCombine)
{
case nsClipCombine_kIntersect:
nrgn = ::gdk_regions_intersect (mRegion,a);
gdk_region_destroy(mRegion);
mRegion = nrgn;
break;
case nsClipCombine_kUnion:
nrgn = ::gdk_regions_union (mRegion,a);
gdk_region_destroy(mRegion);
mRegion = nrgn;
break;
case nsClipCombine_kSubtract:
nrgn = ::gdk_regions_subtract (mRegion,a);
gdk_region_destroy(mRegion);
mRegion = nrgn;
break;
case nsClipCombine_kReplace:
gdk_region_destroy(mRegion);
mRegion = a;
break;
}
aClipEmpty = ::gdk_region_empty(mRegion);
::gdk_gc_set_clip_region(mRenderingSurface->gc, mRegion);
return NS_OK;
}

Просмотреть файл

@ -35,6 +35,7 @@
#include "nsVoidArray.h"
#include "nsDrawingSurfaceGTK.h"
#include "nsRegionGTK.h"
#include <gtk/gtk.h>
@ -147,14 +148,13 @@ public:
//locals
NS_IMETHOD CommonInit();
NS_IMETHOD SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
protected:
nsDrawingSurfaceGTK *mOffscreenSurface;
nsDrawingSurfaceGTK *mRenderingSurface;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
GdkRegion *mRegion;
nsRegionGTK *mRegion;
nsTransform2D *mTMatrix;
float mP2T;