bug 797015 - [ARMv6] Add a pref to completely disable screenshot code (including memory allocation) r=mfinkle
authorBrad Lassey <blassey@mozilla.com>
Tue, 02 Oct 2012 17:30:11 -0700
changeset 109767 f468573e0725553ad76546cd3d6ce0c22b69c6e5
parent 109766 1c6b5cae9dc164b2f18ccba4dcfd149fbea1b134
child 109768 81675e760c1229669a5e620e6ffd1f8d762882c3
push id23652
push userryanvm@gmail.com
push dateWed, 10 Oct 2012 01:10:20 +0000
treeherdermozilla-central@5cca0408a73f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs797015
milestone19.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 797015 - [ARMv6] Add a pref to completely disable screenshot code (including memory allocation) r=mfinkle
mobile/android/base/MemoryMonitor.java
mobile/android/base/ScreenshotHandler.java
--- a/mobile/android/base/MemoryMonitor.java
+++ b/mobile/android/base/MemoryMonitor.java
@@ -147,34 +147,34 @@ class MemoryMonitor extends BroadcastRec
             return;
         }
 
         // TODO hook in memory-reduction stuff for different levels here
         if (level >= MEMORY_PRESSURE_MEDIUM) {
             if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
                 GeckoAppShell.onLowMemory();
             }
-            ScreenshotHandler.disableScreenshot();
+            ScreenshotHandler.disableScreenshot(false);
             GeckoAppShell.geckoEventSync();
         }
     }
 
     private boolean decreaseMemoryPressure() {
         int newLevel;
         synchronized (this) {
             if (mMemoryPressure <= 0) {
                 return false;
             }
 
             newLevel = --mMemoryPressure;
         }
         Log.d(LOGTAG, "Decreased memory pressure to " + newLevel);
 
         if (newLevel == MEMORY_PRESSURE_NONE) {
-            ScreenshotHandler.enableScreenshot();
+            ScreenshotHandler.enableScreenshot(false);
         }
 
         return true;
     }
 
     class PressureDecrementer implements Runnable {
         private static final int DECREMENT_DELAY = 5 * 60 * 1000; // 5 minutes
 
--- a/mobile/android/base/ScreenshotHandler.java
+++ b/mobile/android/base/ScreenshotHandler.java
@@ -7,37 +7,41 @@ package org.mozilla.gecko;
 
 import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
 import org.mozilla.gecko.gfx.IntSize;
 import org.mozilla.gecko.gfx.LayerView;
 import org.mozilla.gecko.gfx.RectUtils;
 import org.mozilla.gecko.gfx.ScreenshotLayer;
 import org.mozilla.gecko.mozglue.DirectBufferAllocator;
 import org.mozilla.gecko.util.FloatUtils;
+import org.mozilla.gecko.PrefsHelper;
 
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.opengl.GLES20;
 import android.util.FloatMath;
 import android.util.Log;
 
 import java.nio.ByteBuffer;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Queue;
 
 public final class ScreenshotHandler implements Runnable {
     public static final int SCREENSHOT_THUMBNAIL = 0;
     public static final int SCREENSHOT_CHECKERBOARD = 1;
 
+    private static final String SCREENSHOT_DISABLED_PREF = "gfx.java.screenshot.enabled";
+
     private static final String LOGTAG = "GeckoScreenshotHandler";
     private static final int BYTES_FOR_16BPP = 2;
     private static final int MAX_PIXELS_PER_SLICE = 100000;
 
     private static boolean sDisableScreenshot;
+    private static boolean sForceDisabled;
     private static ScreenshotHandler sInstance;
 
     private final int mMaxTextureSize;
     private final int mMinTextureSize;
     private final int mMaxPixels;
 
     private final Queue<PendingScreenshot> mPendingScreenshots;
     private ByteBuffer mBuffer;
@@ -75,48 +79,67 @@ public final class ScreenshotHandler imp
             throw new UnsupportedOperationException();
         }
         mMaxPixels = Math.min(ScreenshotLayer.getMaxNumPixels(), mMaxTextureSize * mMaxTextureSize);
         mMinTextureSize = (int)Math.ceil(mMaxPixels / mMaxTextureSize);
         mPendingScreenshots = new LinkedList<PendingScreenshot>();
         mBuffer = DirectBufferAllocator.allocate(mMaxPixels * BYTES_FOR_16BPP);
         mDirtyRect = new RectF();
         clearDirtyRect();
+        PrefsHelper.getPref(SCREENSHOT_DISABLED_PREF,
+             new PrefsHelper.PrefHandlerBase() {
+                  @Override public void prefValue(String pref, boolean value) {
+                      if (SCREENSHOT_DISABLED_PREF.equals(pref) && !value)
+                          disableScreenshot(true);
+                  }
+             }
+            );
     }
 
     private void cleanup() {
         synchronized (mPendingScreenshots) {
             if (mPendingScreenshots.isEmpty()) {
                 // no screenshots are pending, its safe to free the buffer
                 mBuffer = DirectBufferAllocator.free(mBuffer);
             } else {
                 discardPendingScreenshots();
                 mBuffer = null;
             }
         }
     }
 
     // Invoked via reflection from robocop test
     public static synchronized void disableScreenshot() {
+        disableScreenshot(true);
+    }
+
+    // Invoked via reflection from robocop test
+    public static synchronized void disableScreenshot(boolean forced) {
         if (sDisableScreenshot) {
+            if (!sForceDisabled)
+                sForceDisabled = forced;
             return;
         }
+
+        sForceDisabled = forced;
+
         sDisableScreenshot = true;
         if (sInstance != null) {
             sInstance.cleanup();
             sInstance = null;
         }
         Log.i(LOGTAG, "Screenshotting disabled");
     }
 
-    public static synchronized void enableScreenshot() {
-        if (!sDisableScreenshot) {
+    public static synchronized void enableScreenshot(boolean forced) {
+        if (!sDisableScreenshot || (sForceDisabled && !forced)) {
             return;
         }
         sDisableScreenshot = false;
+        sForceDisabled = false;
         Log.i(LOGTAG, "Screenshotting enabled");
     }
 
     public static void screenshotWholePage(Tab tab) {
         if (GeckoApp.mAppContext.isApplicationInBackground()) {
             return;
         }
         ScreenshotHandler handler = getInstance();