Bug 590252 - part 1 - Add framework to Decoder superclass to handle invalidations.r=joe,a=blocker

This commit is contained in:
Bobby Holley 2010-08-24 16:40:45 -04:00
parent d0989f8f70
commit 6cc5f55cb2
3 changed files with 51 additions and 4 deletions

View File

@ -92,6 +92,26 @@ Decoder::Finish()
return FinishInternal();
}
void
Decoder::FlushInvalidations()
{
// If we've got an empty invalidation rect, we have nothing to do
if (mInvalidRect.IsEmpty())
return;
// Tell the image that it's been updated
mImage->FrameUpdated(mFrameCount - 1, mInvalidRect);
// Fire OnDataAvailable
if (mObserver) {
PRBool isCurrentFrame = mImage->GetCurrentFrameIndex() == (mFrameCount - 1);
mObserver->OnDataAvailable(nsnull, isCurrentFrame, &mInvalidRect);
}
// Clear the invalidation rectangle
mInvalidRect.Empty();
}
/*
* Hook stubs. Override these as necessary in decoder implementations.
*/
@ -125,6 +145,11 @@ Decoder::PostFrameStart()
// We shouldn't already be mid-frame
NS_ABORT_IF_FALSE(!mInFrame, "Starting new frame but not done with old one!");
// We should take care of any invalidation region when wrapping up the
// previous frame
NS_ABORT_IF_FALSE(mInvalidRect.IsEmpty(),
"Start image frame with non-empty invalidation region!");
// Update our state to reflect the new frame
mFrameCount++;
mInFrame = true;
@ -154,5 +179,18 @@ Decoder::PostFrameStop()
mObserver->OnStopFrame(nsnull, mFrameCount - 1); // frame # is zero-indexed
}
void
Decoder::PostInvalidation(nsIntRect& aRect)
{
// We should be mid-frame
NS_ABORT_IF_FALSE(mInFrame, "Can't invalidate when not mid-frame!");
// Account for the new region
mInvalidRect.UnionRect(mInvalidRect, aRect);
// For now, just flush invalidations immediately. We'll stop doing this soon.
FlushInvalidations();
}
} // namespace imagelib
} // namespace mozilla

View File

@ -86,6 +86,11 @@ public:
*/
nsresult Finish();
/**
* Tells the decoder to flush any pending invalidations.
*/
void FlushInvalidations();
// We're not COM-y, so we don't get refcounts by default
NS_INLINE_DECL_REFCOUNTING(Decoder)
@ -130,6 +135,9 @@ protected:
void PostFrameStart();
void PostFrameStop();
// Called by the decoders when they have a region to invalidate. We may not
// actually pass these invalidations on right away.
void PostInvalidation(nsIntRect& aRect);
/*
* Member variables.
@ -141,6 +149,8 @@ protected:
PRUint32 mFrameCount; // Number of frames, including anything in-progress
nsIntRect mInvalidRect; // Tracks an invalidation region in the current frame.
bool mInitialized;
bool mSizeDecode;
bool mInFrame;

View File

@ -930,16 +930,15 @@ RasterImage::EnsureCleanFrame(PRUint32 aFrameNum, PRInt32 aX, PRInt32 aY,
nsresult
RasterImage::FrameUpdated(PRUint32 aFrameNum, nsIntRect &aUpdatedRect)
{
NS_ASSERTION(aFrameNum < mFrames.Length(), "Invalid frame index!");
if (aFrameNum >= mFrames.Length())
return NS_ERROR_INVALID_ARG;
NS_ABORT_IF_FALSE(aFrameNum < mFrames.Length(), "Invalid frame index!");
imgFrame *frame = GetImgFrame(aFrameNum);
NS_ABORT_IF_FALSE(frame, "Calling FrameUpdated on frame that doesn't exist!");
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
frame->ImageUpdated(aUpdatedRect);
// XXXbholley - this should turn into a void method as soon the decoders
// stop using it
return NS_OK;
}