Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render G offscreen only when it's needed (opacity != 1) #2450

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions android/src/main/java/com/horcrux/svg/GroupView.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,24 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
final SvgView svg = getSvgView();
final GroupView self = this;
final RectF groupRect = new RectF();
if (mLayerBitmap == null) {
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas = new Canvas(mLayerBitmap);

if (mOpacity != 1) {
if (mLayerBitmap == null) {
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas = new Canvas(mLayerBitmap);
} else {
mLayerBitmap.recycle();
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas.setBitmap(mLayerBitmap);
}
// Copy current matrix from original canvas
mLayerCanvas.save();
mLayerCanvas.setMatrix(canvas.getMatrix());
} else {
mLayerBitmap.recycle();
mLayerBitmap =
Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
mLayerCanvas.setBitmap(mLayerBitmap);
mLayerCanvas = canvas;
}
// Copy current matrix from original canvas
int saveCount = mLayerCanvas.save();
mLayerCanvas.setMatrix(canvas.getMatrix());

elements = new ArrayList<>();
for (int i = 0; i < getChildCount(); i++) {
Expand Down Expand Up @@ -157,13 +162,15 @@ void drawGroup(final Canvas canvas, final Paint paint, final float opacity) {
}
}

// Restore copied canvas and temporary reset original canvas matrix to draw bitmap 1:1
mLayerCanvas.restoreToCount(saveCount);
saveCount = canvas.save();
canvas.setMatrix(null);
mLayerPaint.setAlpha((int) (mOpacity * 255));
canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint);
canvas.restoreToCount(saveCount);
if (mOpacity != 1) {
// Restore copied canvas and temporary reset original canvas matrix to draw bitmap 1:1
mLayerCanvas.restore();
int saveCount = canvas.save();
canvas.setMatrix(null);
mLayerPaint.setAlpha((int) (mOpacity * 255));
canvas.drawBitmap(mLayerBitmap, 0, 0, mLayerPaint);
canvas.restoreToCount(saveCount);
}
this.setClientRect(groupRect);
popGlyphContext();
}
Expand Down
Loading