From 12f5d166941b71c87a356bc624363c672242d31a Mon Sep 17 00:00:00 2001 From: "tor%cs.brown.edu" Date: Sun, 24 Feb 2002 23:42:32 +0000 Subject: [PATCH] Bug 127430 - delete client image copy. r=pavlov, sr=blizzard, a=chofmann --- gfx/src/gtk/nsImageGTK.cpp | 73 ++++++++++++++++++++++++++++++++++ gfx/src/gtk/nsImageGTK.h | 2 + gfx/src/ps/nsPostScriptObj.cpp | 4 ++ 3 files changed, 79 insertions(+) diff --git a/gfx/src/gtk/nsImageGTK.cpp b/gfx/src/gtk/nsImageGTK.cpp index 8380a997b68..9c88665989a 100644 --- a/gfx/src/gtk/nsImageGTK.cpp +++ b/gfx/src/gtk/nsImageGTK.cpp @@ -78,6 +78,7 @@ nsImageGTK::nsImageGTK() mNaturalHeight = 0; mIsSpacer = PR_TRUE; mPendingUpdate = PR_FALSE; + mOptimized = PR_FALSE; #ifdef TRACE_IMAGE_ALLOCATION printf("nsImageGTK::nsImageGTK(this=%p)\n", @@ -1740,6 +1741,33 @@ NS_IMETHODIMP nsImageGTK::DrawTile(nsIRenderingContext &aContext, nsresult nsImageGTK::Optimize(nsIDeviceContext* aContext) { + if (!mOptimized) + UpdateCachedImage(); + + if ((gdk_rgb_get_visual()->depth > 8) && (mAlphaDepth != 8)) { + if(nsnull != mImageBits) { + delete[] mImageBits; + mImageBits = nsnull; + } + + if (nsnull != mAlphaBits) { + delete[] mAlphaBits; + mAlphaBits = nsnull; + } + } + + if (mTrueAlphaBits) { + delete[] mTrueAlphaBits; + mTrueAlphaBits = nsnull; + } + + if ((mAlphaDepth==0) && mAlphaPixmap) { + gdk_pixmap_unref(mAlphaPixmap); + mAlphaPixmap = nsnull; + } + + mOptimized = PR_TRUE; + return NS_OK; } @@ -1748,6 +1776,48 @@ nsresult nsImageGTK::Optimize(nsIDeviceContext* aContext) NS_IMETHODIMP nsImageGTK::LockImagePixels(PRBool aMaskPixels) { + if (mOptimized && mImagePixmap) { + Display *display = GDK_WINDOW_XDISPLAY(mImagePixmap); + Colormap colormap = GDK_COLORMAP_XCOLORMAP(gdk_rgb_get_cmap()); + XImage *ximage, *xmask=0; + XColor color; + + ximage = XGetImage(GDK_WINDOW_XDISPLAY(mImagePixmap), + GDK_WINDOW_XWINDOW(mImagePixmap), + 0, 0, mWidth, mHeight, + AllPlanes, ZPixmap); + + if ((mAlphaDepth==1) && mAlphaPixmap) + xmask = XGetImage(GDK_WINDOW_XDISPLAY(mAlphaPixmap), + GDK_WINDOW_XWINDOW(mAlphaPixmap), + 0, 0, mWidth, mHeight, + AllPlanes, XYPixmap); + + mImageBits = (PRUint8*) new PRUint8[mSizeImage]; + + /* read back the image in the slowest (but simplest) way possible... */ + for (PRInt32 y=0; y>8; + *target++ = color.green>>8; + *target++ = color.blue>>8; + } + } + } + + XDestroyImage(ximage); + if (xmask) + XDestroyImage(xmask); + } + return NS_OK; } @@ -1756,6 +1826,9 @@ nsImageGTK::LockImagePixels(PRBool aMaskPixels) NS_IMETHODIMP nsImageGTK::UnlockImagePixels(PRBool aMaskPixels) { + if (mOptimized) + Optimize(nsnull); + return NS_OK; } diff --git a/gfx/src/gtk/nsImageGTK.h b/gfx/src/gtk/nsImageGTK.h index 20eaff97240..d9bb6981d09 100644 --- a/gfx/src/gtk/nsImageGTK.h +++ b/gfx/src/gtk/nsImageGTK.h @@ -230,6 +230,8 @@ private: PRInt8 mNumBytesPixel; PRUint8 mFlags; // flags set by ImageUpdated PRInt8 mDepth; // bits per pixel + + PRPackedBool mOptimized; }; #endif diff --git a/gfx/src/ps/nsPostScriptObj.cpp b/gfx/src/ps/nsPostScriptObj.cpp index afd50db21ad..af78a9f8ddb 100644 --- a/gfx/src/ps/nsPostScriptObj.cpp +++ b/gfx/src/ps/nsPostScriptObj.cpp @@ -2491,6 +2491,7 @@ PRInt32 sRow, eRow, rStep; fprintf(mPrintContext->prSetup->out, " { currentfile rowdata readhexstring pop }\n"); fprintf(mPrintContext->prSetup->out, " image\n"); + aImage->LockImagePixels(PR_FALSE); theBits = aImage->GetBits(); n = 0; if ( ( isTopToBottom = aImage->GetIsRowOrderTopToBottom()) == PR_TRUE ) { @@ -2519,6 +2520,7 @@ PRInt32 sRow, eRow, rStep; if ( isTopToBottom == PR_TRUE && y < eRow ) break; if ( isTopToBottom == PR_FALSE && y >= eRow ) break; } + aImage->UnlockImagePixels(PR_FALSE); fprintf(mPrintContext->prSetup->out, "\ngrestore\n"); XL_RESTORE_NUMERIC_LOCALE(); @@ -2568,6 +2570,7 @@ PRInt32 sRow, eRow, rStep; fprintf(mPrintContext->prSetup->out, " { currentfile rowdata readhexstring pop }\n"); fprintf(mPrintContext->prSetup->out, " false 3 colorimage\n"); + aImage->LockImagePixels(PR_FALSE); theBits = aImage->GetBits(); n = 0; if ( ( isTopToBottom = aImage->GetIsRowOrderTopToBottom()) == PR_TRUE ) { @@ -2595,6 +2598,7 @@ PRInt32 sRow, eRow, rStep; if ( isTopToBottom == PR_TRUE && y < eRow ) break; if ( isTopToBottom == PR_FALSE && y >= eRow ) break; } + aImage->UnlockImagePixels(PR_FALSE); fprintf(mPrintContext->prSetup->out, "\ngrestore\n"); XL_RESTORE_NUMERIC_LOCALE();