patch to hold on to the image gc when possible. reduces the number of creategc/freegc calls r=imot. linux performance bug 26502

This commit is contained in:
pavlov%netscape.com 2000-08-17 21:53:10 +00:00
parent 5ddc004c36
commit f91b5e9881
2 changed files with 26 additions and 9 deletions

View File

@ -69,6 +69,7 @@ nsImageGTK::nsImageGTK()
mAlphaHeight = 0;
mAlphaWidth = 0;
mConvertedBits = nsnull;
mGC = nsnull;
#ifdef TRACE_IMAGE_ALLOCATION
printf("nsImageGTK::nsImageGTK(this=%p)\n",
this);
@ -97,6 +98,10 @@ nsImageGTK::~nsImageGTK()
gdk_pixmap_unref(mImagePixmap);
}
if (mGC) {
gdk_gc_unref(mGC);
}
#ifdef TRACE_IMAGE_ALLOCATION
printf("nsImageGTK::~nsImageGTK(this=%p)\n",
this);
@ -865,16 +870,19 @@ void nsImageGTK::DrawImageOffscreen(PRInt32 validX, PRInt32 validY, PRInt32 vali
void nsImageGTK::SetupGCForAlpha(GdkGC *aGC, PRInt32 aX, PRInt32 aY)
{
// XXX should use (different?) GC cache here
if (mAlphaPixmap)
{
if (mAlphaPixmap) {
// Setup gc to use the given alpha-pixmap for clipping
XGCValues xvalues;
memset(&xvalues, 0, sizeof(XGCValues));
unsigned long xvalues_mask = 0;
xvalues.clip_x_origin = aX;
xvalues.clip_y_origin = aY;
xvalues.clip_mask = GDK_WINDOW_XWINDOW(mAlphaPixmap);
xvalues_mask = GCClipXOrigin | GCClipYOrigin | GCClipMask;
xvalues_mask = GCClipXOrigin | GCClipYOrigin;
if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, mFlags)) {
xvalues.clip_mask = GDK_WINDOW_XWINDOW(mAlphaPixmap);
xvalues_mask |= GCClipMask;
}
XChangeGC(GDK_DISPLAY(), GDK_GC_XGC(aGC), xvalues_mask, &xvalues);
}
@ -953,13 +961,20 @@ nsImageGTK::Draw(nsIRenderingContext &aContext,
gPixmapTime = PR_Now();
#endif
// make a copy of the GC so that we can completly restore the things we are about to change
GdkGC *copyGC;
if (mAlphaPixmap) {
copyGC = gdk_gc_new(drawing->GetDrawable());
GdkGC *gc = ((nsRenderingContextGTK&)aContext).GetGC();
gdk_gc_copy(copyGC, gc);
gdk_gc_unref(gc);
if (mGC) {
copyGC = gdk_gc_ref(mGC);
} else {
mGC = gdk_gc_new(drawing->GetDrawable());
GdkGC *gc = ((nsRenderingContextGTK&)aContext).GetGC();
gdk_gc_copy(mGC, gc);
gdk_gc_unref(gc); // unref the one we got
gdk_gc_ref(mGC); // we're holding on to this one
copyGC = gdk_gc_ref(mGC);
}
SetupGCForAlpha(copyGC, aX, aY);
} else {
// don't make a copy... we promise not to change it

View File

@ -173,6 +173,8 @@ private:
nsPoint mLocation; // alpha mask location
GdkPixmap *mImagePixmap;
GdkGC *mGC;
PRUint8 mFlags; // flags set by ImageUpdated
};