Bug 1462355 - Part 1c. Make individual image decoders to use updated Decoder/SurfacePipe methods.

Extend this change to nsWebPDecoder.cpp
This commit is contained in:
wolfbeast 2018-11-21 13:34:01 +01:00 committed by Roy Tam
commit 7937138cb0
6 changed files with 49 additions and 33 deletions

View file

@ -674,8 +674,7 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
}
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
FullOutputFrame(),
nsresult rv = AllocateFrame(OutputSize(), FullOutputFrame(),
mMayHaveTransparency ? SurfaceFormat::B8G8R8A8
: SurfaceFormat::B8G8R8X8);
if (NS_FAILED(rv)) {

View file

@ -187,6 +187,14 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,
// Make sure there's no animation if we're downscaling.
MOZ_ASSERT_IF(Size() != OutputSize(), !GetImageMetadata().HasAnimation());
AnimationParams animParams {
aFrameRect,
FrameTimeout::FromRawMilliseconds(mGIFStruct.delay_time),
uint32_t(mGIFStruct.images_decoded),
BlendMethod::OVER,
DisposalMethod(mGIFStruct.disposal_method)
};
SurfacePipeFlags pipeFlags = aIsInterlaced
? SurfacePipeFlags::DEINTERLACE
: SurfacePipeFlags();
@ -198,17 +206,18 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,
// The first frame is always decoded into an RGB surface.
pipe =
SurfacePipeFactory::CreateSurfacePipe(this, mGIFStruct.images_decoded,
Size(), OutputSize(),
aFrameRect, format, pipeFlags);
SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
aFrameRect, format,
Some(animParams), pipeFlags);
} else {
// This is an animation frame (and not the first). To minimize the memory
// usage of animations, the image data is stored in paletted form.
MOZ_ASSERT(Size() == OutputSize());
pipe =
SurfacePipeFactory::CreatePalettedSurfacePipe(this, mGIFStruct.images_decoded,
Size(), aFrameRect, format,
aDepth, pipeFlags);
SurfacePipeFactory::CreatePalettedSurfacePipe(this, Size(), aFrameRect,
format,
aDepth, Some(animParams),
pipeFlags);
}
mCurrentFrameIndex = mGIFStruct.images_decoded;
@ -249,9 +258,7 @@ nsGIFDecoder2::EndImageFrame()
mGIFStruct.images_decoded++;
// Tell the superclass we finished a frame
PostFrameStop(opacity,
DisposalMethod(mGIFStruct.disposal_method),
FrameTimeout::FromRawMilliseconds(mGIFStruct.delay_time));
PostFrameStop(opacity);
// Reset the transparent pixel
if (mOldColor) {

View file

@ -70,8 +70,9 @@ nsIconDecoder::ReadHeader(const char* aData)
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
Maybe<SurfacePipe> pipe =
SurfacePipeFactory::CreateSurfacePipe(this, 0, Size(), OutputSize(),
SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
FullFrame(), SurfaceFormat::B8G8R8A8,
/* aAnimParams */ Nothing(),
SurfacePipeFlags());
if (!pipe) {
return Transition::TerminateFailure();

View file

@ -388,8 +388,8 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength)
jpeg_has_multiple_scans(&mInfo);
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
FullOutputFrame(), SurfaceFormat::B8G8R8X8);
nsresult rv = AllocateFrame(OutputSize(), FullOutputFrame(),
SurfaceFormat::B8G8R8X8);
if (NS_FAILED(rv)) {
mState = JPEG_ERROR;
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,

View file

@ -208,6 +208,25 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
MOZ_ASSERT_IF(Size() != OutputSize(),
transparency != TransparencyType::eFrameRect);
Maybe<AnimationParams> animParams;
#ifdef PNG_APNG_SUPPORTED
if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) {
mAnimInfo = AnimFrameInfo(mPNG, mInfo);
if (mAnimInfo.mDispose == DisposalMethod::CLEAR) {
// We may have to display the background under this image during
// animation playback, so we regard it as transparent.
PostHasTransparency();
}
animParams.emplace(AnimationParams {
aFrameInfo.mFrameRect,
FrameTimeout::FromRawMilliseconds(mAnimInfo.mTimeout),
mNumFrames, mAnimInfo.mBlend, mAnimInfo.mDispose
});
}
#endif
// If this image is interlaced, we can display better quality intermediate
// results to the user by post processing them with ADAM7InterpolatingFilter.
SurfacePipeFlags pipeFlags = aFrameInfo.mIsInterlaced
@ -220,9 +239,9 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
}
Maybe<SurfacePipe> pipe =
SurfacePipeFactory::CreateSurfacePipe(this, mNumFrames, Size(),
OutputSize(), aFrameInfo.mFrameRect,
format, pipeFlags);
SurfacePipeFactory::CreateSurfacePipe(this, Size(), OutputSize(),
aFrameInfo.mFrameRect, format,
animParams, pipeFlags);
if (!pipe) {
mPipe = SurfacePipe();
@ -239,18 +258,6 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
"image frame with %dx%d pixels for decoder %p",
mFrameRect.width, mFrameRect.height, this));
#ifdef PNG_APNG_SUPPORTED
if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) {
mAnimInfo = AnimFrameInfo(mPNG, mInfo);
if (mAnimInfo.mDispose == DisposalMethod::CLEAR) {
// We may have to display the background under this image during
// animation playback, so we regard it as transparent.
PostHasTransparency();
}
}
#endif
return NS_OK;
}
@ -269,9 +276,7 @@ nsPNGDecoder::EndImageFrame()
opacity = Opacity::FULLY_OPAQUE;
}
PostFrameStop(opacity, mAnimInfo.mDispose,
FrameTimeout::FromRawMilliseconds(mAnimInfo.mTimeout),
mAnimInfo.mBlend, Some(mFrameRect));
PostFrameStop(opacity);
}
nsresult

View file

@ -234,8 +234,12 @@ nsWebPDecoder::CreateFrame(const nsIntRect& aFrameRect)
SurfacePipeFlags pipeFlags = SurfacePipeFlags();
AnimationParams animParams {
aFrameRect, mTimeout, mCurrentFrame, mBlend, mDisposal
};
Maybe<SurfacePipe> pipe = SurfacePipeFactory::CreateSurfacePipe(this,
mCurrentFrame, Size(), OutputSize(), aFrameRect, mFormat, pipeFlags);
Size(), OutputSize(), aFrameRect, mFormat, Some(animParams), pipeFlags);
if (!pipe) {
MOZ_LOG(sWebPLog, LogLevel::Error,
("[this=%p] nsWebPDecoder::CreateFrame -- no pipe\n", this));