Bug 1119774 (Part 1) - Add a pref and Image init flag for downscale-during-decode. r=tn

This commit is contained in:
Seth Fowler 2015-01-12 03:24:25 -08:00
Родитель 1cd9ab3a7d
Коммит e45b4b33bd
6 изменённых файлов: 47 добавлений и 10 удалений

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

@ -233,6 +233,7 @@ private:
DECL_GFX_PREF(Once, "image.cache.timeweight", ImageCacheTimeWeight, int32_t, 500);
DECL_GFX_PREF(Once, "image.cache.size", ImageCacheSize, int32_t, 5*1024*1024);
DECL_GFX_PREF(Live, "image.downscale-during-decode.enabled", ImageDownscaleDuringDecodeEnabled, bool, false);
DECL_GFX_PREF(Live, "image.high_quality_downscaling.enabled", ImageHQDownscalingEnabled, bool, false);
DECL_GFX_PREF(Live, "image.high_quality_downscaling.min_factor", ImageHQDownscalingMinFactor, uint32_t, 1000);
DECL_GFX_PREF(Live, "image.high_quality_upscaling.max_size", ImageHQUpscalingMaxSize, uint32_t, 20971520);

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

@ -52,11 +52,16 @@ public:
* multipart/x-mixed-replace image parts fall into this category.) If this
* flag is set, INIT_FLAG_DISCARDABLE and INIT_FLAG_DECODE_ON_DRAW must not be
* set.
*
* INIT_FLAG_DOWNSCALE_DURING_DECODE: The container should attempt to
* downscale images during decoding instead of decoding them to their
* intrinsic size.
*/
static const uint32_t INIT_FLAG_NONE = 0x0;
static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
static const uint32_t INIT_FLAG_DECODE_ON_DRAW = 0x2;
static const uint32_t INIT_FLAG_TRANSIENT = 0x4;
static const uint32_t INIT_FLAG_NONE = 0x0;
static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
static const uint32_t INIT_FLAG_DECODE_ON_DRAW = 0x2;
static const uint32_t INIT_FLAG_TRANSIENT = 0x4;
static const uint32_t INIT_FLAG_DOWNSCALE_DURING_DECODE = 0x8;
/**
* Creates a new image container.

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

@ -31,14 +31,22 @@ namespace image {
ImageFactory::Initialize()
{ }
static bool
ShouldDownscaleDuringDecode(const nsCString& aMimeType)
{
// Not enabled for anything yet.
return false;
}
static uint32_t
ComputeImageFlags(ImageURL* uri, bool isMultiPart)
ComputeImageFlags(ImageURL* uri, const nsCString& aMimeType, bool isMultiPart)
{
nsresult rv;
// We default to the static globals.
bool isDiscardable = gfxPrefs::ImageMemDiscardable();
bool doDecodeOnDraw = gfxPrefs::ImageMemDecodeOnDraw();
bool doDownscaleDuringDecode = gfxPrefs::ImageDownscaleDuringDecodeEnabled();
// We want UI to be as snappy as possible and not to flicker. Disable
// discarding and decode-on-draw for chrome URLS.
@ -56,10 +64,15 @@ ComputeImageFlags(ImageURL* uri, bool isMultiPart)
isDiscardable = doDecodeOnDraw = false;
}
// Downscale-during-decode is only enabled for certain content types.
if (doDownscaleDuringDecode && !ShouldDownscaleDuringDecode(aMimeType)) {
doDownscaleDuringDecode = false;
}
// For multipart/x-mixed-replace, we basically want a direct channel to the
// decoder. Disable both for this case as well.
// decoder. Disable everything for this case.
if (isMultiPart) {
isDiscardable = doDecodeOnDraw = false;
isDiscardable = doDecodeOnDraw = doDownscaleDuringDecode = false;
}
// We have all the information we need.
@ -73,6 +86,9 @@ ComputeImageFlags(ImageURL* uri, bool isMultiPart)
if (isMultiPart) {
imageFlags |= Image::INIT_FLAG_TRANSIENT;
}
if (doDownscaleDuringDecode) {
imageFlags |= Image::INIT_FLAG_DOWNSCALE_DURING_DECODE;
}
return imageFlags;
}
@ -89,7 +105,7 @@ ImageFactory::CreateImage(nsIRequest* aRequest,
"Pref observers should have been initialized already");
// Compute the image's initialization flags.
uint32_t imageFlags = ComputeImageFlags(aURI, aIsMultiPart);
uint32_t imageFlags = ComputeImageFlags(aURI, aMimeType, aIsMultiPart);
// Select the type of image to create based on MIME type.
if (aMimeType.EqualsLiteral(IMAGE_SVG_XML)) {

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

@ -325,14 +325,21 @@ RasterImage::Init(const char* aMimeType,
// transient images.
MOZ_ASSERT(!(aFlags & INIT_FLAG_TRANSIENT) ||
(!(aFlags & INIT_FLAG_DISCARDABLE) &&
!(aFlags & INIT_FLAG_DECODE_ON_DRAW)),
"Transient images can't be discardable or decode-on-draw");
!(aFlags & INIT_FLAG_DECODE_ON_DRAW),
!(aFlags & INIT_FLAG_DOWNSCALE_DURING_DECODE)),
"Illegal init flags for transient image");
// Store initialization data
mSourceDataMimeType.Assign(aMimeType);
mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
mDecodeOnDraw = !!(aFlags & INIT_FLAG_DECODE_ON_DRAW);
mTransient = !!(aFlags & INIT_FLAG_TRANSIENT);
mDownscaleDuringDecode = !!(aFlags & INIT_FLAG_DOWNSCALE_DURING_DECODE);
#ifndef MOZ_ENABLE_SKIA
// Downscale-during-decode requires Skia.
mDownscaleDuringDecode = false;
#endif
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
if (!mDiscardable) {

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

@ -386,6 +386,7 @@ private: // data
bool mDiscardable:1; // Is container discardable?
bool mHasSourceData:1; // Do we have source data?
bool mHasBeenDecoded:1; // Decoded at least once?
bool mDownscaleDuringDecode:1;
// Whether we're waiting to start animation. If we get a StartAnimation() call
// but we don't yet have more than one frame, mPendingAnimation is set so that

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

@ -3753,13 +3753,20 @@ pref("browser.zoom.reflowZoom.reflowTimeout", 500);
*/
pref("browser.zoom.reflowZoom.reflowTextOnPageLoad", true);
//
// Image-related prefs
//
// The maximum size, in bytes, of the decoded images we cache
pref("image.cache.size", 5242880);
// A weight, from 0-1000, to place on time when comparing to size.
// Size is given a weight of 1000 - timeweight.
pref("image.cache.timeweight", 500);
// Whether we attempt to downscale images during decoding.
pref("image.downscale-during-decode.enabled", false);
// The default Accept header sent for images loaded over HTTP(S)
pref("image.http.accept", "image/png,image/*;q=0.8,*/*;q=0.5");