зеркало из https://github.com/mozilla/pjs.git
Bug 513681 - part 16 - Move end-of-decode logic into Finish() and cleanup into destructor, abolishing Shutdown().r=joe,a=blocker
This commit is contained in:
Родитель
651bacc715
Коммит
94aab005de
|
@ -94,17 +94,13 @@ nsBMPDecoder::InitInternal()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsBMPDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
nsBMPDecoder::FinishInternal()
|
||||
{
|
||||
PR_LOG(gBMPLog, PR_LOG_DEBUG, ("nsBMPDecoder::Close()\n"));
|
||||
|
||||
// We should never make multiple frames
|
||||
NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple BMP frames?");
|
||||
|
||||
// Send notifications if appropriate
|
||||
if (!IsSizeDecode() &&
|
||||
!mError && !(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
(GetFrameCount() == 1)) {
|
||||
if (!IsSizeDecode() && !mError && (GetFrameCount() == 1)) {
|
||||
PostFrameStop();
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
|
|
|
@ -148,7 +148,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ nsGIFDecoder2::nsGIFDecoder2()
|
|||
|
||||
nsGIFDecoder2::~nsGIFDecoder2()
|
||||
{
|
||||
PR_FREEIF(mGIFStruct.local_colormap);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -143,18 +144,15 @@ nsGIFDecoder2::InitInternal()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsGIFDecoder2::ShutdownInternal(PRUint32 aFlags)
|
||||
nsGIFDecoder2::FinishInternal()
|
||||
{
|
||||
// Send notifications if appropriate
|
||||
if (!IsSizeDecode() &&
|
||||
!mError && !(aFlags & CLOSE_FLAG_DONTNOTIFY)) {
|
||||
if (!IsSizeDecode() && !mError) {
|
||||
if (mCurrentFrame == mGIFStruct.images_decoded)
|
||||
EndImageFrame();
|
||||
EndGIF(/* aSuccess = */ PR_TRUE);
|
||||
}
|
||||
|
||||
PR_FREEIF(mGIFStruct.local_colormap);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
private:
|
||||
/* These functions will be called when the decoder has a decoded row,
|
||||
|
|
|
@ -84,46 +84,6 @@ nsICODecoder::nsICODecoder()
|
|||
|
||||
nsICODecoder::~nsICODecoder()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsICODecoder::InitInternal()
|
||||
{
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!IsSizeDecode() && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsICODecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// We should never make multiple frames
|
||||
NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple ICO frames?");
|
||||
|
||||
// Send notifications if appropriate
|
||||
if (!IsSizeDecode() &&
|
||||
!mError && !(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
(GetFrameCount() == 1)) {
|
||||
// Tell the image that it's data has been updated
|
||||
nsIntRect r(0, 0, mDirEntry.mWidth, mDirEntry.mHeight);
|
||||
rv = mImage->FrameUpdated(0, r);
|
||||
|
||||
|
||||
if (mObserver) {
|
||||
mObserver->OnDataAvailable(nsnull, PR_TRUE, &r);
|
||||
}
|
||||
PostFrameStop();
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
mObserver->OnStopContainer(nsnull, 0);
|
||||
mObserver->OnStopDecode(nsnull, NS_OK, nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
mPos = 0;
|
||||
|
||||
delete[] mColors;
|
||||
|
@ -139,6 +99,43 @@ nsICODecoder::ShutdownInternal(PRUint32 aFlags)
|
|||
mRow = nsnull;
|
||||
}
|
||||
mDecodingAndMask = PR_FALSE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsICODecoder::InitInternal()
|
||||
{
|
||||
// Fire OnStartDecode at init time to support bug 512435
|
||||
if (!IsSizeDecode() && mObserver)
|
||||
mObserver->OnStartDecode(nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsICODecoder::FinishInternal()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// We should never make multiple frames
|
||||
NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple ICO frames?");
|
||||
|
||||
// Send notifications if appropriate
|
||||
if (!IsSizeDecode() && !mError && (GetFrameCount() == 1)) {
|
||||
// Tell the image that it's data has been updated
|
||||
nsIntRect r(0, 0, mDirEntry.mWidth, mDirEntry.mHeight);
|
||||
rv = mImage->FrameUpdated(0, r);
|
||||
|
||||
|
||||
if (mObserver) {
|
||||
mObserver->OnDataAvailable(nsnull, PR_TRUE, &r);
|
||||
}
|
||||
PostFrameStop();
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
mObserver->OnStopContainer(nsnull, 0);
|
||||
mObserver->OnStopDecode(nsnull, NS_OK, nsnull);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
private:
|
||||
// Private helper methods
|
||||
|
|
|
@ -77,13 +77,11 @@ nsIconDecoder::InitInternal()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsIconDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
nsIconDecoder::FinishInternal()
|
||||
{
|
||||
// If we haven't notified of completion yet for a full/success decode, we
|
||||
// didn't finish. Notify in error mode
|
||||
if (!(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
!IsSizeDecode() &&
|
||||
!mNotifiedDone)
|
||||
if (!IsSizeDecode() && !mNotifiedDone)
|
||||
NotifyDone(/* aSuccess = */ PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
PRUint8 mWidth;
|
||||
PRUint8 mHeight;
|
||||
|
|
|
@ -123,6 +123,10 @@ nsJPEGDecoder::nsJPEGDecoder()
|
|||
|
||||
nsJPEGDecoder::~nsJPEGDecoder()
|
||||
{
|
||||
// Step 8: Release JPEG decompression object
|
||||
mInfo.src = nsnull;
|
||||
jpeg_destroy_decompress(&mInfo);
|
||||
|
||||
PR_FREEIF(mBackBuffer);
|
||||
if (mTransform)
|
||||
qcms_transform_release(mTransform);
|
||||
|
@ -176,11 +180,8 @@ nsJPEGDecoder::InitInternal()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsJPEGDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
nsJPEGDecoder::FinishInternal()
|
||||
{
|
||||
PR_LOG(gJPEGlog, PR_LOG_DEBUG,
|
||||
("[this=%p] nsJPEGDecoder::Close\n", this));
|
||||
|
||||
/* If we're not in any sort of error case, flush the decoder.
|
||||
*
|
||||
* XXXbholley - It seems wrong that this should be necessary, but at the
|
||||
|
@ -189,15 +190,9 @@ nsJPEGDecoder::ShutdownInternal(PRUint32 aFlags)
|
|||
*/
|
||||
if ((mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER) &&
|
||||
(mState != JPEG_ERROR) &&
|
||||
!IsSizeDecode() &&
|
||||
!(aFlags & CLOSE_FLAG_DONTNOTIFY))
|
||||
!IsSizeDecode())
|
||||
this->Write(nsnull, 0);
|
||||
|
||||
/* Step 8: Release JPEG decompression object */
|
||||
mInfo.src = nsnull;
|
||||
|
||||
jpeg_destroy_decompress(&mInfo);
|
||||
|
||||
/* If we already know we're in an error state, don't
|
||||
bother flagging another one here. */
|
||||
if (mState == JPEG_ERROR)
|
||||
|
@ -205,9 +200,7 @@ nsJPEGDecoder::ShutdownInternal(PRUint32 aFlags)
|
|||
|
||||
/* If we're doing a full decode and haven't notified of completion yet,
|
||||
* we must not have got everything we wanted. Send error notifications. */
|
||||
if (!(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
!IsSizeDecode() &&
|
||||
!mNotifiedDone)
|
||||
if (!IsSizeDecode() && !mNotifiedDone)
|
||||
NotifyDone(/* aSuccess = */ PR_FALSE);
|
||||
|
||||
/* Otherwise, no problems. */
|
||||
|
|
|
@ -91,7 +91,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
void NotifyDone(PRBool aSuccess);
|
||||
|
||||
|
|
|
@ -93,6 +93,8 @@ nsPNGDecoder::nsPNGDecoder() :
|
|||
|
||||
nsPNGDecoder::~nsPNGDecoder()
|
||||
{
|
||||
if (mPNG)
|
||||
png_destroy_read_struct(&mPNG, mInfo ? &mInfo : NULL, NULL);
|
||||
if (mCMSLine)
|
||||
nsMemory::Free(mCMSLine);
|
||||
if (interlacebuf)
|
||||
|
@ -294,16 +296,12 @@ nsPNGDecoder::InitInternal()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsPNGDecoder::ShutdownInternal(PRUint32 aFlags)
|
||||
nsPNGDecoder::FinishInternal()
|
||||
{
|
||||
if (mPNG)
|
||||
png_destroy_read_struct(&mPNG, mInfo ? &mInfo : NULL, NULL);
|
||||
|
||||
// If we're a full/success decode but haven't sent stop notifications yet,
|
||||
// we didn't get all the data we needed. Send error notifications.
|
||||
if (!(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
!IsSizeDecode() &&
|
||||
!mNotifiedDone)
|
||||
if (!IsSizeDecode() && !mNotifiedDone)
|
||||
NotifyDone(/* aSuccess = */ PR_FALSE);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
virtual nsresult FinishInternal();
|
||||
|
||||
void CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
||||
PRInt32 width, PRInt32 height,
|
||||
|
|
|
@ -60,7 +60,8 @@ Decoder::Init(imgIContainer *aImage,
|
|||
NS_IMETHODIMP
|
||||
Decoder::Close(PRUint32 aFlags)
|
||||
{
|
||||
return Shutdown(aFlags);
|
||||
NS_ABORT_IF_FALSE(0, "Not reached!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP Decoder::Flush()
|
||||
|
@ -78,6 +79,7 @@ Decoder::Decoder()
|
|||
|
||||
Decoder::~Decoder()
|
||||
{
|
||||
NS_WARN_IF_FALSE(!mInFrame, "Shutting down decoder mid-frame!");
|
||||
mInitialized = false;
|
||||
}
|
||||
|
||||
|
@ -91,6 +93,9 @@ Decoder::Init(RasterImage* aImage, imgIDecoderObserver* aObserver)
|
|||
// We should always have an image
|
||||
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
|
||||
|
||||
// No re-initializing
|
||||
NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!");
|
||||
|
||||
// Save our paremeters
|
||||
mImage = aImage;
|
||||
mObserver = aObserver;
|
||||
|
@ -116,20 +121,6 @@ Decoder::Finish()
|
|||
return FinishInternal();
|
||||
}
|
||||
|
||||
nsresult
|
||||
Decoder::Shutdown(PRUint32 aFlags)
|
||||
{
|
||||
// Implementation-specific shutdown
|
||||
nsresult rv = ShutdownInternal(aFlags);
|
||||
|
||||
// Get rid of our strong references
|
||||
mImage = nsnull;
|
||||
mObserver = nsnull;
|
||||
|
||||
NS_ABORT_IF_FALSE(!mInFrame, "Shutting down mid-frame!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Hook stubs. Override these as necessary in decoder implementations.
|
||||
*/
|
||||
|
@ -137,7 +128,6 @@ Decoder::Shutdown(PRUint32 aFlags)
|
|||
nsresult Decoder::InitInternal() {return NS_OK; }
|
||||
nsresult Decoder::WriteInternal(const char* aBuffer, PRUint32 aCount) {return NS_OK; }
|
||||
nsresult Decoder::FinishInternal() {return NS_OK; }
|
||||
nsresult Decoder::ShutdownInternal(PRUint32 aFlags) {return NS_OK; }
|
||||
|
||||
/*
|
||||
* Progress Notifications
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
*/
|
||||
|
||||
/**
|
||||
* Initialize an image decoder.
|
||||
* Initialize an image decoder. Decoders may not be re-initialized.
|
||||
*
|
||||
* @param aContainer The image container to decode to.
|
||||
* @param aObserver The observer for decode notification events.
|
||||
|
@ -94,15 +94,6 @@ public:
|
|||
*/
|
||||
nsresult Finish();
|
||||
|
||||
/**
|
||||
* Shuts down the decoder.
|
||||
*
|
||||
* Notifications Sent: None
|
||||
*
|
||||
* XXX - These flags will go away later in the patch stack
|
||||
*/
|
||||
nsresult Shutdown(PRUint32 aFlags);
|
||||
|
||||
// We're not COM-y, so we don't get refcounts by default
|
||||
// XXX - This is uncommented in a later patch when we stop inheriting imgIDecoder
|
||||
// NS_INLINE_DECL_REFCOUNTING(Decoder)
|
||||
|
@ -134,7 +125,6 @@ protected:
|
|||
virtual nsresult InitInternal();
|
||||
virtual nsresult WriteInternal(const char* aBuffer, PRUint32 aCount);
|
||||
virtual nsresult FinishInternal();
|
||||
virtual nsresult ShutdownInternal(PRUint32 aFlags);
|
||||
|
||||
/*
|
||||
* Progress notifications.
|
||||
|
|
|
@ -2171,13 +2171,13 @@ RasterImage::ShutdownDecoder(eShutdownIntent aIntent)
|
|||
// Figure out what kind of decode we were doing before we get rid of our decoder
|
||||
bool wasSizeDecode = mDecoder->IsSizeDecode();
|
||||
|
||||
// Close the decoder with the appropriate flags
|
||||
mInDecoder = PR_TRUE;
|
||||
PRUint32 closeFlags = (aIntent == eShutdownIntent_Error)
|
||||
? (PRUint32) imgIDecoder::CLOSE_FLAG_DONTNOTIFY
|
||||
: 0;
|
||||
nsresult rv = mDecoder->Close(closeFlags);
|
||||
mInDecoder = PR_FALSE;
|
||||
// If we're not in error mode, finalize the decoder
|
||||
nsresult rv = NS_OK;
|
||||
if (aIntent != eShutdownIntent_Error) {
|
||||
mInDecoder = PR_TRUE;
|
||||
rv = mDecoder->Finish();
|
||||
mInDecoder = PR_FALSE;
|
||||
}
|
||||
|
||||
// null out the decoder, _then_ check for errors on the close (otherwise the
|
||||
// error routine might re-invoke ShutdownDecoder)
|
||||
|
|
Загрузка…
Ссылка в новой задаче