bug 748621 - planet.mozilla.org always shows black checkerboard r=BenWa

This commit is contained in:
Brad Lassey
2012-04-24 21:39:10 -04:00
parent 95f173f367
commit 6854080c9f

View File

@@ -73,6 +73,7 @@ import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.provider.Settings; import android.provider.Settings;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.opengl.GLES20;
import android.util.*; import android.util.*;
import android.net.Uri; import android.net.Uri;
@@ -129,6 +130,7 @@ public class GeckoAppShell
private static float sCheckerboardPageWidth, sCheckerboardPageHeight; private static float sCheckerboardPageWidth, sCheckerboardPageHeight;
private static float sLastCheckerboardWidthRatio, sLastCheckerboardHeightRatio; private static float sLastCheckerboardWidthRatio, sLastCheckerboardHeightRatio;
private static RepaintRunnable sRepaintRunnable = new RepaintRunnable(); private static RepaintRunnable sRepaintRunnable = new RepaintRunnable();
static private int sMaxTextureSize = 0;
private static Map<String, CopyOnWriteArrayList<GeckoEventListener>> mEventListeners private static Map<String, CopyOnWriteArrayList<GeckoEventListener>> mEventListeners
= new HashMap<String, CopyOnWriteArrayList<GeckoEventListener>>(); = new HashMap<String, CopyOnWriteArrayList<GeckoEventListener>>();
@@ -2202,17 +2204,34 @@ public class GeckoAppShell
sRepaintRunnable.addRectToRepaint(top, left, bottom, right); sRepaintRunnable.addRectToRepaint(top, left, bottom, right);
} }
private static int clamp(int min, int val, int max) {
return Math.max(Math.min(max, val), min);
}
public static void screenshotWholePage(Tab tab) { public static void screenshotWholePage(Tab tab) {
if (sMaxTextureSize == 0) {
int[] maxTextureSize = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
sMaxTextureSize = maxTextureSize[0];
if (sMaxTextureSize == 0)
return;
}
ImmutableViewportMetrics viewport = GeckoApp.mAppContext.getLayerController().getViewportMetrics(); ImmutableViewportMetrics viewport = GeckoApp.mAppContext.getLayerController().getViewportMetrics();
// source width and height to screenshot // source width and height to screenshot
float sw = viewport.pageSizeWidth; float sw = viewport.pageSizeWidth;
float sh = viewport.pageSizeHeight; float sh = viewport.pageSizeHeight;
int maxPixels = Math.min(ScreenshotLayer.getMaxNumPixels(), sMaxTextureSize * sMaxTextureSize);
// 2Mb of 16bit image data // 2Mb of 16bit image data
// may be bumped by up to 4x for power of 2 alignment // may be bumped by up to 4x for power of 2 alignment
float ratio = (float)Math.sqrt((sw * sh) / (ScreenshotLayer.getMaxNumPixels() / 4)); float idealZoomFactor = (float)Math.sqrt((sw * sh) / (maxPixels / 4));
// destination width and hight
int dw = IntSize.nextPowerOfTwo(sw / ratio); // calc destination width and hight
int dh = IntSize.nextPowerOfTwo(sh / ratio); int idealDstWidth = IntSize.nextPowerOfTwo(sw / idealZoomFactor);
// min texture size such that the other dimention doesn't excede the max
int minTextureSize = maxPixels / sMaxTextureSize;
int dw = clamp(minTextureSize, idealDstWidth, sMaxTextureSize);
int dh = maxPixels / dw;
sLastCheckerboardWidthRatio = dw / sw; sLastCheckerboardWidthRatio = dw / sw;
sLastCheckerboardHeightRatio = dh / sh; sLastCheckerboardHeightRatio = dh / sh;
sCheckerboardPageWidth = viewport.pageSizeWidth; sCheckerboardPageWidth = viewport.pageSizeWidth;