Backed out changeset 382f3133d961 (bug 920160) for suspicion of causing Android reftest failures. a=backout
authorRyan VanderMeulen <ryanvm@gmail.com>
Sun, 27 Oct 2013 21:18:56 -0400
changeset 156217 7090e4028a66574ccca1f9dcb05a2eb88c216b77
parent 156209 32bc5b2be9dd725b2fbda5615f286c0c83f5ed05
child 156224 e7922b4a6decb7ad2107d40b6a029538170d997d
push idunknown
push userunknown
push dateunknown
reviewersbackout
bugs920160
milestone26.0a2
backs out382f3133d96188fd237692c537739fc72bc2266c
Backed out changeset 382f3133d961 (bug 920160) for suspicion of causing Android reftest failures. a=backout
b2g/app/b2g.js
gfx/2d/2D.h
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
gfx/2d/Factory.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
hal/Hal.cpp
hal/Hal.h
hal/fallback/FallbackMemory.cpp
hal/linux/LinuxMemory.cpp
hal/moz.build
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -792,19 +792,16 @@ pref("dom.mozInputMethod.enabled", true)
 // to communicate with a usb cable via adb forward
 pref("devtools.debugger.unix-domain-socket", "/data/local/debugger-socket");
 
 // enable Skia/GL (OpenGL-accelerated 2D drawing) for large enough 2d canvases,
 // falling back to Skia/software for smaller canvases
 pref("gfx.canvas.azure.backends", "skia");
 pref("gfx.canvas.azure.accelerated", true);
 
-// Turn on dynamic cache size for Skia
-pref("gfx.canvas.skiagl.dynamic-cache", true);
-
 // enable fence with readpixels for SurfaceStream
 pref("gfx.gralloc.fence-with-readpixels", true);
 
 // Enable Telephony API
 pref("dom.telephony.enabled", true);
 
 // Cell Broadcast API
 pref("dom.cellbroadcast.enabled", true);
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -975,19 +975,16 @@ public:
   static void SetGlobalEventRecorder(DrawEventRecorder *aRecorder);
 
 #ifdef USE_SKIA_GPU
   static TemporaryRef<DrawTarget>
     CreateDrawTargetSkiaWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLContext,
                                                       GrGLInterface* aGrGLInterface,
                                                       const IntSize &aSize,
                                                       SurfaceFormat aFormat);
-
-  static void
-    SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes);
 #endif
 
 #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE)
   static TemporaryRef<GlyphRenderingOptions>
     CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting);
 #endif
   static TemporaryRef<DrawTarget>
     CreateDualDrawTarget(DrawTarget *targetA, DrawTarget *targetB);
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -71,68 +71,66 @@ public:
 
   std::vector<SkColor> mColors;
   std::vector<SkScalar> mPositions;
   int mCount;
   ExtendMode mExtendMode;
 };
 
 #ifdef USE_SKIA_GPU
-int DrawTargetSkia::sTextureCacheCount = 256;
-int DrawTargetSkia::sTextureCacheSizeInBytes = 96*1024*1024;
 
 static std::vector<DrawTargetSkia*>&
 GLDrawTargets()
 {
   static std::vector<DrawTargetSkia*> targets;
   return targets;
 }
 
-void
-DrawTargetSkia::RebalanceCacheLimits()
+#define SKIA_MAX_CACHE_ITEMS 256
+
+// 64MB was chosen because it seems we can pass all of our tests
+// on the current hardware (Tegra2) without running out of memory
+#define SKIA_TOTAL_CACHE_SIZE 64*1024*1024
+
+static void
+SetCacheLimits()
 {
-  // Divide the global cache limits equally between all currently active GL-backed
-  // Skia DrawTargets.
   std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
-  uint32_t targetCount = targets.size();
-  if (targetCount == 0)
+  uint32_t size = targets.size();
+  if (size == 0)
     return;
 
-  int individualCacheSize = sTextureCacheSizeInBytes / targetCount;
-  for (uint32_t i = 0; i < targetCount; i++) {
-    targets[i]->SetCacheLimits(sTextureCacheCount, individualCacheSize);
+  int individualCacheSize = SKIA_TOTAL_CACHE_SIZE / size;
+  for (uint32_t i = 0; i < size; i++) {
+    targets[i]->SetCacheLimits(SKIA_MAX_CACHE_ITEMS, individualCacheSize);
   }
+
 }
 
+#undef SKIA_MAX_CACHE_ITEMS
+#undef SKIA_TOTAL_CACHE_SIZE
+
 static void
 AddGLDrawTarget(DrawTargetSkia* target)
 {
   GLDrawTargets().push_back(target);
-  DrawTargetSkia::RebalanceCacheLimits();
+  SetCacheLimits();
 }
 
 static void
 RemoveGLDrawTarget(DrawTargetSkia* target)
 {
   std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
   std::vector<DrawTargetSkia*>::iterator it = std::find(targets.begin(), targets.end(), target);
   if (it != targets.end()) {
     targets.erase(it);
-    DrawTargetSkia::RebalanceCacheLimits();
+    SetCacheLimits();
   }
 }
 
-void
-DrawTargetSkia::SetGlobalCacheLimits(int aCount, int aSizeInBytes)
-{
-  sTextureCacheCount = aCount;
-  sTextureCacheSizeInBytes = aSizeInBytes;
-
-  DrawTargetSkia::RebalanceCacheLimits();
-}
 #endif
 
 DrawTargetSkia::DrawTargetSkia()
   : mSnapshot(nullptr)
 {
 #ifdef ANDROID
   mSoftClipping = false;
 #else
@@ -737,16 +735,17 @@ DrawTargetSkia::InitWithGLContextAndGrGL
 }
 
 void
 DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes)
 {
   MOZ_ASSERT(mGrContext, "No GrContext!");
   mGrContext->setTextureCacheLimits(aCount, aSizeInBytes);
 }
