Bug 1291054 (Part 4) - Add Decoder convenience methods for the common case of frame rects that cover the whole image. r=edwin

This commit is contained in:
Seth Fowler 2016-07-29 14:26:23 -07:00
parent 3cca5ff418
commit 6ce660afb2
5 changed files with 33 additions and 9 deletions

View File

@ -272,6 +272,18 @@ public:
return mImageMetadata.GetSize();
}
/**
* @return an IntRect which covers the entire area of this image at its
* intrinsic size, appropriate for use as a frame rect when the image itself
* does not specify one.
*
* Illegal to call if HasSize() returns false.
*/
gfx::IntRect FullFrame() const
{
return gfx::IntRect(gfx::IntPoint(), Size());
}
/**
* @return the output size of this decoder. If this is different than the
* intrinsic size, then the image will be downscaled during the decoding
@ -285,6 +297,22 @@ public:
: Size();
}
/**
* @return an IntRect which covers the entire area of this image at its size
* after scaling - that is, at its output size.
*
* XXX(seth): This is only used for decoders which are using the old
* Downscaler code instead of SurfacePipe, since the old AllocateFrame() and
* Downscaler APIs required that the frame rect be specified in output space.
* We should remove this once all decoders use SurfacePipe.
*
* Illegal to call if HasSize() returns false.
*/
gfx::IntRect FullOutputFrame() const
{
return gfx::IntRect(gfx::IntPoint(), OutputSize());
}
virtual Telemetry::ID SpeedHistogram();
ImageMetadata& GetImageMetadata() { return mImageMetadata; }
@ -411,8 +439,7 @@ protected:
/// Helper method for decoders which only have 'basic' frame allocation needs.
nsresult AllocateBasicFrame() {
return AllocateFrame(0, Size(), gfx::IntRect(gfx::IntPoint(), Size()),
gfx::SurfaceFormat::B8G8R8A8);
return AllocateFrame(0, Size(), FullFrame(), gfx::SurfaceFormat::B8G8R8A8);
}
private:

View File

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

View File

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

View File

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

View File

@ -151,7 +151,7 @@ nsPNGDecoder::GetTransparencyType(SurfaceFormat aFormat,
if (aFormat == SurfaceFormat::B8G8R8A8) {
return TransparencyType::eAlpha;
}
if (!IntRect(IntPoint(), Size()).IsEqualEdges(aFrameRect)) {
if (!aFrameRect.IsEqualEdges(FullFrame())) {
MOZ_ASSERT(HasAnimation());
return TransparencyType::eFrameRect;
}