Address drawMesh API feedback

Added annotations where appropriate, updated documentation, and made
Mesh factory methods into constructors.

Bug: b/265855122
Test: atest CtsUiRenderingTestCases:MeshTest
Change-Id: Ic06821ea40750d40882f1dc6acd0a21dae76b7ab
diff --git a/core/api/current.txt b/core/api/current.txt
index d3de158..d6be2d2 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -15009,7 +15009,7 @@
     method public void drawLine(float, float, float, float, @NonNull android.graphics.Paint);
     method public void drawLines(@NonNull @Size(multiple=4) float[], int, int, @NonNull android.graphics.Paint);
     method public void drawLines(@NonNull @Size(multiple=4) float[], @NonNull android.graphics.Paint);
-    method public void drawMesh(@NonNull android.graphics.Mesh, android.graphics.BlendMode, @NonNull android.graphics.Paint);
+    method public void drawMesh(@NonNull android.graphics.Mesh, @Nullable android.graphics.BlendMode, @NonNull android.graphics.Paint);
     method public void drawOval(@NonNull android.graphics.RectF, @NonNull android.graphics.Paint);
     method public void drawOval(float, float, float, float, @NonNull android.graphics.Paint);
     method public void drawPaint(@NonNull android.graphics.Paint);
@@ -15611,10 +15611,10 @@
   }
 
   public class Mesh {
-    method @NonNull public static android.graphics.Mesh make(@NonNull android.graphics.MeshSpecification, int, @NonNull java.nio.Buffer, int, @NonNull android.graphics.Rect);
-    method @NonNull public static android.graphics.Mesh makeIndexed(@NonNull android.graphics.MeshSpecification, int, @NonNull java.nio.Buffer, int, @NonNull java.nio.ShortBuffer, @NonNull android.graphics.Rect);
-    method public void setColorUniform(@NonNull String, int);
-    method public void setColorUniform(@NonNull String, long);
+    ctor public Mesh(@NonNull android.graphics.MeshSpecification, int, @NonNull java.nio.Buffer, int, @NonNull android.graphics.Rect);
+    ctor public Mesh(@NonNull android.graphics.MeshSpecification, int, @NonNull java.nio.Buffer, int, @NonNull java.nio.ShortBuffer, @NonNull android.graphics.Rect);
+    method public void setColorUniform(@NonNull String, @ColorInt int);
+    method public void setColorUniform(@NonNull String, @ColorLong long);
     method public void setColorUniform(@NonNull String, @NonNull android.graphics.Color);
     method public void setFloatUniform(@NonNull String, float);
     method public void setFloatUniform(@NonNull String, float, float);
diff --git a/graphics/java/android/graphics/BaseCanvas.java b/graphics/java/android/graphics/BaseCanvas.java
index 8cd8ddf..a7acaf9 100644
--- a/graphics/java/android/graphics/BaseCanvas.java
+++ b/graphics/java/android/graphics/BaseCanvas.java
@@ -675,10 +675,11 @@
      *
      * @param mesh {@link Mesh} object that will be drawn to the screen
      * @param blendMode {@link BlendMode} used to blend mesh primitives as the destination color
-     *            with the Paint color/shader as the source color.
+     *            with the Paint color/shader as the source color. This defaults to
+     *            {@link BlendMode#MODULATE} if null.
      * @param paint {@link Paint} used to provide a color/shader/blend mode.
      */
-    public void drawMesh(@NonNull Mesh mesh, BlendMode blendMode, @NonNull Paint paint) {
+    public void drawMesh(@NonNull Mesh mesh, @Nullable BlendMode blendMode, @NonNull Paint paint) {
         if (!isHardwareAccelerated() && onHwFeatureInSwMode()) {
             throw new RuntimeException("software rendering doesn't support meshes");
         }
diff --git a/graphics/java/android/graphics/Mesh.java b/graphics/java/android/graphics/Mesh.java
index a599b2c..ce673ce 100644
--- a/graphics/java/android/graphics/Mesh.java
+++ b/graphics/java/android/graphics/Mesh.java
@@ -16,6 +16,8 @@
 
 package android.graphics;
 
+import android.annotation.ColorInt;
+import android.annotation.ColorLong;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 
@@ -27,10 +29,8 @@
 /**
  * Class representing a mesh object.
  *
- * This class generates Mesh objects via the
- * {@link #make(MeshSpecification, int, Buffer, int, Rect)} and
- * {@link #makeIndexed(MeshSpecification, int, Buffer, int, ShortBuffer, Rect)} methods,
- * where a {@link MeshSpecification} is required along with various attributes for
+ * This class represents a Mesh object that can optionally be indexed.
+ * A {@link MeshSpecification} is required along with various attributes for
  * detailing the mesh object, including a mode, vertex buffer, optional index buffer, and bounds
  * for the mesh. Once generated, a mesh object can be drawn through
  * {@link Canvas#drawMesh(Mesh, BlendMode, Paint)}
@@ -62,7 +62,7 @@
     }
 
     /**
-     * Generates a {@link Mesh} object.
+     * Constructor for a non-indexed Mesh.
      *
      * @param meshSpec     {@link MeshSpecification} used when generating the mesh.
      * @param mode         Determines what mode to draw the mesh in. Must be one of
@@ -74,10 +74,8 @@
      *                     backed buffer generated.
      * @param vertexCount  the number of vertices represented in the vertexBuffer and mesh.
      * @param bounds       bounds of the mesh object.
-     * @return a new Mesh object.
      */
-    @NonNull
-    public static Mesh make(@NonNull MeshSpecification meshSpec, @Mode int mode,
+    public Mesh(@NonNull MeshSpecification meshSpec, @Mode int mode,
             @NonNull Buffer vertexBuffer, int vertexCount, @NonNull Rect bounds) {
         if (mode != TRIANGLES && mode != TRIANGLE_STRIP) {
             throw new IllegalArgumentException("Invalid value passed in for mode parameter");
@@ -88,11 +86,12 @@
         if (nativeMesh == 0) {
             throw new IllegalArgumentException("Mesh construction failed.");
         }
-        return new Mesh(nativeMesh, false);
+
+        meshSetup(nativeMesh, false);
     }
 
     /**
-     * Generates a {@link Mesh} object.
+     * Constructor for an indexed Mesh.
      *
      * @param meshSpec     {@link MeshSpecification} used when generating the mesh.
      * @param mode         Determines what mode to draw the mesh in. Must be one of
@@ -108,10 +107,8 @@
      *                     currently implementation will have a CPU
      *                     backed buffer generated.
      * @param bounds       bounds of the mesh object.
-     * @return a new Mesh object.
      */
-    @NonNull
-    public static Mesh makeIndexed(@NonNull MeshSpecification meshSpec, @Mode int mode,
+    public Mesh(@NonNull MeshSpecification meshSpec, @Mode int mode,
             @NonNull Buffer vertexBuffer, int vertexCount, @NonNull ShortBuffer indexBuffer,
             @NonNull Rect bounds) {
         if (mode != TRIANGLES && mode != TRIANGLE_STRIP) {
@@ -124,7 +121,8 @@
         if (nativeMesh == 0) {
             throw new IllegalArgumentException("Mesh construction failed.");
         }
-        return new Mesh(nativeMesh, true);
+
+        meshSetup(nativeMesh, true);
     }
 
     /**
@@ -137,7 +135,7 @@
      * @param color       the provided sRGB color will be converted into the shader program's output
      *                    colorspace and be available as a vec4 uniform in the program.
      */
-    public void setColorUniform(@NonNull String uniformName, int color) {
+    public void setColorUniform(@NonNull String uniformName, @ColorInt int color) {
         setUniform(uniformName, Color.valueOf(color).getComponents(), true);
     }
 
@@ -151,7 +149,7 @@
      * @param color       the provided sRGB color will be converted into the shader program's output
      *                    colorspace and be available as a vec4 uniform in the program.
      */
-    public void setColorUniform(@NonNull String uniformName, long color) {
+    public void setColorUniform(@NonNull String uniformName, @ColorLong long color) {
         Color exSRGB = Color.valueOf(color).convert(ColorSpace.get(ColorSpace.Named.EXTENDED_SRGB));
         setUniform(uniformName, exSRGB.getComponents(), true);
     }
@@ -357,7 +355,7 @@
                 mNativeMeshWrapper, uniformName, value1, value2, value3, value4, count);
     }
 
-    private Mesh(long nativeMeshWrapper, boolean isIndexed) {
+    private void meshSetup(long nativeMeshWrapper, boolean isIndexed) {
         mNativeMeshWrapper = nativeMeshWrapper;
         this.mIsIndexed = isIndexed;
         MeshHolder.MESH_SPECIFICATION_REGISTRY.registerNativeAllocation(this, mNativeMeshWrapper);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/MeshActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/MeshActivity.java
index d3a5885..0f97bb2 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/MeshActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/MeshActivity.java
@@ -64,7 +64,7 @@
             vertexBuffer.put(4, 0.0f);
             vertexBuffer.put(5, 400.0f);
             vertexBuffer.rewind();
-            Mesh mesh = Mesh.make(
+            Mesh mesh = new Mesh(
                     meshSpec, Mesh.TRIANGLES, vertexBuffer, 3, new Rect(0, 0, 1000, 1000));
 
             canvas.drawMesh(mesh, BlendMode.COLOR, new Paint());
@@ -98,7 +98,7 @@
             }
             iVertexBuffer.rewind();
             indexBuffer.rewind();
-            Mesh mesh2 = Mesh.makeIndexed(meshSpec, Mesh.TRIANGLES, iVertexBuffer, 102, indexBuffer,
+            Mesh mesh2 = new Mesh(meshSpec, Mesh.TRIANGLES, iVertexBuffer, 102, indexBuffer,
                     new Rect(0, 0, 1000, 1000));
             Paint paint = new Paint();
             paint.setColor(Color.RED);
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/MeshLargeActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/MeshLargeActivity.java
index f97d942..bb296cc 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/MeshLargeActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/MeshLargeActivity.java
@@ -109,7 +109,7 @@
             }
             vertexBuffer.rewind();
             indexBuffer.rewind();
-            Mesh mesh = Mesh.makeIndexed(
+            Mesh mesh = new Mesh(
                     meshSpec, Mesh.TRIANGLES, vertexBuffer, numTriangles + 2, indexBuffer,
                     new Rect(0, 0, 1000, 1000)
             );