DroidFish: Draw pictures in off-screen bitmaps to prevent crash when "Force GPU rendering" is enabled in android developer options.

This commit is contained in:
Peter Osterlund 2012-06-15 22:06:42 +00:00
parent b7be2823ab
commit 62008f45c7

View File

@ -2,8 +2,11 @@ package org.petero.droidfish;
import com.larvalabs.svgandroid.SVG;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.PictureDrawable;
/**
@ -13,6 +16,9 @@ public class SVGPictureDrawable extends PictureDrawable {
private final int iWidth;
private final int iHeight;
private Rect cachedBounds;
private Bitmap cachedBitmap;
public SVGPictureDrawable(SVG svg) {
super(svg.getPicture());
@ -42,6 +48,14 @@ public class SVGPictureDrawable extends PictureDrawable {
@Override
public void draw(Canvas canvas) {
canvas.drawPicture(getPicture(), getBounds());
Rect b = getBounds();
if (!b.equals(cachedBounds)) {
Bitmap bm = Bitmap.createBitmap(b.right-b.left, b.bottom-b.top, Bitmap.Config.ARGB_8888);
Canvas bmCanvas = new Canvas(bm);
bmCanvas.drawPicture(getPicture(), getBounds());
cachedBitmap = bm;
cachedBounds = b;
}
canvas.drawBitmap(cachedBitmap, null, b, null);
}
}