mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-15 10:22:40 +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:
@@ -2,8 +2,11 @@ package org.petero.droidfish;
|
|||||||
|
|
||||||
import com.larvalabs.svgandroid.SVG;
|
import com.larvalabs.svgandroid.SVG;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.PictureDrawable;
|
import android.graphics.drawable.PictureDrawable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,6 +16,9 @@ public class SVGPictureDrawable extends PictureDrawable {
|
|||||||
|
|
||||||
private final int iWidth;
|
private final int iWidth;
|
||||||
private final int iHeight;
|
private final int iHeight;
|
||||||
|
|
||||||
|
private Rect cachedBounds;
|
||||||
|
private Bitmap cachedBitmap;
|
||||||
|
|
||||||
public SVGPictureDrawable(SVG svg) {
|
public SVGPictureDrawable(SVG svg) {
|
||||||
super(svg.getPicture());
|
super(svg.getPicture());
|
||||||
@@ -42,6 +48,14 @@ public class SVGPictureDrawable extends PictureDrawable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user