Эх сурвалжийг харах

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

Mario Zechner 11 сар өмнө
parent
commit
7994973a22

+ 13 - 2
spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SkeletonRenderer.java

@@ -49,6 +49,7 @@ import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 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
  * render them to a {@link Canvas}. */
@@ -246,8 +247,18 @@ public class SkeletonRenderer {
 		for (int i = 0; i < commands.size; i++) {
 			RenderCommand command = commands.get(i);
 
-			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));
+			if (Build.VERSION.SDK_INT >= 29) {
+				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));
+			}
 		}
 	}
 

+ 5 - 0
spine-android/spine-android/src/main/java/com/esotericsoftware/spine/android/SpineView.java

@@ -40,6 +40,7 @@ import com.esotericsoftware.spine.Skeleton;
 
 import android.content.Context;
 import android.graphics.Canvas;
+import android.os.Build;
 import android.os.Handler;
 import android.os.Looper;
 import android.util.AttributeSet;
@@ -187,6 +188,10 @@ public class SpineView extends View implements Choreographer.FrameCallback {
 	public SpineView (Context context, SpineController controller) {
 		super(context);
 		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