Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug 716140 - Control multithreaded encoding with a pref. r=seth

  • Loading branch information...
commit 498908fed8796f81189e736fbbc186b1ee3987b0 1 parent 1199545
@joedrew joedrew authored
Showing with 28 additions and 8 deletions.
  1. +20 −8 image/src/RasterImage.cpp
  2. +8 −0 modules/libpref/src/init/all.js
View
28 image/src/RasterImage.cpp
@@ -76,6 +76,8 @@ static uint32_t gMaxMSBeforeYield = 0;
static bool gHQDownscaling = false;
// This is interpreted as a floating-point value / 1000
static uint32_t gHQDownscalingMinFactor = 1000;
+static bool gMultithreadedDecoding = true;
+static int32_t gDecodingThreadLimit = -1;
// The maximum number of times any one RasterImage was decoded. This is only
// used for statistics.
@@ -92,6 +94,10 @@ InitPrefCaches()
"image.high_quality_downscaling.enabled", false);
Preferences::AddUintVarCache(&gHQDownscalingMinFactor,
"image.high_quality_downscaling.min_factor", 1000);
+ Preferences::AddBoolVarCache(&gMultithreadedDecoding,
+ "image.multithreaded_decoding.enabled", true);
+ Preferences::AddIntVarCache(&gDecodingThreadLimit,
+ "image.multithreaded_decoding.limit", -1);
}
/* We define our own error checking macros here for 2 reasons:
@@ -3553,14 +3559,20 @@ RasterImage::DecodePool::Singleton()
RasterImage::DecodePool::DecodePool()
{
- mThreadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
- if (mThreadPool) {
- mThreadPool->SetName(NS_LITERAL_CSTRING("ImageDecoder"));
- mThreadPool->SetThreadLimit(std::max(PR_GetNumberOfProcessors() - 1, 1));
+ if (gMultithreadedDecoding) {
+ mThreadPool = do_CreateInstance(NS_THREADPOOL_CONTRACTID);
+ if (mThreadPool) {
+ mThreadPool->SetName(NS_LITERAL_CSTRING("ImageDecoder"));
+ if (gDecodingThreadLimit <= 0) {
+ mThreadPool->SetThreadLimit(std::max(PR_GetNumberOfProcessors() - 1, 1));
+ } else {
+ mThreadPool->SetThreadLimit(static_cast<uint32_t>(gDecodingThreadLimit));
+ }
- nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
- if (obsSvc) {
- obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
+ nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
+ if (obsSvc) {
+ obsSvc->AddObserver(this, "xpcom-shutdown-threads", false);
+ }
}
}
}
@@ -3607,7 +3619,7 @@ RasterImage::DecodePool::RequestDecode(RasterImage* aImg)
aImg->mDecodeRequest->mRequestStatus = DecodeRequest::REQUEST_PENDING;
nsRefPtr<DecodeJob> job = new DecodeJob(aImg->mDecodeRequest, aImg);
- if (!mThreadPool) {
+ if (!gMultithreadedDecoding || !mThreadPool) {
NS_DispatchToMainThread(job);
} else {
mThreadPool->Dispatch(job, nsIEventTarget::DISPATCH_NORMAL);
View
8 modules/libpref/src/init/all.js
@@ -3870,6 +3870,14 @@ pref("image.mem.max_ms_before_yield", 5);
// might keep around more than this, but we'll try to get down to this value).
pref("image.mem.max_decoded_image_kb", 51200);
+// Whether we decode images on multiple background threads rather than the
+// foreground thread.
+pref("image.multithreaded_decoding.enabled", true);
+
+// How many threads we'll use for multithreaded decoding. If < 0, will be
+// automatically determined based on the system's number of cores.
+pref("image.multithreaded_decoding.limit", -1);
+
// WebGL prefs
pref("gl.msaa-level", 2);
pref("webgl.force-enabled", false);
Please sign in to comment.
Something went wrong with that request. Please try again.