From 85a8762e4ffe7b480acd4a17fb12cfce9a217123 Mon Sep 17 00:00:00 2001 From: "pavlov%netscape.com" Date: Fri, 19 Oct 2001 04:16:50 +0000 Subject: [PATCH] part of fix for bug 104999. r=jag sr=jst --- .../libpr0n/decoders/jpeg/nsJPEGDecoder.cpp | 2 +- modules/libpr0n/decoders/png/nsPNGDecoder.cpp | 4 ++ .../libpr0n/public/imgIContainerObserver.idl | 2 +- modules/libpr0n/src/imgContainer.cpp | 37 +++++++++++++------ 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp b/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp index 0204644cb0de..af0b9df52db2 100644 --- a/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp +++ b/modules/libpr0n/decoders/jpeg/nsJPEGDecoder.cpp @@ -866,5 +866,5 @@ term_source (j_decompress_ptr jd) src->decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull); } - /* No work necessary here */ + src->decoder->mFrame->SetMutable(PR_FALSE); } diff --git a/modules/libpr0n/decoders/png/nsPNGDecoder.cpp b/modules/libpr0n/decoders/png/nsPNGDecoder.cpp index e546d203ed82..39e79b1b16d5 100644 --- a/modules/libpr0n/decoders/png/nsPNGDecoder.cpp +++ b/modules/libpr0n/decoders/png/nsPNGDecoder.cpp @@ -537,5 +537,9 @@ end_callback(png_structp png_ptr, png_infop info_ptr) decoder->mObserver->OnStopContainer(nsnull, nsnull, decoder->mImage); decoder->mObserver->OnStopDecode(nsnull, nsnull, NS_OK, nsnull); } + + // We are never going to change the data of this frame again. Let the OS + // do what it wants with this image. + decoder->mFrame->SetMutable(PR_FALSE); } diff --git a/modules/libpr0n/public/imgIContainerObserver.idl b/modules/libpr0n/public/imgIContainerObserver.idl index 84bb60a62359..9733dd497dc9 100644 --- a/modules/libpr0n/public/imgIContainerObserver.idl +++ b/modules/libpr0n/public/imgIContainerObserver.idl @@ -1,4 +1,4 @@ -/** -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file diff --git a/modules/libpr0n/src/imgContainer.cpp b/modules/libpr0n/src/imgContainer.cpp index 34b6ce56aa2b..0b380d2ceac8 100644 --- a/modules/libpr0n/src/imgContainer.cpp +++ b/modules/libpr0n/src/imgContainer.cpp @@ -26,13 +26,13 @@ #include "imgContainer.h" #include "nsIServiceManager.h" +#include "nsIImage.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "gfxIImageFrame.h" -#include "nsIImage.h" #include "nsMemory.h" -NS_IMPL_ISUPPORTS3(imgContainer, imgIContainer, nsITimerCallback,imgIDecoderObserver) +NS_IMPL_ISUPPORTS3(imgContainer, imgIContainer, nsITimerCallback, imgIDecoderObserver) //****************************************************************************** imgContainer::imgContainer() : @@ -105,10 +105,13 @@ NS_IMETHODIMP imgContainer::GetHeight(nscoord *aHeight) /* readonly attribute gfxIImageFrame currentFrame; */ NS_IMETHODIMP imgContainer::GetCurrentFrame(gfxIImageFrame * *aCurrentFrame) { - if (mCompositingFrame) - return mCompositingFrame->QueryInterface(NS_GET_IID(gfxIImageFrame), (void**)aCurrentFrame); // addrefs again - else - return this->GetFrameAt(mCurrentAnimationFrameIndex, aCurrentFrame); + if (mCompositingFrame) { + *aCurrentFrame = mCompositingFrame; + NS_ADDREF(*aCurrentFrame); + return NS_OK; + } + + return this->GetFrameAt(mCurrentAnimationFrameIndex, aCurrentFrame); } //****************************************************************************** @@ -162,10 +165,14 @@ NS_IMETHODIMP imgContainer::AppendFrame(gfxIImageFrame *item) (numFrames >= 1)) // Not sure if I want to create a composite frame for every anim. Could be smarter. { mCompositingFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2"); - mCompositingFrame->Init(0, 0, mSize.width, mSize.height, gfxIFormats::RGB_A1); - nsCOMPtr img(do_GetInterface(mCompositingFrame)); - img->SetDecodedRect(0, 0, mSize.width, mSize.height); - + mCompositingFrame->Init(0, 0, mSize.width, mSize.height, gfxIFormats::RGB_A1); + + nsCOMPtr ireq(do_QueryInterface(mCompositingFrame)); + if (ireq) { + nsCOMPtr img(do_GetInterface(ireq)); + img->SetDecodedRect(0, 0, mSize.width, mSize.height); + } + nsCOMPtr firstFrame; this->GetFrameAt(0, getter_AddRefs(firstFrame)); @@ -243,6 +250,14 @@ NS_IMETHODIMP imgContainer::EndFrameDecode(PRUint32 aFrameNum, PRUint32 aTimeout NS_IMETHODIMP imgContainer::DecodingComplete(void) { mDoneDecoding = PR_TRUE; + + PRUint32 numFrames; + mFrames.Count(&numFrames); + if (numFrames == 1) { + nsCOMPtr currentFrame; + GetFrameAt(0, getter_AddRefs(currentFrame)); + currentFrame->SetMutable(PR_FALSE); + } return NS_OK; } @@ -568,7 +583,7 @@ NS_IMETHODIMP imgContainer::OnDataAvailable(imgIRequest *aRequest, nsISupports * aFrame->DrawTo(mCompositingFrame, x, aRect->y, aRect->width, aRect->height); BuildCompositeMask(mCompositingFrame, aFrame); } - return NS_OK; + return NS_OK; } //******************************************************************************