Bug 958758. Refactor common image discard checks into one place. r=seth

This commit is contained in:
Timothy Nikkel 2014-01-21 17:19:22 -06:00
Родитель e1d75aac97
Коммит 9004dc4dcd
2 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@ -1195,7 +1195,7 @@ RasterImage::ApplyDecodeFlags(uint32_t aNewFlags)
// decode.
if (!(aNewFlags & FLAG_SYNC_DECODE))
return false;
if (!CanForciblyDiscard() || mDecoder || mAnim)
if (!CanForciblyDiscardAndRedecode())
return false;
ForceDiscard();
}
@ -1938,6 +1938,14 @@ RasterImage::CanForciblyDiscard() {
mHasSourceData; // ...have the source data...
}
bool
RasterImage::CanForciblyDiscardAndRedecode() {
return mDiscardable && // ...Enabled at creation time...
mHasSourceData && // ...have the source data...
!mDecoder && // Can't discard with an open decoder
!mAnim; // Can never discard animated images
}
// Helper method to tell us whether the clock is currently running for
// discarding this image. Mainly for assertions.
bool
@ -2379,7 +2387,7 @@ RasterImage::SyncDecode()
// If we've finished decoding we need to discard so we can re-decode
// with the new flags. If we can't discard then there isn't
// anything we can do.
if (!CanForciblyDiscard() || mDecoder || mAnim)
if (!CanForciblyDiscardAndRedecode())
return NS_ERROR_NOT_AVAILABLE;
ForceDiscard();
}
@ -2611,7 +2619,7 @@ RasterImage::Draw(gfxContext *aContext,
// We can only draw with the default decode flags
if (mFrameDecodeFlags != DECODE_FLAGS_DEFAULT) {
if (!CanForciblyDiscard() || mDecoder || mAnim)
if (!CanForciblyDiscardAndRedecode())
return NS_ERROR_NOT_AVAILABLE;
ForceDiscard();
@ -2734,7 +2742,7 @@ RasterImage::UnlockImage()
NS_IMETHODIMP
RasterImage::RequestDiscard()
{
if (CanDiscard() && !mDecoder && !mAnim) {
if (CanDiscard() && CanForciblyDiscardAndRedecode()) {
ForceDiscard();
}

Просмотреть файл

@ -762,6 +762,7 @@ private: // data
// Helpers
bool CanDiscard();
bool CanForciblyDiscard();
bool CanForciblyDiscardAndRedecode();
bool DiscardingActive();
bool StoringSourceData() const;