bug 797015 - [ARMv6] Add a pref to completely disable screenshot code (including memory allocation) r=mfinkle

This commit is contained in:
Brad Lassey 2012-10-02 17:30:11 -07:00
Родитель 176f990f84
Коммит dbe5a35414
2 изменённых файлов: 27 добавлений и 4 удалений

Просмотреть файл

@ -152,7 +152,7 @@ class MemoryMonitor extends BroadcastReceiver {
if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) { if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
GeckoAppShell.onLowMemory(); GeckoAppShell.onLowMemory();
} }
ScreenshotHandler.disableScreenshot(); ScreenshotHandler.disableScreenshot(false);
GeckoAppShell.geckoEventSync(); GeckoAppShell.geckoEventSync();
} }
} }
@ -169,7 +169,7 @@ class MemoryMonitor extends BroadcastReceiver {
Log.d(LOGTAG, "Decreased memory pressure to " + newLevel); Log.d(LOGTAG, "Decreased memory pressure to " + newLevel);
if (newLevel == MEMORY_PRESSURE_NONE) { if (newLevel == MEMORY_PRESSURE_NONE) {
ScreenshotHandler.enableScreenshot(); ScreenshotHandler.enableScreenshot(false);
} }
return true; return true;

Просмотреть файл

@ -12,6 +12,7 @@ import org.mozilla.gecko.gfx.RectUtils;
import org.mozilla.gecko.gfx.ScreenshotLayer; import org.mozilla.gecko.gfx.ScreenshotLayer;
import org.mozilla.gecko.mozglue.DirectBufferAllocator; import org.mozilla.gecko.mozglue.DirectBufferAllocator;
import org.mozilla.gecko.util.FloatUtils; import org.mozilla.gecko.util.FloatUtils;
import org.mozilla.gecko.PrefsHelper;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.RectF; 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_THUMBNAIL = 0;
public static final int SCREENSHOT_CHECKERBOARD = 1; 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 String LOGTAG = "GeckoScreenshotHandler";
private static final int BYTES_FOR_16BPP = 2; private static final int BYTES_FOR_16BPP = 2;
private static final int MAX_PIXELS_PER_SLICE = 100000; private static final int MAX_PIXELS_PER_SLICE = 100000;
private static boolean sDisableScreenshot; private static boolean sDisableScreenshot;
private static boolean sForceDisabled;
private static ScreenshotHandler sInstance; private static ScreenshotHandler sInstance;
private final int mMaxTextureSize; private final int mMaxTextureSize;
@ -80,6 +84,14 @@ public final class ScreenshotHandler implements Runnable {
mBuffer = DirectBufferAllocator.allocate(mMaxPixels * BYTES_FOR_16BPP); mBuffer = DirectBufferAllocator.allocate(mMaxPixels * BYTES_FOR_16BPP);
mDirtyRect = new RectF(); mDirtyRect = new RectF();
clearDirtyRect(); 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() { private void cleanup() {
@ -96,9 +108,19 @@ public final class ScreenshotHandler implements Runnable {
// Invoked via reflection from robocop test // Invoked via reflection from robocop test
public static synchronized void disableScreenshot() { public static synchronized void disableScreenshot() {
disableScreenshot(true);
}
// Invoked via reflection from robocop test
public static synchronized void disableScreenshot(boolean forced) {
if (sDisableScreenshot) { if (sDisableScreenshot) {
if (!sForceDisabled)
sForceDisabled = forced;
return; return;
} }
sForceDisabled = forced;
sDisableScreenshot = true; sDisableScreenshot = true;
if (sInstance != null) { if (sInstance != null) {
sInstance.cleanup(); sInstance.cleanup();
@ -107,11 +129,12 @@ public final class ScreenshotHandler implements Runnable {
Log.i(LOGTAG, "Screenshotting disabled"); Log.i(LOGTAG, "Screenshotting disabled");
} }
public static synchronized void enableScreenshot() { public static synchronized void enableScreenshot(boolean forced) {
if (!sDisableScreenshot) { if (!sDisableScreenshot || (sForceDisabled && !forced)) {
return; return;
} }
sDisableScreenshot = false; sDisableScreenshot = false;
sForceDisabled = false;
Log.i(LOGTAG, "Screenshotting enabled"); Log.i(LOGTAG, "Screenshotting enabled");
} }