more x server traffic reduction by reducing cliping stuff r=blizzard

This commit is contained in:
pavlov%netscape.com 2000-02-03 23:18:31 +00:00
parent e89e4e37a5
commit 7a85210963
5 changed files with 58 additions and 68 deletions

View File

@ -376,24 +376,6 @@ NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
return NS_OK;
}
/* below are utility functions used mostly for nsRenderingContext and nsImage
* to plug into gdk_* functions for drawing. You should not set a pointer
* that might hang around with the return from these. instead use the ones
* above. pav
*/
GdkDrawable *nsDrawingSurfaceGTK::GetDrawable(void)
{
return mPixmap;
}
void nsDrawingSurfaceGTK::GetSize(PRUint32 *aWidth, PRUint32 *aHeight)
{
*aWidth = mWidth;
*aHeight = mHeight;
}
PRUint8
nsDrawingSurfaceGTK::ConvertMaskToCount(unsigned long val)
{

View File

@ -60,9 +60,9 @@ public:
* that might hang around with the return from these. instead use the ones
* above. pav
*/
GdkDrawable *GetDrawable(void);
GdkDrawable *GetDrawable(void) { return mPixmap; }
void GetSize(PRUint32 *aWidth, PRUint32 *aHeight);
void GetSize(PRUint32 *aWidth, PRUint32 *aHeight) { *aWidth = mWidth; *aHeight = mHeight; }
protected:

View File

@ -59,7 +59,7 @@ void nsGCCache::Flush(unsigned long flags)
if (gc_cache [i].flags & flags) {
gdk_gc_unref(gc_cache [i].gc);
if (gc_cache [i].clipRegion)
gdk_region_destroy(gc_cache [i].clipRegion);
gdk_region_destroy(gc_cache [i].clipRegion);
memset (&gc_cache [i], 0, sizeof (gc_cache [i]));
}
else
@ -83,17 +83,17 @@ GdkGC *nsGCCache::GetGCFromDW(GdkWindow *window, GdkGCValues *gcv, GdkGCValuesMa
i++)
{
if (flags == gc_cache [i].flags &&
!memcmp (gcv, &gc_cache [i].gcv, sizeof (*gcv)))
!memcmp (gcv, &gc_cache [i].gcv, sizeof (*gcv)))
if (clipRegion) {
if (gc_cache[i].clipRegion &&
gdk_region_equal(clipRegion, gc_cache[i].clipRegion)) {
// printf("found GC in cache %i\n", ++numCalls);
return gc_cache [i].gc;
}
if (gc_cache[i].clipRegion &&
gdk_region_equal(clipRegion, gc_cache[i].clipRegion)) {
// printf("found GC in cache %i\n", ++numCalls);
return gc_cache [i].gc;
}
} else {
if(!gc_cache[i].clipRegion)
// printf("found GC in cache %i\n", ++numCalls);
return gc_cache [i].gc;
if(!gc_cache[i].clipRegion)
// printf("found GC in cache (no region) %i\n", ++numCalls);
return gc_cache [i].gc;
}
}
@ -111,7 +111,7 @@ GdkGC *nsGCCache::GetGCFromDW(GdkWindow *window, GdkGCValues *gcv, GdkGCValuesMa
if (clear_p) {
gdk_gc_unref(gc_cache [this_slot].gc);
if (gc_cache [this_slot].clipRegion)
gdk_region_destroy(gc_cache [this_slot].clipRegion);
gdk_region_destroy(gc_cache [this_slot].clipRegion);
gc_cache [this_slot].gc = NULL;
gc_cache [this_slot].clipRegion = NULL;
}
@ -125,7 +125,7 @@ GdkGC *nsGCCache::GetGCFromDW(GdkWindow *window, GdkGCValues *gcv, GdkGCValuesMa
gc_cache [this_slot].clipRegion = gdk_region_copy(clipRegion);
if (gc_cache [this_slot].clipRegion) {
gdk_gc_set_clip_region(gc, gc_cache [this_slot].clipRegion);
gdk_gc_set_clip_region(gc, gc_cache [this_slot].clipRegion);
}
}

View File

@ -157,21 +157,6 @@ NS_IMETHODIMP nsRenderingContextGTK::Init(nsIDeviceContext* aContext,
NS_IMETHODIMP nsRenderingContextGTK::CommonInit()
{
// this keeps the cursor flashing
PRUint32 w, h;
mSurface->GetSize(&w, &h);
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)&mClipRegion)) )
{
mClipRegion->Init();
mClipRegion->SetTo(0,0,w,h);
} else {
// we're going to crash shortly after if we hit this, but we will return NS_ERROR_FAILURE anyways.
return NS_ERROR_FAILURE;
}
mContext->GetDevUnitsToAppUnits(mP2T);
float app2dev;
mContext->GetAppUnitsToDevUnits(app2dev);
@ -344,12 +329,11 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty)
mTMatrix = state->mMatrix;
}
if (state->mClipRegion) {
NS_IF_RELEASE(mClipRegion);
// state->mClipRegion might be null, but thats ok. we want that.
NS_IF_RELEASE(mClipRegion);
mClipRegion = state->mClipRegion;
mClipIsSet = PR_FALSE;
}
mClipRegion = state->mClipRegion;
mClipIsSet = PR_FALSE;
if (state->mFontMetrics && (mFontMetrics != state->mFontMetrics))
SetFont(state->mFontMetrics);
@ -383,10 +367,26 @@ NS_IMETHODIMP nsRenderingContextGTK::IsVisibleRect(const nsRect& aRect,
return NS_OK;
}
NS_METHOD nsRenderingContextGTK::CreateClipRegion()
{
PRUint32 w, h;
mSurface->GetSize(&w, &h);
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)&mClipRegion)) ) {
mClipRegion->Init();
mClipRegion->SetTo(0,0,w,h);
} else {
// we're going to crash shortly after if we hit this, but we will return NS_ERROR_FAILURE anyways.
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP nsRenderingContextGTK::GetClipRect(nsRect &aRect, PRBool &aClipValid)
{
PRInt32 x, y, w, h;
if (!mClipRegion->IsEmpty())
if (!mClipRegion || !mClipRegion->IsEmpty())
{
mClipRegion->GetBoundingBox(&x,&y,&w,&h);
aRect.SetRect(x,y,w,h);
@ -443,6 +443,11 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
if (!mClipRegion) {
CreateClipRegion();
}
nsRect trect = aRect;
#ifdef TRACE_SET_CLIP
@ -452,8 +457,6 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
mClipIsSet = PR_FALSE;
mClipIsSet = PR_FALSE;
mTMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height);
@ -509,8 +512,10 @@ void nsRenderingContextGTK::UpdateGC()
valuesMask = GdkGCValuesMask(valuesMask | GDK_GC_FUNCTION);
values.function = mFunction;
GdkRegion *rgn;
mClipRegion->GetNativeRegion((void*&)rgn);
GdkRegion *rgn = nsnull;
if (mClipRegion) {
mClipRegion->GetNativeRegion((void*&)rgn);
}
mGC = gcCache->GetClipGC(mSurface->GetDrawable(),
&values,
@ -564,8 +569,8 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
if(!mClipRegion) {
return NS_ERROR_FAILURE;
if (!mClipRegion) {
CreateClipRegion();
}
mClipIsSet = PR_FALSE;
@ -596,6 +601,9 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
*/
NS_IMETHODIMP nsRenderingContextGTK::CopyClipRegion(nsIRegion &aRegion)
{
if (!mClipRegion)
return NS_ERROR_FAILURE;
aRegion.SetTo(*NS_STATIC_CAST(nsIRegion*, mClipRegion));
return NS_OK;
}
@ -604,7 +612,7 @@ NS_IMETHODIMP nsRenderingContextGTK::GetClipRegion(nsIRegion **aRegion)
{
nsresult rv = NS_ERROR_FAILURE;
if (!aRegion)
if (!aRegion || !mClipRegion)
return NS_ERROR_NULL_POINTER;
if (*aRegion) { // copy it, they should be using CopyClipRegion
@ -1619,10 +1627,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage,
{
nscoord x, y, w, h;
if (mClipRegion->IsEmpty())
{
// this is bad!
// printf("drawing image with empty clip region\n");
if (!mClipRegion) {
return NS_ERROR_FAILURE;
} else if (mClipRegion->IsEmpty()) {
return NS_ERROR_FAILURE;
}
@ -1657,10 +1664,9 @@ NS_IMETHODIMP nsRenderingContextGTK::DrawImage(nsIImage *aImage,
{
nsRect sr,dr;
if (mClipRegion->IsEmpty())
{
// this is bad!
// printf("drawing image with empty clip region\n");
if (!mClipRegion) {
return NS_ERROR_FAILURE;
} else if (mClipRegion->IsEmpty()) {
return NS_ERROR_FAILURE;
}

View File

@ -77,6 +77,8 @@ public:
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
NS_METHOD CreateClipRegion();
NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine, PRBool &aClipEmpty);