+
 #endif
 
 void
 DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat)
 {
   bool isOpaque = false;
   if (aFormat == FORMAT_B8G8R8X8) {
     // We have to manually set the A channel to be 255 as Skia doesn't understand BGRX
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -100,19 +100,17 @@ public:
 
 #ifdef USE_SKIA_GPU
   virtual GenericRefCountedBase* GetGLContext() const MOZ_OVERRIDE { return mGLContext; }
   void InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLContext,
                                          GrGLInterface* aGrGLInterface,
                                          const IntSize &aSize,
                                          SurfaceFormat aFormat) MOZ_OVERRIDE;
 
-  void SetCacheLimits(int aCount, int aSizeInBytes);
-  static void SetGlobalCacheLimits(int aCount, int aSizeInBytes);
-  static void RebalanceCacheLimits();
+  void SetCacheLimits(int number, int sizeInBytes);
 #endif
 
   operator std::string() const {
     std::stringstream stream;
     stream << "DrawTargetSkia(" << this << ")";
     return stream.str();
   }
 
@@ -127,19 +125,16 @@ private:
    * These members have inter-dependencies, but do not keep each other alive, so
    * destruction order is very important here: mGrContext uses mGrGLInterface, and
    * through it, uses mGLContext, so it is important that they be declared in the
    * present order.
    */
   RefPtr<GenericRefCountedBase> mGLContext;
   SkRefPtr<GrGLInterface> mGrGLInterface;
   SkRefPtr<GrContext> mGrContext;
-
-  static int sTextureCacheCount;
-  static int sTextureCacheSizeInBytes;
 #endif
 
   IntSize mSize;
   SkRefPtr<SkCanvas> mCanvas;
   SourceSurfaceSkia* mSnapshot;
   bool mSoftClipping;
 };
 
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -508,22 +508,16 @@ Factory::CreateDrawTargetSkiaWithGLConte
                                                            const IntSize &aSize,
                                                            SurfaceFormat aFormat)
 {
   DrawTargetSkia* newDrawTargetSkia = new DrawTargetSkia();
   newDrawTargetSkia->InitWithGLContextAndGrGLInterface(aGLContext, aGrGLInterface, aSize, aFormat);
   RefPtr<DrawTarget> newTarget = newDrawTargetSkia;
   return newTarget;
 }
-
-void
-Factory::SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes)
-{
-    DrawTargetSkia::SetGlobalCacheLimits(aCount, aSizeInBytes);
-}
 #endif // USE_SKIA_GPU
 
 #ifdef USE_SKIA_FREETYPE
 TemporaryRef<GlyphRenderingOptions>
 Factory::CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting)
 {
   RefPtr<GlyphRenderingOptionsCairo> options =
     new GlyphRenderingOptionsCairo();
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -60,17 +60,16 @@
 #include "GLContext.h"
 #include "GLContextProvider.h"
 
 #ifdef MOZ_WIDGET_ANDROID
 #include "TexturePoolOGL.h"
 #endif
 
 #ifdef USE_SKIA
-#include "mozilla/Hal.h"
 #include "skia/SkGraphics.h"
 #endif
 
 #ifdef USE_SKIA_GPU
 #include "skia/GrContext.h"
 #include "skia/GrGLInterface.h"
 #include "GLContextSkia.h"
 #endif
@@ -282,20 +281,16 @@ gfxPlatform::gfxPlatform()
                                  false);
     Preferences::AddBoolVarCache(&mDrawBigImageBorders,
                                  "layers.draw-bigimage-borders",
                                  false);
 
     uint32_t canvasMask = (1 << BACKEND_CAIRO) | (1 << BACKEND_SKIA);
     uint32_t contentMask = 0;
     InitBackendPrefs(canvasMask, contentMask);
