зеркало из https://github.com/mozilla/pjs.git
bug 513681 - part 15 - Coalesce OnStartFrame/OnStopFrame into superclass.r=joe,a=blocker
This commit is contained in:
Родитель
486c767cb4
Коммит
1fb3382df1
|
@ -98,11 +98,14 @@ nsBMPDecoder::ShutdownInternal(PRUint32 aFlags)
|
|||
{
|
||||
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)) {
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, 0);
|
||||
!mError && !(aFlags & CLOSE_FLAG_DONTNOTIFY) &&
|
||||
(GetFrameCount() == 1)) {
|
||||
PostFrameStop();
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
mObserver->OnStopContainer(nsnull, mImage);
|
||||
|
@ -280,10 +283,8 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
memset(mImageData, 0, imageLength);
|
||||
}
|
||||
|
||||
if (mObserver) {
|
||||
mObserver->OnStartFrame(nsnull, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
}
|
||||
PRUint8 bpc; // bytes per color
|
||||
bpc = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4; // OS/2 Bitmaps have no padding byte
|
||||
|
|
|
@ -332,8 +332,8 @@ nsresult nsGIFDecoder2::BeginImageFrame(gfx_depth aDepth)
|
|||
mImage->SetFrameDisposalMethod(mGIFStruct.images_decoded,
|
||||
mGIFStruct.disposal_method);
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(nsnull, mGIFStruct.images_decoded);
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
|
||||
mCurrentFrame = mGIFStruct.images_decoded;
|
||||
return NS_OK;
|
||||
|
@ -370,8 +370,6 @@ void nsGIFDecoder2::EndImageFrame()
|
|||
mCurrentRow = mLastFlushedRow = -1;
|
||||
mCurrentPass = mLastFlushedPass = 0;
|
||||
|
||||
PRUint32 curframe = mGIFStruct.images_decoded;
|
||||
|
||||
// Only add frame if we have any rows at all
|
||||
if (mGIFStruct.rows_remaining != mGIFStruct.height) {
|
||||
if (mGIFStruct.rows_remaining && mGIFStruct.images_decoded) {
|
||||
|
@ -394,8 +392,8 @@ void nsGIFDecoder2::EndImageFrame()
|
|||
// even if some of them weren't decoded properly and thus are blank.
|
||||
mGIFStruct.images_decoded++;
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, curframe);
|
||||
// Tell the superclass we finished a frame
|
||||
PostFrameStop();
|
||||
|
||||
// Reset the transparent pixel
|
||||
if (mOldColor) {
|
||||
|
|
|
@ -101,9 +101,13 @@ 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)) {
|
||||
!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);
|
||||
|
@ -111,8 +115,8 @@ nsICODecoder::ShutdownInternal(PRUint32 aFlags)
|
|||
|
||||
if (mObserver) {
|
||||
mObserver->OnDataAvailable(nsnull, PR_TRUE, &r);
|
||||
mObserver->OnStopFrame(nsnull, 0);
|
||||
}
|
||||
PostFrameStop();
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
mObserver->OnStopContainer(nsnull, 0);
|
||||
|
@ -289,10 +293,8 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
|
|||
gfxASurface::ImageFormatARGB32, (PRUint8**)&mImageData, &imageLength);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (mObserver) {
|
||||
mObserver->OnStartFrame(nsnull, 0);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
}
|
||||
|
||||
if (mColors && (mPos >= mImageOffset + BITMAPINFOSIZE) &&
|
||||
|
|
|
@ -138,8 +138,9 @@ nsIconDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
|||
mState = iconStateError;
|
||||
return rv;
|
||||
}
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(nsnull, 0);
|
||||
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
|
||||
// Book Keeping
|
||||
aBuffer++;
|
||||
|
@ -199,8 +200,7 @@ nsIconDecoder::NotifyDone(PRBool aSuccess)
|
|||
NS_ABORT_IF_FALSE(!mNotifiedDone, "Calling NotifyDone twice");
|
||||
|
||||
// Notify
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, 0);
|
||||
PostFrameStop();
|
||||
if (aSuccess)
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
|
|
|
@ -402,8 +402,9 @@ nsJPEGDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
|
|||
(" JPEGDecoderAccounting: nsJPEGDecoder::Write -- created image frame with %ux%u pixels",
|
||||
mInfo.image_width, mInfo.image_height));
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(nsnull, 0);
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
|
||||
mState = JPEG_START_DECOMPRESS;
|
||||
}
|
||||
|
||||
|
@ -574,8 +575,7 @@ nsJPEGDecoder::NotifyDone(PRBool aSuccess)
|
|||
NS_ABORT_IF_FALSE(!mNotifiedDone, "calling NotifyDone twice!");
|
||||
|
||||
// Notify
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, 0);
|
||||
PostFrameStop();
|
||||
if (aSuccess)
|
||||
mImage->DecodingComplete();
|
||||
if (mObserver) {
|
||||
|
|
|
@ -129,8 +129,8 @@ void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
|||
SetAnimFrameInfo();
|
||||
#endif
|
||||
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(nsnull, mImage->GetNumFrames() - 1);
|
||||
// Tell the superclass we're starting a frame
|
||||
PostFrameStart();
|
||||
|
||||
PR_LOG(gPNGDecoderAccountingLog, PR_LOG_DEBUG,
|
||||
("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created "
|
||||
|
@ -214,8 +214,7 @@ void nsPNGDecoder::EndImageFrame()
|
|||
#endif
|
||||
|
||||
mImage->EndFrameDecode(numFrames - 1);
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, numFrames - 1);
|
||||
PostFrameStop();
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -69,8 +69,10 @@ NS_IMETHODIMP Decoder::Flush()
|
|||
}
|
||||
|
||||
Decoder::Decoder()
|
||||
: mInitialized(false)
|
||||
: mFrameCount(0)
|
||||
, mInitialized(false)
|
||||
, mSizeDecode(false)
|
||||
, mInFrame(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -124,6 +126,7 @@ Decoder::Shutdown(PRUint32 aFlags)
|
|||
mImage = nsnull;
|
||||
mObserver = nsnull;
|
||||
|
||||
NS_ABORT_IF_FALSE(!mInFrame, "Shutting down mid-frame!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -155,5 +158,40 @@ Decoder::PostSize(PRInt32 aWidth, PRInt32 aHeight)
|
|||
mObserver->OnStartContainer(nsnull, mImage);
|
||||
}
|
||||
|
||||
void
|
||||
Decoder::PostFrameStart()
|
||||
{
|
||||
// We shouldn't already be mid-frame
|
||||
NS_ABORT_IF_FALSE(!mInFrame, "Starting new frame but not done with old one!");
|
||||
|
||||
// Update our state to reflect the new frame
|
||||
mFrameCount++;
|
||||
mInFrame = true;
|
||||
|
||||
// Decoder implementations should only call this method if they successfully
|
||||
// appended the frame to the image. So mFrameCount should always match that
|
||||
// reported by the Image.
|
||||
NS_ABORT_IF_FALSE(mFrameCount == mImage->GetNumFrames(),
|
||||
"Decoder frame count doesn't match image's!");
|
||||
|
||||
// Fire notification
|
||||
if (mObserver)
|
||||
mObserver->OnStartFrame(nsnull, mFrameCount - 1); // frame # is zero-indexed
|
||||
}
|
||||
|
||||
void
|
||||
Decoder::PostFrameStop()
|
||||
{
|
||||
// We should be mid-frame
|
||||
NS_ABORT_IF_FALSE(mInFrame, "Stopping frame when we didn't start one!");
|
||||
|
||||
// Update our state
|
||||
mInFrame = false;
|
||||
|
||||
// Fire notification
|
||||
if (mObserver)
|
||||
mObserver->OnStopFrame(nsnull, mFrameCount - 1); // frame # is zero-indexed
|
||||
}
|
||||
|
||||
} // namespace imagelib
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -121,6 +121,10 @@ public:
|
|||
mSizeDecode = aSizeDecode;
|
||||
}
|
||||
|
||||
// The number of frames we have, including anything in-progress. Thus, this
|
||||
// is only 0 if we haven't begun any frames.
|
||||
PRUint32 GetFrameCount() { return mFrameCount; }
|
||||
|
||||
protected:
|
||||
|
||||
/*
|
||||
|
@ -140,6 +144,11 @@ protected:
|
|||
// the image of its size and sends notifications.
|
||||
void PostSize(PRInt32 aWidth, PRInt32 aHeight);
|
||||
|
||||
// Called by decoders when they begin/end a frame. Informs the image, sends
|
||||
// notifications, and does internal book-keeping.
|
||||
void PostFrameStart();
|
||||
void PostFrameStop();
|
||||
|
||||
|
||||
/*
|
||||
* Member variables.
|
||||
|
@ -149,8 +158,11 @@ protected:
|
|||
nsRefPtr<RasterImage> mImage;
|
||||
nsCOMPtr<imgIDecoderObserver> mObserver;
|
||||
|
||||
PRUint32 mFrameCount; // Number of frames, including anything in-progress
|
||||
|
||||
bool mInitialized;
|
||||
bool mSizeDecode;
|
||||
bool mInFrame;
|
||||
};
|
||||
|
||||
} // namespace imagelib
|
||||
|
|
Загрузка…
Ссылка в новой задаче