[android] Fix Canvas.drawVertices() for Android <= 9. Closes #2638

This commit is contained in:
Mario Zechner 2024-10-01 15:28:53 +02:00
parent fb1cd5e161
commit 7994973a22
2 changed files with 18 additions and 2 deletions

View File

@ -49,6 +49,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.RectF; import android.graphics.RectF;
import android.os.Build;
/** Is responsible to transform the {@link Skeleton} with its current pose to {@link SkeletonRenderer.RenderCommand} commands and /** Is responsible to transform the {@link Skeleton} with its current pose to {@link SkeletonRenderer.RenderCommand} commands and
* render them to a {@link Canvas}. */ * render them to a {@link Canvas}. */
@ -246,8 +247,18 @@ public class SkeletonRenderer {
for (int i = 0; i < commands.size; i++) { for (int i = 0; i < commands.size; i++) {
RenderCommand command = commands.get(i); RenderCommand command = commands.get(i);
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0, if (Build.VERSION.SDK_INT >= 29) {
command.colors.items, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode)); canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0,
command.colors.items, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode));
} else {
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2638
int[] colors = command.colors.items;
int[] colorsCopy = new int[command.vertices.size];
System.arraycopy(colors, 0, colorsCopy, 0, command.colors.size);
canvas.drawVertices(Canvas.VertexMode.TRIANGLES, command.vertices.size, command.vertices.items, 0, command.uvs.items, 0,
colorsCopy, 0, command.indices.items, 0, command.indices.size, command.texture.getPaint(command.blendMode));
}
} }
} }

View File

@ -40,6 +40,7 @@ import com.esotericsoftware.spine.Skeleton;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -187,6 +188,10 @@ public class SpineView extends View implements Choreographer.FrameCallback {
public SpineView (Context context, SpineController controller) { public SpineView (Context context, SpineController controller) {
super(context); super(context);
this.controller = controller; this.controller = controller;
// See https://github.com/EsotericSoftware/spine-runtimes/issues/2638
if (Build.VERSION.SDK_INT < 29) {
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
} }
/** Constructs a new {@link SpineView} without providing a {@link SpineController}, which you need to provide using /** Constructs a new {@link SpineView} without providing a {@link SpineController}, which you need to provide using