Bug 1291054 (Part 2) - Add a Decoder::OutputSize() getter and use it in the decoders. r=edwin

This commit is contained in:
Seth Fowler 2016-07-29 15:45:58 -07:00
parent 1d1a71d4bc
commit 881c87ebec
6 changed files with 27 additions and 22 deletions

View File

@ -129,6 +129,10 @@ public:
* If this decoder supports downscale-during-decode and is configured to
* downscale, returns the target size that the output size will be decoded to.
* Otherwise, returns Nothing().
*
* Note that virtually all callers don't care whether a decoder is configured
* to downscale; they just want to know what the decoder's output size is.
* Such callers should use OutputSize() instead.
*/
Maybe<gfx::IntSize> GetTargetSize();
@ -268,6 +272,19 @@ public:
return mImageMetadata.GetSize();
}
/**
* @return the output size of this decoder. If this is different than the
* intrinsic size, then the image will be downscaled during the decoding
* process.
*
* Illegal to call if HasSize() returns false.
*/
gfx::IntSize OutputSize() const
{
return mDownscaler ? mDownscaler->TargetSize()
: GetSize();
}
virtual Telemetry::ID SpeedHistogram();
ImageMetadata& GetImageMetadata() { return mImageMetadata; }

View File

@ -674,9 +674,8 @@ nsBMPDecoder::ReadBitfields(const char* aData, size_t aLength)
}
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
IntSize targetSize = mDownscaler ? mDownscaler->TargetSize() : GetSize();
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, targetSize,
IntRect(IntPoint(), targetSize),
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
IntRect(IntPoint(), OutputSize()),
SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
return Transition::TerminateFailure();

View File

@ -193,18 +193,13 @@ nsGIFDecoder2::BeginImageFrame(const IntRect& aFrameRect,
Maybe<SurfacePipe> pipe;
if (mGIFStruct.images_decoded == 0) {
// This is the first frame. We may be downscaling, so compute the target
// size.
IntSize targetSize = mDownscaler ? mDownscaler->TargetSize()
: GetSize();
// The first frame may be displayed progressively.
pipeFlags |= SurfacePipeFlags::PROGRESSIVE_DISPLAY;
// The first frame is always decoded into an RGB surface.
pipe =
SurfacePipeFactory::CreateSurfacePipe(this, mGIFStruct.images_decoded,
GetSize(), targetSize,
GetSize(), OutputSize(),
aFrameRect, format, pipeFlags);
} else {
// This is an animation frame (and not the first). To minimize the memory

View File

@ -69,12 +69,10 @@ nsIconDecoder::ReadHeader(const char* aData)
}
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
IntSize targetSize = mDownscaler ? mDownscaler->TargetSize() : GetSize();
IntRect frameRect(IntPoint(0, 0), GetSize());
Maybe<SurfacePipe> pipe =
SurfacePipeFactory::CreateSurfacePipe(this, 0, GetSize(), targetSize,
frameRect, SurfaceFormat::B8G8R8A8,
SurfacePipeFactory::CreateSurfacePipe(this, 0, GetSize(), OutputSize(),
IntRect(IntPoint(), GetSize()),
SurfaceFormat::B8G8R8A8,
SurfacePipeFlags());
if (!pipe) {
return Transition::TerminateFailure();

View File

@ -388,10 +388,9 @@ nsJPEGDecoder::ReadJPEGData(const char* aData, size_t aLength)
jpeg_has_multiple_scans(&mInfo);
MOZ_ASSERT(!mImageData, "Already have a buffer allocated?");
nsIntSize targetSize = mDownscaler ? mDownscaler->TargetSize() : GetSize();
nsresult rv = AllocateFrame(0, targetSize,
nsIntRect(nsIntPoint(), targetSize),
gfx::SurfaceFormat::B8G8R8A8);
nsresult rv = AllocateFrame(/* aFrameNum = */ 0, OutputSize(),
IntRect(IntPoint(), OutputSize()),
SurfaceFormat::B8G8R8A8);
if (NS_FAILED(rv)) {
mState = JPEG_ERROR;
MOZ_LOG(sJPEGDecoderAccountingLog, LogLevel::Debug,

View File

@ -201,9 +201,6 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
MOZ_ASSERT_IF(mDownscaler, !GetImageMetadata().HasAnimation());
MOZ_ASSERT_IF(mDownscaler, transparency != TransparencyType::eFrameRect);
IntSize targetSize = mDownscaler ? mDownscaler->TargetSize()
: GetSize();
// 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
@ -217,7 +214,7 @@ nsPNGDecoder::CreateFrame(const FrameInfo& aFrameInfo)
Maybe<SurfacePipe> pipe =
SurfacePipeFactory::CreateSurfacePipe(this, mNumFrames, GetSize(),
targetSize, aFrameInfo.mFrameRect,
OutputSize(), aFrameInfo.mFrameRect,
format, pipeFlags);
if (!pipe) {