mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-17 09:37:50 +01:00
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:
parent
b7be2823ab
commit
62008f45c7
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user