Bug 1187386 (Part 7) - Eliminate remaining dependencies on a non-null mImage in Decoder. r=tn

This commit is contained in:
Seth Fowler 2015-07-31 07:29:18 -07:00
parent 5b920b75e5
commit d7d368b6c9
2 changed files with 31 additions and 22 deletions

View File

@ -49,9 +49,9 @@ Decoder::Decoder(RasterImage* aImage)
Decoder::~Decoder()
{
MOZ_ASSERT(mProgress == NoProgress,
MOZ_ASSERT(mProgress == NoProgress || !mImage,
"Destroying Decoder without taking all its progress changes");
MOZ_ASSERT(mInvalidRect.IsEmpty(),
MOZ_ASSERT(mInvalidRect.IsEmpty() || !mImage,
"Destroying Decoder without taking all its invalidations");
mInitialized = false;
@ -288,7 +288,8 @@ Decoder::AllocateFrameInternal(uint32_t aFrameNum,
}
const uint32_t bytesPerPixel = aPaletteDepth == 0 ? 4 : 1;
if (!SurfaceCache::CanHold(aFrameRect.Size(), bytesPerPixel)) {
if (ShouldUseSurfaceCache() &&
!SurfaceCache::CanHold(aFrameRect.Size(), bytesPerPixel)) {
NS_WARNING("Trying to add frame that's too large for the SurfaceCache");
return RawAccessFrameRef();
}
@ -308,24 +309,26 @@ Decoder::AllocateFrameInternal(uint32_t aFrameNum,
return RawAccessFrameRef();
}
InsertOutcome outcome =
SurfaceCache::Insert(frame, ImageKey(mImage.get()),
RasterSurfaceKey(aTargetSize,
aDecodeFlags,
aFrameNum),
Lifetime::Persistent);
if (outcome == InsertOutcome::FAILURE) {
// We couldn't insert the surface, almost certainly due to low memory. We
// treat this as a permanent error to help the system recover; otherwise, we
// might just end up attempting to decode this image again immediately.
ref->Abort();
return RawAccessFrameRef();
} else if (outcome == InsertOutcome::FAILURE_ALREADY_PRESENT) {
// Another decoder beat us to decoding this frame. We abort this decoder
// rather than treat this as a real error.
mDecodeAborted = true;
ref->Abort();
return RawAccessFrameRef();
if (ShouldUseSurfaceCache()) {
InsertOutcome outcome =
SurfaceCache::Insert(frame, ImageKey(mImage.get()),
RasterSurfaceKey(aTargetSize,
aDecodeFlags,
aFrameNum),
Lifetime::Persistent);
if (outcome == InsertOutcome::FAILURE) {
// We couldn't insert the surface, almost certainly due to low memory. We
// treat this as a permanent error to help the system recover; otherwise,
// we might just end up attempting to decode this image again immediately.
ref->Abort();
return RawAccessFrameRef();
} else if (outcome == InsertOutcome::FAILURE_ALREADY_PRESENT) {
// Another decoder beat us to decoding this frame. We abort this decoder
// rather than treat this as a real error.
mDecodeAborted = true;
ref->Abort();
return RawAccessFrameRef();
}
}
nsIntRect refreshArea;
@ -354,7 +357,10 @@ Decoder::AllocateFrameInternal(uint32_t aFrameNum,
}
mFrameCount++;
mImage->OnAddedFrame(mFrameCount, refreshArea);
if (mImage) {
mImage->OnAddedFrame(mFrameCount, refreshArea);
}
return ref;
}

View File

@ -237,6 +237,9 @@ public:
/// Are we in the middle of a frame right now? Used for assertions only.
bool InFrame() const { return mInFrame; }
/// Should we store surfaces created by this decoder in the SurfaceCache?
bool ShouldUseSurfaceCache() const { return bool(mImage); }
/**
* Returns true if this decoder was aborted.
*