-
-#ifdef USE_SKIA
-    InitializeSkiaCaches();
-#endif
 }
 
 gfxPlatform*
 gfxPlatform::GetPlatform()
 {
     if (!gPlatform) {
         Init();
     }
@@ -819,49 +814,16 @@ gfxPlatform::SupportsAzureContentForDraw
 
 bool
 gfxPlatform::UseAcceleratedSkiaCanvas()
 {
   return Preferences::GetBool("gfx.canvas.azure.accelerated", false) &&
          mPreferredCanvasBackend == BACKEND_SKIA;
 }
 
-void
-gfxPlatform::InitializeSkiaCaches()
-{
-#ifdef USE_SKIA_GPU
-  if (UseAcceleratedSkiaCanvas()) {
-    bool usingDynamicCache = Preferences::GetBool("gfx.canvas.skiagl.dynamic-cache", false);
-
-    int cacheItemLimit = Preferences::GetInt("gfx.canvas.skiagl.cache-items", 256);
-    int cacheSizeLimit = Preferences::GetInt("gfx.canvas.skiagl.cache-size", 96);
-
-    // Prefs are in megabytes, but we want the sizes in bytes
-    cacheSizeLimit *= 1024*1024;
-
-    if (usingDynamicCache) {
-      uint32_t totalMemory = mozilla::hal::GetTotalSystemMemory();
-
-      if (totalMemory <= 256*1024*1024) {
-        // We need a very minimal cache on 256 meg devices
-        cacheSizeLimit = 2*1024*1024;
-      } else if (totalMemory > 0) {
-        cacheSizeLimit = totalMemory / 16;
-      }
-    }
-
-#ifdef DEBUG
-    printf_stderr("Determined SkiaGL cache limits: Size %i, Items: %i\n", cacheSizeLimit, cacheItemLimit);
-#endif
-
-    Factory::SetGlobalSkiaCacheLimits(cacheItemLimit, cacheSizeLimit);
-  }
-#endif
-}
-
 already_AddRefed<gfxASurface>
 gfxPlatform::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
 {
   if (aTarget->GetType() == BACKEND_CAIRO) {
     cairo_surface_t* csurf =
       static_cast<cairo_surface_t*>(aTarget->GetNativeSurface(NATIVE_SURFACE_CAIRO_SURFACE));
     return gfxASurface::Wrap(csurf);
   }
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -268,18 +268,16 @@ public:
     bool SupportsAzureContentForDrawTarget(mozilla::gfx::DrawTarget* aTarget);
 
     bool SupportsAzureContentForType(mozilla::gfx::BackendType aType) {
       return (1 << aType) & mContentBackendBitmask;
     }
 
     virtual bool UseAcceleratedSkiaCanvas();
 
-    virtual void InitializeSkiaCaches();
-
     void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) {
       aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend));
       aObj.DefineProperty("AzureSkiaAccelerated", UseAcceleratedSkiaCanvas());
       aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend));
       aObj.DefineProperty("AzureContentBackend", GetBackendName(mContentBackend));
     }
 
     mozilla::gfx::BackendType GetPreferredCanvasBackend() {
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -1180,17 +1180,10 @@ StartDiskSpaceWatcher()
 void
 StopDiskSpaceWatcher()
 {
   AssertMainProcess();
   AssertMainThread();
   PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
 }
 
-uint32_t
-GetTotalSystemMemory()
-{
-  return hal_impl::GetTotalSystemMemory();
-}
-
-
 } // namespace hal
 } // namespace mozilla
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -585,23 +585,16 @@ void StartDiskSpaceWatcher();
 
 /**
  * Stop monitoring disk space for low space situations.
  *
  * This API is currently only allowed to be used from the main process.
  */
 void StopDiskSpaceWatcher();
 
-/**
- * Get total system memory of device being run on in bytes.
- *
- * Returns 0 if we are unable to determine this information from /proc/meminfo.
- */
-uint32_t GetTotalSystemMemory();
-
 } // namespace MOZ_HAL_NAMESPACE
 } // namespace mozilla
 
 #ifdef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_DEFINED_HAL_NAMESPACE
 # undef MOZ_HAL_NAMESPACE
 #endif
 
