diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 23f7b7c6771..f5101661937 100644 --- a/image/public/imgIContainer.idl +++ b/image/public/imgIContainer.idl @@ -69,7 +69,7 @@ native nsIntSizeByVal(nsIntSize); * * Internally, imgIContainer also manages animation of images. */ -[scriptable, builtinclass, uuid(25236a61-9568-4b2b-a2ce-209a2db9771d)] +[scriptable, builtinclass, uuid(60e07aae-8500-46c7-b305-9a35ad7e6665)] interface imgIContainer : nsISupports { /** @@ -151,6 +151,9 @@ interface imgIContainer : nsISupports * FLAG_SYNC_DECODE: Forces synchronous/non-progressive decode of all * available data before the call returns. * + * FLAG_SYNC_DECODE_IF_FAST: Like FLAG_SYNC_DECODE, but requests a sync decode + * be performed only if ImageLib estimates it can be completed very quickly. + * * FLAG_DECODE_NO_PREMULTIPLY_ALPHA: Do not premultiply alpha if * it's not already premultiplied in the image data. * @@ -177,12 +180,13 @@ interface imgIContainer : nsISupports */ const unsigned long FLAG_NONE = 0x0; const unsigned long FLAG_SYNC_DECODE = 0x1; - const unsigned long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x2; - const unsigned long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x4; - const unsigned long FLAG_CLAMP = 0x8; - const unsigned long FLAG_HIGH_QUALITY_SCALING = 0x10; - const unsigned long FLAG_WANT_DATA_SURFACE = 0x20; - const unsigned long FLAG_BYPASS_SURFACE_CACHE = 0x40; + const unsigned long FLAG_SYNC_DECODE_IF_FAST = 0x2; + const unsigned long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x4; + const unsigned long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x8; + const unsigned long FLAG_CLAMP = 0x10; + const unsigned long FLAG_HIGH_QUALITY_SCALING = 0x20; + const unsigned long FLAG_WANT_DATA_SURFACE = 0x40; + const unsigned long FLAG_BYPASS_SURFACE_CACHE = 0x80; /** * A constant specifying the default set of decode flags (i.e., the default diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index ae01a97ebfb..a56b49d43ef 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -1420,23 +1420,18 @@ RasterImage::WantDecodedFrames(const nsIntSize& aSize, uint32_t aFlags, SurfaceCache::UnlockSurfaces(ImageKey(this)); } + DecodeStrategy strategy = DecodeStrategy::ASYNC; + if (aShouldSyncNotify) { // We can sync notify, which means we can also sync decode. if (aFlags & FLAG_SYNC_DECODE) { - Decode(DecodeStrategy::SYNC_IF_POSSIBLE, Some(aSize), aFlags); - return; + strategy = DecodeStrategy::SYNC_IF_POSSIBLE; + } else if (aFlags & FLAG_SYNC_DECODE_IF_FAST) { + strategy = DecodeStrategy::SYNC_FOR_SMALL_IMAGES; } - - // Here we are explicitly trading off flashing for responsiveness in the - // case that we're redecoding an image (see bug 845147). - Decode(mHasBeenDecoded ? DecodeStrategy::ASYNC - : DecodeStrategy::SYNC_FOR_SMALL_IMAGES, - Some(aSize), aFlags); - return; } - // We can't sync notify, so do an async decode. - Decode(DecodeStrategy::ASYNC, Some(aSize), aFlags); + Decode(strategy, Some(aSize), aFlags); } //****************************************************************************** @@ -1466,7 +1461,7 @@ RasterImage::StartDecoding() return NS_OK; } - return RequestDecodeForSize(mSize, FLAG_SYNC_DECODE); + return RequestDecodeForSize(mSize, FLAG_SYNC_DECODE_IF_FAST); } NS_IMETHODIMP @@ -1487,8 +1482,15 @@ RasterImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags) // downscale-during-decode. nsIntSize targetSize = mDownscaleDuringDecode ? aSize : mSize; - // Sync decode small images if requested. - bool shouldSyncDecodeSmallImages = aFlags & FLAG_SYNC_DECODE; + // Decide whether to sync decode images we can decode quickly. Here we are + // explicitly trading off flashing for responsiveness in the case that we're + // redecoding an image (see bug 845147). + bool shouldSyncDecodeIfFast = + !mHasBeenDecoded && (aFlags & FLAG_SYNC_DECODE_IF_FAST); + + uint32_t flags = shouldSyncDecodeIfFast + ? aFlags + : aFlags & ~FLAG_SYNC_DECODE_IF_FAST; // Look up the first frame of the image, which will implicitly start decoding // if it's not available right now. @@ -1496,8 +1498,8 @@ RasterImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags) // synchronously decoding small images, while passing false has the effect of // decoding asynchronously, but that's not obvious from the argument name. // This API needs to be reworked. - LookupFrame(0, targetSize, DecodeFlags(aFlags), - /* aShouldSyncNotify = */ shouldSyncDecodeSmallImages); + LookupFrame(0, targetSize, flags, + /* aShouldSyncNotify = */ shouldSyncDecodeIfFast); return NS_OK; }