Bug 1292505 (Part 1b) - Update DecoderFactory to use SetOutputSize(), and propagate the changes to RasterImage. r=edwin

This commit is contained in:
Seth Fowler 2016-08-05 04:19:03 -07:00
Родитель f2c6e25053
Коммит 1e04c585b2
3 изменённых файлов: 18 добавлений и 34 удалений

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

@ -109,7 +109,7 @@ DecoderFactory::CreateDecoder(DecoderType aType,
NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer,
const IntSize& aIntrinsicSize,
const Maybe<IntSize>& aTargetSize,
const IntSize& aOutputSize,
DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags,
int aSampleSize)
@ -125,25 +125,19 @@ DecoderFactory::CreateDecoder(DecoderType aType,
// Initialize the decoder.
decoder->SetMetadataDecode(false);
decoder->SetIterator(aSourceBuffer->Iterator());
decoder->SetOutputSize(aOutputSize);
decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::FIRST_FRAME_ONLY);
decoder->SetSurfaceFlags(aSurfaceFlags);
decoder->SetSampleSize(aSampleSize);
// Set a target size for downscale-during-decode if applicable.
if (aTargetSize) {
DebugOnly<nsresult> rv = decoder->SetTargetSize(*aTargetSize);
MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
}
if (NS_FAILED(decoder->Init())) {
return nullptr;
}
// Add a placeholder to the SurfaceCache so we won't trigger any more decoders
// with the same parameters.
IntSize surfaceSize = aTargetSize.valueOr(aIntrinsicSize);
SurfaceKey surfaceKey =
RasterSurfaceKey(surfaceSize, aSurfaceFlags, /* aFrameNum = */ 0);
RasterSurfaceKey(aOutputSize, aSurfaceFlags, /* aFrameNum = */ 0);
InsertOutcome outcome =
SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey);
if (outcome != InsertOutcome::SUCCESS) {
@ -254,16 +248,10 @@ DecoderFactory::CreateDecoderForICOResource(DecoderType aType,
// Initialize the decoder, copying settings from @aICODecoder.
decoder->SetMetadataDecode(aICODecoder->IsMetadataDecode());
decoder->SetIterator(aSourceBuffer->Iterator());
decoder->SetOutputSize(aICODecoder->OutputSize());
decoder->SetDecoderFlags(aICODecoder->GetDecoderFlags());
decoder->SetSurfaceFlags(aICODecoder->GetSurfaceFlags());
// Set a target size for downscale-during-decode if applicable.
const Maybe<IntSize> targetSize = aICODecoder->GetTargetSize();
if (targetSize) {
DebugOnly<nsresult> rv = decoder->SetTargetSize(*targetSize);
MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
}
if (NS_FAILED(decoder->Init())) {
return nullptr;
}
@ -274,7 +262,7 @@ DecoderFactory::CreateDecoderForICOResource(DecoderType aType,
/* static */ already_AddRefed<Decoder>
DecoderFactory::CreateAnonymousDecoder(DecoderType aType,
NotNull<SourceBuffer*> aSourceBuffer,
const Maybe<IntSize>& aTargetSize,
const Maybe<IntSize>& aOutputSize,
SurfaceFlags aSurfaceFlags)
{
if (aType == DecoderType::UNKNOWN) {
@ -303,10 +291,9 @@ DecoderFactory::CreateAnonymousDecoder(DecoderType aType,
decoder->SetDecoderFlags(decoderFlags);
decoder->SetSurfaceFlags(aSurfaceFlags);
// Set a target size for downscale-during-decode if applicable.
if (aTargetSize) {
DebugOnly<nsresult> rv = decoder->SetTargetSize(*aTargetSize);
MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
// Set an output size for downscale-during-decode if requested.
if (aOutputSize) {
decoder->SetOutputSize(*aOutputSize);
}
if (NS_FAILED(decoder->Init())) {

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

@ -57,10 +57,9 @@ public:
* from.
* @param aIntrinsicSize The intrinsic size of the image, normally obtained
* during the metadata decode.
* @param aTargetSize If not Nothing(), the target size which the image should
* be scaled to during decoding. It's an error to specify
* a target size for a decoder type which doesn't support
* downscale-during-decode.
* @param aOutputSize The output size for the decoder. If this is smaller than
* the intrinsic size, the decoder will downscale the
* image.
* @param aDecoderFlags Flags specifying the behavior of this decoder.
* @param aSurfaceFlags Flags specifying the type of output this decoder
* should produce.
@ -72,7 +71,7 @@ public:
NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer,
const gfx::IntSize& aIntrinsicSize,
const Maybe<gfx::IntSize>& aTargetSize,
const gfx::IntSize& aOutputSize,
DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags,
int aSampleSize);
@ -150,17 +149,17 @@ public:
* @param aType Which type of decoder to create - JPEG, PNG, etc.
* @param aSourceBuffer The SourceBuffer which the decoder will read its data
* from.
* @param aTargetSize If not Nothing(), the target size which the image should
* be scaled to during decoding. It's an error to specify
* a target size for a decoder type which doesn't support
* downscale-during-decode.
* @param aOutputSize If Some(), the output size for the decoder. If this is
* smaller than the intrinsic size, the decoder will
* downscale the image. If Nothing(), the output size will
* be the intrinsic size.
* @param aSurfaceFlags Flags specifying the type of output this decoder
* should produce.
*/
static already_AddRefed<Decoder>
CreateAnonymousDecoder(DecoderType aType,
NotNull<SourceBuffer*> aSourceBuffer,
const Maybe<gfx::IntSize>& aTargetSize,
const Maybe<gfx::IntSize>& aOutputSize,
SurfaceFlags aSurfaceFlags);
/**

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

@ -1134,8 +1134,6 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
// expire.
SurfaceCache::UnlockEntries(ImageKey(this));
Maybe<IntSize> targetSize = mSize != aSize ? Some(aSize) : Nothing();
// Determine which flags we need to decode this image with.
DecoderFlags decoderFlags = DefaultDecoderFlags();
if (aFlags & FLAG_ASYNC_NOTIFY) {
@ -1163,7 +1161,7 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
decoderFlags, surfaceFlags);
} else {
task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
mSourceBuffer, mSize, targetSize,
mSourceBuffer, mSize, aSize,
decoderFlags, surfaceFlags,
mRequestedSampleSize);
}