VectorDrawable: add an override to avoid intermediate rasterization

This matters for statically converting drawables into SVG,
which is necessary for drawable-based app icons.
This commit is contained in:
Mis012
2025-06-21 01:15:48 +02:00
parent 6031eecefc
commit 1c83948b15

View File

@@ -811,6 +811,9 @@ class PathParser {
public class VectorDrawable extends Drawable { public class VectorDrawable extends Drawable {
private static final String LOGTAG = VectorDrawable.class.getSimpleName(); private static final String LOGTAG = VectorDrawable.class.getSimpleName();
/* don't use an intermediary bitmap (for making an SVG) */
static boolean direct_draw_override = false;
private static final String SHAPE_CLIP_PATH = "clip-path"; private static final String SHAPE_CLIP_PATH = "clip-path";
private static final String SHAPE_GROUP = "group"; private static final String SHAPE_GROUP = "group";
private static final String SHAPE_PATH = "path"; private static final String SHAPE_PATH = "path";
@@ -939,16 +942,20 @@ public class VectorDrawable extends Drawable {
// we offset to (0, 0); // we offset to (0, 0);
mTmpBounds.offsetTo(0, 0); mTmpBounds.offsetTo(0, 0);
mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight); if (direct_draw_override) {
if (!mAllowCaching) { mVectorState.mVPathRenderer.draw(canvas, scaledWidth, scaledHeight, null);
mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
} else { } else {
if (!mVectorState.canReuseCache()) { mVectorState.createCachedBitmapIfNeeded(scaledWidth, scaledHeight);
if (!mAllowCaching) {
mVectorState.updateCachedBitmap(scaledWidth, scaledHeight); mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
mVectorState.updateCacheStates(); } else {
if (!mVectorState.canReuseCache()) {
mVectorState.updateCachedBitmap(scaledWidth, scaledHeight);
mVectorState.updateCacheStates();
}
} }
mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
} }
mVectorState.drawCachedBitmapWithRootAlpha(canvas, colorFilter, mTmpBounds);
canvas.restoreToCount(saveCount); canvas.restoreToCount(saveCount);
} }