Bug 590260 - Decode more bytes at a time during image redecodes.r=joe,a=blocker

This commit is contained in:
Bobby Holley 2010-08-25 18:58:27 -04:00
parent 24095da713
commit d0989f8f70
4 changed files with 39 additions and 6 deletions

View File

@ -76,6 +76,22 @@ static PRLogModuleInfo *gCompressedImageAccountingLog = PR_NewLogModule ("Compre
#define gCompressedImageAccountingLog
#endif
// Tweakable progressive decoding parameters
static PRUint32 gDecodeBytesAtATime = 200000;
static PRUint32 gMaxMSBeforeYield = 400;
void
RasterImage::SetDecodeBytesAtATime(PRUint32 aBytesAtATime)
{
gDecodeBytesAtATime = aBytesAtATime;
}
void
RasterImage::SetMaxMSBeforeYield(PRUint32 aMaxMS)
{
gMaxMSBeforeYield = aMaxMS;
}
/* We define our own error checking macros here for 2 reasons:
*
* 1) Most of the failures we encounter here will (hopefully) be
@ -2557,10 +2573,6 @@ RasterImage::DoError()
LOG_CONTAINER_ERROR;
}
// Tweakable progressive decoding parameters
#define DECODE_BYTES_AT_A_TIME 4096
#define MAX_USEC_BEFORE_YIELD (1000 * 5)
// Decodes some data, then re-posts itself to the end of the event queue if
// there's more processing to be done
NS_IMETHODIMP
@ -2598,11 +2610,11 @@ imgDecodeWorker::Run()
// synchronous. Write all the data in that case, otherwise write a
// chunk
PRUint32 maxBytes = image->mDecoder->IsSizeDecode()
? image->mSourceData.Length() : DECODE_BYTES_AT_A_TIME;
? image->mSourceData.Length() : gDecodeBytesAtATime;
// Loop control
PRBool haveMoreData = PR_TRUE;
nsTime deadline(PR_Now() + MAX_USEC_BEFORE_YIELD);
nsTime deadline(PR_Now() + 1000 * gMaxMSBeforeYield);
// We keep decoding chunks until one of three possible events occur:
// 1) We don't have any data left to decode

View File

@ -290,6 +290,10 @@ public:
kDisposeRestorePrevious // Restore the previous (composited) frame
};
// Progressive decoding knobs
static void SetDecodeBytesAtATime(PRUint32 aBytesAtATime);
static void SetMaxMSBeforeYield(PRUint32 aMaxMS);
private:
struct Anim
{

View File

@ -87,6 +87,8 @@
#define DISCARD_PREF "image.mem.discardable"
#define DECODEONDRAW_PREF "image.mem.decodeondraw"
#define BYTESATATIME_PREF "image.mem.decode_bytes_at_a_time"
#define MAXMS_PREF "image.mem.max_ms_before_yield"
#define SVG_MIMETYPE "image/svg+xml"
using namespace mozilla::imagelib;
@ -118,6 +120,15 @@ ReloadPrefs(nsIPrefBranch *aBranch)
if (NS_SUCCEEDED(rv))
gDecodeOnDraw = decodeondraw;
// Progressive decoding knobs
PRInt32 bytesAtATime, maxMS;
rv = aBranch->GetIntPref(BYTESATATIME_PREF, &bytesAtATime);
if (NS_SUCCEEDED(rv))
RasterImage::SetDecodeBytesAtATime(bytesAtATime);
rv = aBranch->GetIntPref(MAXMS_PREF, &maxMS);
if (NS_SUCCEEDED(rv))
RasterImage::SetMaxMSBeforeYield(maxMS);
// Discard timeout
mozilla::imagelib::DiscardTracker::ReloadTimeout();
}

View File

@ -3154,6 +3154,12 @@ pref("image.mem.decodeondraw", false);
// value and twice this value.
pref("image.mem.min_discard_timeout_ms", 10000);
// Chunk size for calls to the image decoders
pref("image.mem.decode_bytes_at_a_time", 200000);
// The longest time we can spend in an iteration of an async decode
pref("image.mem.max_ms_before_yield", 400);
// WebGL prefs
pref("webgl.enabled_for_all_sites", false);
pref("webgl.shader_validator", true);