b=326672, undecoded parts of images render as black instead of being clipped out, r=stuart

This commit is contained in:
vladimir%pobox.com 2006-05-01 23:45:48 +00:00
Родитель 4321a61bbf
Коммит db6df75fb2
2 изменённых файлов: 33 добавлений и 2 удалений

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

@ -54,6 +54,7 @@ nsThebesImage::nsThebesImage()
: mWidth(0),
mHeight(0),
mDecoded(0,0,0,0),
mImageComplete(PR_FALSE),
mAlphaDepth(0)
{
static PRBool hasCheckedOptimize = PR_FALSE;
@ -165,7 +166,9 @@ nsThebesImage::ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *
PRBool
nsThebesImage::GetIsImageComplete()
{
return mDecoded == nsRect(0, 0, mWidth, mHeight);
if (!mImageComplete)
mImageComplete = (mDecoded == nsRect(0, 0, mWidth, mHeight));
return mImageComplete;
}
nsresult
@ -264,9 +267,32 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface,
gfxRect sr(aSX, aSY, aSWidth, aSHeight);
gfxRect dr(aDX, aDY, aDWidth, aDHeight);
gfxFloat xscale = gfxFloat(aDWidth) / aSWidth;
gfxFloat yscale = gfxFloat(aDHeight) / aSHeight;
if (!mImageComplete) {
if (mDecoded.IsEmpty()) {
// nothing's decoded, nothing to render
return NS_OK;
}
// we need to set up a clip
ctx->Save();
gfxFloat d0x = (aDX / xscale) - aSX;
gfxFloat d0y = (aDY / yscale) - aSY;
ctx->NewPath();
ctx->Rectangle(gfxRect(d0x + (mDecoded.x*xscale),
d0y + (mDecoded.y*yscale),
mDecoded.width * xscale,
mDecoded.height * xscale), PR_TRUE);
ctx->Clip();
}
gfxMatrix mat;
mat.Translate(gfxPoint(aSX, aSY));
mat.Scale(double(aSWidth)/aDWidth, double(aSHeight)/aDHeight);
mat.Scale(1.0/xscale, 1.0/yscale);
nsRefPtr<gfxPattern> pat = new gfxPattern(ThebesSurface());
pat->SetMatrix(mat);
@ -275,6 +301,10 @@ nsThebesImage::Draw(nsIRenderingContext &aContext, nsIDrawingSurface *aSurface,
ctx->PixelSnappedRectangleAndSetPattern(dr, pat);
ctx->Fill();
if (!mImageComplete) {
ctx->Restore();
}
return NS_OK;
}

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

@ -106,6 +106,7 @@ protected:
PRInt32 mHeight;
PRInt32 mStride;
nsRect mDecoded;
PRPackedBool mImageComplete;
nsRefPtr<gfxImageSurface> mImageSurface;
nsRefPtr<gfxASurface> mOptSurface;