From ce3488035846047de80b921dade32edc7f350016 Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Tue, 2 Oct 2012 17:30:11 -0700 Subject: [PATCH] bug 797015 - [ARMv6] Add a pref to completely disable screenshot code (including memory allocation) r=mfinkle --- mobile/android/base/MemoryMonitor.java | 4 ++-- mobile/android/base/ScreenshotHandler.java | 27 ++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/MemoryMonitor.java b/mobile/android/base/MemoryMonitor.java index 1bbda53bf2e..31d10964ca0 100644 --- a/mobile/android/base/MemoryMonitor.java +++ b/mobile/android/base/MemoryMonitor.java @@ -152,7 +152,7 @@ class MemoryMonitor extends BroadcastReceiver { if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) { GeckoAppShell.onLowMemory(); } - ScreenshotHandler.disableScreenshot(); + ScreenshotHandler.disableScreenshot(false); GeckoAppShell.geckoEventSync(); } } @@ -169,7 +169,7 @@ class MemoryMonitor extends BroadcastReceiver { Log.d(LOGTAG, "Decreased memory pressure to " + newLevel); if (newLevel == MEMORY_PRESSURE_NONE) { - ScreenshotHandler.enableScreenshot(); + ScreenshotHandler.enableScreenshot(false); } return true; diff --git a/mobile/android/base/ScreenshotHandler.java b/mobile/android/base/ScreenshotHandler.java index 25c71719845..e5bc348b26c 100644 --- a/mobile/android/base/ScreenshotHandler.java +++ b/mobile/android/base/ScreenshotHandler.java @@ -12,6 +12,7 @@ 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; @@ -28,11 +29,14 @@ 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; @@ -80,6 +84,14 @@ public final class ScreenshotHandler implements Runnable { 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() { @@ -96,9 +108,19 @@ public final class ScreenshotHandler implements Runnable { // 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(); @@ -107,11 +129,12 @@ public final class ScreenshotHandler implements Runnable { 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"); }