Bug 1573720 - Convert canvas.image.cache.limit to a static pref. r=mccr8
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 15 Aug 2019 05:31:24 +0000
changeset 488379 53019621c04ed8460626f88a9d650ffab5d96aa9
parent 488378 fbb952df34648f42973d2a58404d1edd50e77e09
child 488380 8dc85cb7b8be0122ceda10fec5886ee92f3e4a6c
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1573720
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1573720 - Convert canvas.image.cache.limit to a static pref. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D41919
dom/canvas/CanvasImageCache.cpp
modules/libpref/init/StaticPrefList.yaml
modules/libpref/init/all.js
--- a/dom/canvas/CanvasImageCache.cpp
+++ b/dom/canvas/CanvasImageCache.cpp
@@ -8,16 +8,17 @@
 #include "nsIImageLoadingContent.h"
 #include "nsExpirationTracker.h"
 #include "imgIRequest.h"
 #include "mozilla/dom/Element.h"
 #include "nsTHashtable.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
 #include "nsContentUtils.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/StaticPrefs_canvas.h"
 #include "mozilla/SystemGroup.h"
 #include "mozilla/gfx/2D.h"
 #include "gfx2DGlue.h"
 
 namespace mozilla {
 
 using namespace dom;
 using namespace gfx;
@@ -113,19 +114,16 @@ class AllCanvasImageCacheEntry : public 
     return HashGeneric(key->mImage.get());
   }
   enum { ALLOW_MEMMOVE = true };
 
   nsCOMPtr<imgIContainer> mImage;
   RefPtr<SourceSurface> mSourceSurface;
 };
 
-static bool sPrefsInitialized = false;
-static int32_t sCanvasImageCacheLimit = 0;
-
 class ImageCacheObserver;
 
 class ImageCache final : public nsExpirationTracker<ImageCacheEntryData, 4> {
  public:
   // We use 3 generations of 1 second each to get a 2-3 seconds timeout.
   enum { GENERATION_MS = 1000 };
   ImageCache();
   ~ImageCache();
@@ -214,21 +212,16 @@ class CanvasImageCacheShutdownObserver f
   NS_DECL_NSIOBSERVER
 };
 
 ImageCache::ImageCache()
     : nsExpirationTracker<ImageCacheEntryData, 4>(
           GENERATION_MS, "ImageCache",
           SystemGroup::EventTargetFor(TaskCategory::Other)),
       mTotal(0) {
-  if (!sPrefsInitialized) {
-    sPrefsInitialized = true;
-    Preferences::AddIntVarCache(&sCanvasImageCacheLimit,
-                                "canvas.image.cache.limit", 0);
-  }
   mImageCacheObserver = new ImageCacheObserver(this);
   MOZ_RELEASE_ASSERT(mImageCacheObserver,
                      "GFX: Can't alloc ImageCacheObserver");
 }
 
 ImageCache::~ImageCache() {
   AgeAllGenerations();
   mImageCacheObserver->Destroy();
@@ -292,21 +285,25 @@ void CanvasImageCache::NotifyDrawImage(E
 
     AllCanvasImageCacheEntry* allEntry =
         gImageCache->mAllCanvasCache.PutEntry(allCanvasCacheKey);
     if (allEntry) {
       allEntry->mSourceSurface = aSource;
     }
   }
 
-  if (!sCanvasImageCacheLimit) return;
+  if (!StaticPrefs::canvas_image_cache_limit()) {
+    return;
+  }
 
   // Expire the image cache early if its larger than we want it to be.
-  while (gImageCache->mTotal > size_t(sCanvasImageCacheLimit))
+  while (gImageCache->mTotal >
+         size_t(StaticPrefs::canvas_image_cache_limit())) {
     gImageCache->AgeOneGeneration();
+  }
 }
 
 SourceSurface* CanvasImageCache::LookupAllCanvas(Element* aImage) {
   if (!gImageCache) {
     return nullptr;
   }
 
   nsCOMPtr<imgIContainer> imgContainer = GetImageContainer(aImage);
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -923,16 +923,22 @@
   type: bool
   value: true
   mirror: always
 
 #---------------------------------------------------------------------------
 # Prefs starting with "canvas."
 #---------------------------------------------------------------------------
 
+# Limit for the canvas image cache. 0 means unlimited.
+- name: canvas.image.cache.limit
+  type: int32_t
+  value: 0
+  mirror: always
+
 # Add support for canvas path objects
 - name: canvas.path.enabled
   type: bool
   value: true
   mirror: always
 
 - name: canvas.capturestream.enabled
   type: bool
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4483,20 +4483,16 @@ pref("image.mem.allow_locking_in_content
   pref("image.mem.volatile.min_threshold_kb", 100);
 #else
   pref("image.mem.volatile.min_threshold_kb", -1);
 #endif
 
 // Whether we attempt to decode WebP images or not.
 pref("image.webp.enabled", true);
 
-// Limit for the canvas image cache. 0 means we don't limit the size of the
-// cache.
-pref("canvas.image.cache.limit", 0);
-
 // WebGL prefs
 pref("gl.require-hardware", false);
 #ifdef XP_MACOSX
   pref("gl.multithreaded", true);
 #endif
 pref("gl.ignore-dx-interop2-blacklist", false);
 pref("gl.use-tls-is-current", 0);
 pref("gl.allow-high-power", true);