Bug 1184996 (Part 3) - Replace all remaining references to 'size decodes' with 'metadata decodes'. r=tn

This commit is contained in:
Seth Fowler 2015-07-22 22:39:54 -07:00
parent 23308ca239
commit ff2b61cc0f
14 changed files with 62 additions and 64 deletions

View File

@ -203,8 +203,8 @@ public:
return;
}
if (aDecoder->IsSizeDecode()) {
mSizeDecodeQueue.AppendElement(Move(decoder));
if (aDecoder->IsMetadataDecode()) {
mMetadataDecodeQueue.AppendElement(Move(decoder));
} else {
mFullDecodeQueue.AppendElement(Move(decoder));
}
@ -218,9 +218,9 @@ public:
MonitorAutoLock lock(mMonitor);
do {
// Prioritize size decodes over full decodes.
if (!mSizeDecodeQueue.IsEmpty()) {
return PopWorkFromQueue(mSizeDecodeQueue);
// Prioritize metadata decodes over full decodes.
if (!mMetadataDecodeQueue.IsEmpty()) {
return PopWorkFromQueue(mMetadataDecodeQueue);
}
if (!mFullDecodeQueue.IsEmpty()) {
@ -253,9 +253,9 @@ private:
nsThreadPoolNaming mThreadNaming;
// mMonitor guards mQueue and mShuttingDown.
// mMonitor guards the queues and mShuttingDown.
Monitor mMonitor;
nsTArray<nsRefPtr<Decoder>> mSizeDecodeQueue;
nsTArray<nsRefPtr<Decoder>> mMetadataDecodeQueue;
nsTArray<nsRefPtr<Decoder>> mFullDecodeQueue;
bool mShuttingDown;
};

View File

@ -42,7 +42,7 @@ Decoder::Decoder(RasterImage* aImage)
, mFrameCount(0)
, mFailCode(NS_OK)
, mInitialized(false)
, mSizeDecode(false)
, mMetadataDecode(false)
, mInFrame(false)
, mIsAnimated(false)
{ }
@ -169,7 +169,7 @@ Decoder::Write(const char* aBuffer, uint32_t aCount)
return;
}
if (IsSizeDecode() && HasSize()) {
if (IsMetadataDecode() && HasSize()) {
// More data came in since we found the size. We have nothing to do here.
return;
}
@ -200,7 +200,7 @@ Decoder::CompleteDecode()
// early because of low-memory conditions or losing a race with another
// decoder, we need to send teardown notifications (and report an error to the
// console later).
if (!IsSizeDecode() && !mDecodeDone && !WasAborted()) {
if (!IsMetadataDecode() && !mDecodeDone && !WasAborted()) {
mShouldReportError = true;
// If we only have a data error, we're usable if we have at least one
@ -218,7 +218,7 @@ Decoder::CompleteDecode()
PostDecodeDone();
} else {
// We're not usable. Record some final progress indicating the error.
if (!IsSizeDecode()) {
if (!IsMetadataDecode()) {
mProgress |= FLAG_DECODE_COMPLETE;
}
mProgress |= FLAG_HAS_ERROR;
@ -269,7 +269,7 @@ Decoder::Finish()
SetSizeOnImage();
}
if (mDecodeDone && !IsSizeDecode()) {
if (mDecodeDone && !IsMetadataDecode()) {
MOZ_ASSERT(HasError() || mCurrentFrame, "Should have an error or a frame");
// If this image wasn't animated and isn't a transient image, mark its frame
@ -478,7 +478,7 @@ Decoder::PostFrameStop(Opacity aFrameOpacity /* = Opacity::TRANSPARENT */,
BlendMethod aBlendMethod /* = BlendMethod::OVER */)
{
// We should be mid-frame
MOZ_ASSERT(!IsSizeDecode(), "Stopping frame during a size decode");
MOZ_ASSERT(!IsMetadataDecode(), "Stopping frame during metadata decode");
MOZ_ASSERT(mInFrame, "Stopping frame when we didn't start one");
MOZ_ASSERT(mCurrentFrame, "Stopping frame when we don't have one");
@ -517,7 +517,7 @@ Decoder::PostInvalidation(const nsIntRect& aRect,
void
Decoder::PostDecodeDone(int32_t aLoopCount /* = 0 */)
{
MOZ_ASSERT(!IsSizeDecode(), "Can't be done with decoding with size decode!");
MOZ_ASSERT(!IsMetadataDecode(), "Done with decoding in metadata decode");
MOZ_ASSERT(!mInFrame, "Can't be done decoding if we're mid-frame!");
MOZ_ASSERT(!mDecodeDone, "Decode already done!");
mDecodeDone = true;

View File

@ -97,15 +97,17 @@ public:
* State.
*/
// If we're doing a "size decode", we more or less pass through the image
// data, stopping only to scoop out the image dimensions. A size decode
// must be enabled by SetSizeDecode() _before_calling Init().
bool IsSizeDecode() { return mSizeDecode; }
void SetSizeDecode(bool aSizeDecode)
/**
* If we're doing a metadata decode, we only decode the image's headers, which
* is enough to determine the image's intrinsic size. A metadata decode is
* enabled by calling SetMetadataDecode() *before* calling Init().
*/
void SetMetadataDecode(bool aMetadataDecode)
{
MOZ_ASSERT(!mInitialized, "Shouldn't be initialized yet");
mSizeDecode = aSizeDecode;
mMetadataDecode = aMetadataDecode;
}
bool IsMetadataDecode() { return mMetadataDecode; }
/**
* If this decoder supports downscale-during-decode, sets the target size that
@ -209,7 +211,8 @@ public:
bool GetDecodeDone() const
{
return mDecodeDone || (mSizeDecode && HasSize()) || HasError() || mDataDone;
return mDecodeDone || (mMetadataDecode && HasSize()) ||
HasError() || mDataDone;
}
/**
@ -423,7 +426,7 @@ private:
nsresult mFailCode;
bool mInitialized;
bool mSizeDecode;
bool mMetadataDecode;
bool mInFrame;
bool mIsAnimated;
};

View File

@ -122,7 +122,7 @@ DecoderFactory::CreateDecoder(DecoderType aType,
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetSizeDecode(false);
decoder->SetMetadataDecode(false);
decoder->SetIterator(aSourceBuffer->Iterator());
decoder->SetFlags(aFlags);
decoder->SetSendPartialInvalidations(!aIsRedecode);
@ -162,7 +162,7 @@ DecoderFactory::CreateMetadataDecoder(DecoderType aType,
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetSizeDecode(true);
decoder->SetMetadataDecode(true);
decoder->SetIterator(aSourceBuffer->Iterator());
decoder->Init();

View File

@ -78,10 +78,6 @@ public:
* the image. No actual image data will be decoded and no surfaces will be
* allocated. The decoder will send notifications to @aImage.
*
* XXX(seth): A metadata decode is called a "size decode" in most of ImageLib,
* but we are going to move away from that term, as it's both confusing to
* people and increasingly inaccurate.
*
* @param aType Which type of decoder to create - JPEG, PNG, etc.
* @param aImage The image will own the decoder and which should receive
* notifications as decoding progresses.

View File

@ -2018,17 +2018,17 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder)
aDecoder->TakeInvalidRect(),
aDecoder->GetDecodeFlags());
bool wasSize = aDecoder->IsSizeDecode();
bool wasMetadata = aDecoder->IsMetadataDecode();
bool done = aDecoder->GetDecodeDone();
if (!wasSize && aDecoder->ChunkCount()) {
if (!wasMetadata && aDecoder->ChunkCount()) {
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_CHUNKS,
aDecoder->ChunkCount());
}
if (done) {
// Do some telemetry if this isn't a size decode.
if (!wasSize) {
// Do some telemetry if this isn't a metadata decode.
if (!wasMetadata) {
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
int32_t(aDecoder->DecodeTime().ToMicroseconds()));
@ -2045,12 +2045,12 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder)
// Detect errors.
if (aDecoder->HasError() && !aDecoder->WasAborted()) {
DoError();
} else if (wasSize && !mHasSize) {
} else if (wasMetadata && !mHasSize) {
DoError();
}
// If we were waiting to fire the load event, go ahead and fire it now.
if (mLoadProgress && wasSize) {
if (mLoadProgress && wasMetadata) {
NotifyForLoadEvent(*mLoadProgress);
mLoadProgress = Nothing();
NotifyProgress(FLAG_ONLOAD_UNBLOCKED);
@ -2062,8 +2062,8 @@ RasterImage::FinalizeDecoder(Decoder* aDecoder)
UnlockImage();
}
// If we were a size decode and a full decode was requested, now's the time.
if (done && wasSize && mWantFullDecode) {
// If we were a metadata decode and a full decode was requested, do it.
if (done && wasMetadata && mWantFullDecode) {
mWantFullDecode = false;
RequestDecode();
}

View File

@ -430,8 +430,8 @@ private: // data
// of frames, or no more owning request
bool mAnimationFinished:1;
// Whether, once we are done doing a size decode, we should immediately kick
// off a full decode.
// Whether, once we are done doing a metadata decode, we should immediately
// kick off a full decode.
bool mWantFullDecode:1;
TimeStamp mDrawStartTime;

View File

@ -141,7 +141,7 @@ nsBMPDecoder::FinishInternal()
MOZ_ASSERT(GetFrameCount() <= 1, "Multiple BMP frames?");
// Send notifications if appropriate
if (!IsSizeDecode() && HasSize()) {
if (!IsMetadataDecode() && HasSize()) {
// Invalidate
nsIntRect r(0, 0, mBIH.width, GetHeight());
@ -369,9 +369,8 @@ nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
return;
}
// We have the size. If we're doing a size decode, we got what
// we came for.
if (IsSizeDecode()) {
// We have the size. If we're doing a metadata decode, we're done.
if (IsMetadataDecode()) {
return;
}

View File

@ -103,7 +103,7 @@ nsGIFDecoder2::FinishInternal()
MOZ_ASSERT(!HasError(), "Shouldn't call FinishInternal after error!");
// If the GIF got cut off, handle it anyway
if (!IsSizeDecode() && mGIFOpen) {
if (!IsMetadataDecode() && mGIFOpen) {
if (mCurrentFrameIndex == mGIFStruct.images_decoded) {
EndImageFrame();
}
@ -689,7 +689,7 @@ nsGIFDecoder2::WriteInternal(const char* aBuffer, uint32_t aCount)
mGIFStruct.screen_height = GETINT16(q + 2);
mGIFStruct.global_colormap_depth = (q[4]&0x07) + 1;
if (IsSizeDecode()) {
if (IsMetadataDecode()) {
MOZ_ASSERT(!mGIFOpen, "Gif should not be open at this point");
PostSize(mGIFStruct.screen_width, mGIFStruct.screen_height);
return;
@ -934,8 +934,8 @@ nsGIFDecoder2::WriteInternal(const char* aBuffer, uint32_t aCount)
return;
}
// If we were doing a size decode, we're done
if (IsSizeDecode()) {
// If we were doing a metadata decode, we're done.
if (IsMetadataDecode()) {
return;
}
}
@ -1095,7 +1095,8 @@ nsGIFDecoder2::WriteInternal(const char* aBuffer, uint32_t aCount)
break;
case gif_done:
MOZ_ASSERT(!IsSizeDecode(), "Size decodes shouldn't reach gif_done");
MOZ_ASSERT(!IsMetadataDecode(),
"Metadata decodes shouldn't reach gif_done");
FinishInternal();
goto done;

View File

@ -358,7 +358,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
PNGSIGNATURESIZE);
if (mIsPNG) {
mContainedDecoder = new nsPNGDecoder(mImage);
mContainedDecoder->SetSizeDecode(IsSizeDecode());
mContainedDecoder->SetMetadataDecode(IsMetadataDecode());
mContainedDecoder->SetSendPartialInvalidations(mSendPartialInvalidations);
mContainedDecoder->Init();
if (!WriteToContainedDecoder(mSignature, PNGSIGNATURESIZE)) {
@ -384,7 +384,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
// Raymond Chen says that 32bpp only are valid PNG ICOs
// http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
if (!IsSizeDecode() &&
if (!IsMetadataDecode() &&
!static_cast<nsPNGDecoder*>(mContainedDecoder.get())->IsValidICO()) {
PostDataError();
}
@ -435,7 +435,7 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
nsBMPDecoder* bmpDecoder = new nsBMPDecoder(mImage);
mContainedDecoder = bmpDecoder;
bmpDecoder->SetUseAlphaData(true);
mContainedDecoder->SetSizeDecode(IsSizeDecode());
mContainedDecoder->SetMetadataDecode(IsMetadataDecode());
mContainedDecoder->SetSendPartialInvalidations(mSendPartialInvalidations);
mContainedDecoder->Init();
@ -475,9 +475,8 @@ nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
PostSize(mContainedDecoder->GetImageMetadata().GetWidth(),
mContainedDecoder->GetImageMetadata().GetHeight());
// We have the size. If we're doing a size decode, we got what
// we came for.
if (IsSizeDecode()) {
// We have the size. If we're doing a metadata decode, we're done.
if (IsMetadataDecode()) {
return;
}

View File

@ -67,8 +67,8 @@ nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
return;
}
// If We're doing a size decode, we're done
if (IsSizeDecode()) {
// If we're doing a metadata decode, we're done.
if (IsMetadataDecode()) {
mState = iconStateFinished;
break;
}

View File

@ -195,7 +195,7 @@ nsJPEGDecoder::FinishInternal()
// If we're not in any sort of error case, force our state to JPEG_DONE.
if ((mState != JPEG_DONE && mState != JPEG_SINK_NON_JPEG_TRAILER) &&
(mState != JPEG_ERROR) &&
!IsSizeDecode()) {
!IsMetadataDecode()) {
mState = JPEG_DONE;
}
}
@ -266,8 +266,8 @@ nsJPEGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
return;
}
// If we're doing a size decode, we're done.
if (IsSizeDecode()) {
// If we're doing a metadata decode, we're done.
if (IsMetadataDecode()) {
return;
}

View File

@ -47,7 +47,7 @@ GetPNGDecoderAccountingLog()
# define MOZ_PNG_MAX_DIMENSION 32767
#endif
// For size decodes
// For metadata decodes.
#define WIDTH_OFFSET 16
#define HEIGHT_OFFSET (WIDTH_OFFSET + 4)
#define BYTES_NEEDED_FOR_DIMENSIONS (HEIGHT_OFFSET + 4)
@ -226,8 +226,8 @@ nsPNGDecoder::EndImageFrame()
void
nsPNGDecoder::InitInternal()
{
// For size decodes, we don't need to initialize the png decoder
if (IsSizeDecode()) {
// For metadata decodes, we don't need to initialize the PNG decoder.
if (IsMetadataDecode()) {
return;
}
@ -321,8 +321,8 @@ nsPNGDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
{
MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
// If we only want width/height, we don't need to go through libpng
if (IsSizeDecode()) {
// If we only want width/height, we don't need to go through libpng.
if (IsMetadataDecode()) {
// Are we done?
if (mHeaderBytesRead == BYTES_NEEDED_FOR_DIMENSIONS) {

View File

@ -78,7 +78,7 @@ public:
gfx::SurfaceFormat format;
// For size decodes
// For metadata decodes.
uint8_t mSizeBytes[8]; // Space for width and height, both 4 bytes
uint32_t mHeaderBytesRead;