deleted file mode 100644
--- a/hal/fallback/FallbackMemory.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * vim: sw=2 ts=8 et :
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "Hal.h"
-
-namespace mozilla {
-namespace hal_impl {
-
-uint32_t
-GetTotalSystemMemory()
-{
-	return 0;
-}
-
-} // namespace hal_impl
-} // namespace mozilla
deleted file mode 100644
--- a/hal/linux/LinuxMemory.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * vim: sw=2 ts=8 et :
- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include "Hal.h"
-
-namespace mozilla {
-namespace hal_impl {
-
-uint32_t
-GetTotalSystemMemory()
-{
-  static uint32_t sTotalMemory;
-  static bool sTotalMemoryObtained = false;
-
-  if (!sTotalMemoryObtained) {
-    sTotalMemoryObtained = true;
-
-    FILE* fd = fopen("/proc/meminfo", "r");
-    if (!fd) {
-      return 0;
-    }
-
-    int rv = fscanf(fd, "MemTotal: %i kB", &sTotalMemory);
-
-    if (fclose(fd) || rv != 1) {
-      return 0;
-    }
-  }
-
-  return sTotalMemory * 1024;
-}
-
-} // namespace hal_impl
-} // namespace mozilla
--- a/hal/moz.build
+++ b/hal/moz.build
@@ -45,32 +45,29 @@ elif CONFIG['MOZ_GAMEPAD_BACKEND'] == 'l
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     CPP_SOURCES += [
         'AndroidHal.cpp',
         'AndroidSensor.cpp',
         'FallbackPower.cpp',
         'FallbackAlarm.cpp',
-        'LinuxMemory.cpp',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     CPP_SOURCES += [
         'GonkHal.cpp',
-        'LinuxMemory.cpp',
         'LinuxPower.cpp',
         'GonkSensor.cpp',
         'UeventPoller.cpp',
         'GonkSwitch.cpp',
         'GonkFMRadio.cpp',
         'GonkDiskSpaceWatcher.cpp',
     ]
 elif CONFIG['OS_TARGET'] == 'Linux':
     CPP_SOURCES += [
-        'LinuxMemory.cpp',
         'LinuxPower.cpp',
         'FallbackScreenConfiguration.cpp',
         'FallbackSensor.cpp',
         'FallbackVibration.cpp',
         'FallbackAlarm.cpp',
     ]
     if CONFIG['MOZ_ENABLE_DBUS']:
         CPP_SOURCES += [
@@ -82,35 +79,32 @@ elif CONFIG['OS_TARGET'] == 'Linux':
         ]
 elif CONFIG['OS_TARGET'] == 'WINNT':
     CPP_SOURCES += [
         'WindowsBattery.cpp',
         'WindowsSensor.cpp',
         'FallbackVibration.cpp',
         'FallbackScreenConfiguration.cpp',
         'FallbackPower.cpp',
-        'FallbackMemory.cpp',
         'FallbackAlarm.cpp',
     ]
 elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     CPP_SOURCES += [
         'CocoaBattery.cpp',
         'FallbackVibration.cpp',
         'FallbackPower.cpp',
         'FallbackScreenConfiguration.cpp',
-        'FallbackMemory.cpp',
         'FallbackAlarm.cpp',
     ]
 elif CONFIG['OS_TARGET'] in ('OpenBSD', 'NetBSD', 'FreeBSD', 'DragonFly'):
     CPP_SOURCES += [
         'FallbackSensor.cpp',
         'FallbackVibration.cpp',
         'FallbackPower.cpp',
         'FallbackScreenConfiguration.cpp',
-        'FallbackMemory.cpp',
         'FallbackAlarm.cpp',
     ]
     if CONFIG['MOZ_ENABLE_DBUS']:
         CPP_SOURCES += [
             'UPowerClient.cpp'
         ]
     else:
         CPP_SOURCES += [
@@ -118,17 +112,16 @@ elif CONFIG['OS_TARGET'] in ('OpenBSD', 
         ]
 else:
     CPP_SOURCES += [
         'FallbackBattery.cpp',
         'FallbackSensor.cpp',
         'FallbackVibration.cpp',
         'FallbackPower.cpp',
         'FallbackScreenConfiguration.cpp',
-        'FallbackMemory.cpp',
         'FallbackAlarm.cpp',
     ]
 
 # Fallbacks for backends implemented on Gonk only.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
     CPP_SOURCES += [
         'FallbackLights.cpp',
         'FallbackTime.cpp',