switch over to SkVertices object, and stop using deprecated methods.

This allows Skia to remove
  SK_SUPPORT_LEGACY_CANVAS_VERTICES
  SK_SUPPORT_LEGACY_BITMAP_SETPIXELREF
  SK_SUPPORT_LEGACY_PIXELREFFACTORY

Test: Existing CTS cover these changes

Running CtsGraphicsTestCases, there were 6 failures w/ and w/o this CL.
None of the 6 seems related to this CL.

Change-Id: I724082357d9f6cb699770df3c0b9ef555b957697
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 3dc1be6..2ee4dec 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -209,8 +209,7 @@
         }
 
         mBitmap->reconfigure(info, bitmap->rowBytes(), ctable);
-        mBitmap->ref();
-        bitmap->setPixelRef(mBitmap)->unref();
+        bitmap->setPixelRef(sk_ref_sp(mBitmap), 0, 0);
 
         // since we're already allocated, we lockPixels right away
         // HeapAllocator behaves this way too
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index e66587a..113bc19 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -516,8 +516,7 @@
         // skbug.com/4538: We also need to make sure that the rowBytes on the pixel ref
         //                 match the rowBytes on the bitmap.
         bitmap->setInfo(bitmap->info(), rowBytes);
-        mRecycledBitmap->ref();
-        bitmap->setPixelRef(mRecycledBitmap)->unref();
+        bitmap->setPixelRef(sk_ref_sp(mRecycledBitmap), 0, 0);
 
         // Make sure that the recycled bitmap has the correct alpha type.
         mRecycledBitmap->setAlphaType(bitmap->alphaType());
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index 253daaa..c0f719e 100644
--- a/core/jni/android_graphics_Canvas.cpp
+++ b/core/jni/android_graphics_Canvas.cpp
@@ -28,6 +28,7 @@
 #include "SkDrawFilter.h"
 #include "SkGraphics.h"
 #include "SkRegion.h"
+#include "SkVertices.h"
 
 namespace android {
 
@@ -311,15 +312,15 @@
 }
 
 static void drawVertices(JNIEnv* env, jobject, jlong canvasHandle,
-                         jint modeHandle, jint vertexCount,
+                         jint modeHandle, jint floatCount,
                          jfloatArray jverts, jint vertIndex,
                          jfloatArray jtexs, jint texIndex,
                          jintArray jcolors, jint colorIndex,
                          jshortArray jindices, jint indexIndex,
                          jint indexCount, jlong paintHandle) {
-    AutoJavaFloatArray  vertA(env, jverts, vertIndex + vertexCount);
-    AutoJavaFloatArray  texA(env, jtexs, texIndex + vertexCount);
-    AutoJavaIntArray    colorA(env, jcolors, colorIndex + vertexCount);
+    AutoJavaFloatArray  vertA(env, jverts, vertIndex + floatCount);
+    AutoJavaFloatArray  texA(env, jtexs, texIndex + floatCount);
+    AutoJavaIntArray    colorA(env, jcolors, colorIndex + floatCount);
     AutoJavaShortArray  indexA(env, jindices, indexIndex + indexCount);
 
     const float* verts = vertA.ptr() + vertIndex;
@@ -334,10 +335,15 @@
         indices = (const uint16_t*)(indexA.ptr() + indexIndex);
     }
 
-    SkCanvas::VertexMode mode = static_cast<SkCanvas::VertexMode>(modeHandle);
+    int vertexCount = floatCount >> 1;  // 2 floats per SkPoint
+    SkVertices::VertexMode mode = static_cast<SkVertices::VertexMode>(modeHandle);
     const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
-    get_canvas(canvasHandle)->drawVertices(mode, vertexCount, verts, texs, colors,
-                                           indices, indexCount, *paint);
+    get_canvas(canvasHandle)->drawVertices(SkVertices::MakeCopy(mode, vertexCount,
+                                           reinterpret_cast<const SkPoint*>(verts),
+                                           reinterpret_cast<const SkPoint*>(texs),
+                                           reinterpret_cast<const SkColor*>(colors),
+                                           indexCount, indices).get(),
+                                           SkBlendMode::kModulate, *paint);
 }
 
 static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,
diff --git a/libs/hwui/RecordingCanvas.h b/libs/hwui/RecordingCanvas.h
index 682f244..ccdb4b0 100644
--- a/libs/hwui/RecordingCanvas.h
+++ b/libs/hwui/RecordingCanvas.h
@@ -168,9 +168,7 @@
     virtual void drawArc(float left, float top, float right, float bottom,
             float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
     virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
-    virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
-            const float* verts, const float* tex, const int* colors,
-            const uint16_t* indices, int indexCount, const SkPaint& paint) override
+    virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override
         { /* RecordingCanvas does not support drawVertices(); ignore */ }
 
     virtual void drawVectorDrawable(VectorDrawableRoot* tree) override;
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index d344528..434e01d 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -515,17 +515,8 @@
     mCanvas->drawPath(path, paint);
 }
 
-void SkiaCanvas::drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
-                              const float* verts, const float* texs, const int* colors,
-                              const uint16_t* indices, int indexCount, const SkPaint& paint) {
-#ifndef SK_SCALAR_IS_FLOAT
-    SkDEBUGFAIL("SkScalar must be a float for these conversions to be valid");
-#endif
-    const int ptCount = vertexCount >> 1;
-    mCanvas->drawVertices(SkVertices::MakeCopy(vertexMode, ptCount, (SkPoint*)verts,
-                                               (SkPoint*)texs, (SkColor*)colors,
-                                               indexCount, indices),
-                          SkBlendMode::kModulate, paint);
+void SkiaCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
+    mCanvas->drawVertices(vertices, mode, paint);
 }
 
 // ----------------------------------------------------------------------------
@@ -566,7 +557,7 @@
     if (colors) {
         flags |= SkVertices::kHasColors_BuilderFlag;
     }
-    SkVertices::Builder builder(SkCanvas::kTriangles_VertexMode, ptCount, indexCount, flags);
+    SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, ptCount, indexCount, flags);
     memcpy(builder.positions(), vertices, ptCount * sizeof(SkPoint));
     if (colors) {
         memcpy(builder.colors(), colors, ptCount * sizeof(SkColor));
diff --git a/libs/hwui/SkiaCanvas.h b/libs/hwui/SkiaCanvas.h
index c20c7dba..be958c4 100644
--- a/libs/hwui/SkiaCanvas.h
+++ b/libs/hwui/SkiaCanvas.h
@@ -117,9 +117,7 @@
     virtual void drawArc(float left, float top, float right, float bottom,
             float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
     virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
-    virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
-            const float* verts, const float* tex, const int* colors,
-            const uint16_t* indices, int indexCount, const SkPaint& paint) override;
+    virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) override;
 
     virtual void drawBitmap(Bitmap& bitmap, float left, float top, const SkPaint* paint) override;
     virtual void drawBitmap(Bitmap& bitmap, const SkMatrix& matrix, const SkPaint* paint) override;
diff --git a/libs/hwui/SkiaCanvasProxy.cpp b/libs/hwui/SkiaCanvasProxy.cpp
index 2e5a45e..34dddd1 100644
--- a/libs/hwui/SkiaCanvasProxy.cpp
+++ b/libs/hwui/SkiaCanvasProxy.cpp
@@ -183,20 +183,10 @@
 
 void SkiaCanvasProxy::onDrawVerticesObject(const SkVertices* vertices, SkBlendMode bmode,
         const SkPaint& paint) {
-    // TODO: should we pass through blendmode
     if (mFilterHwuiCalls) {
         return;
     }
-    // convert the SkPoints into floats
-    static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
-    const int floatCount = vertices->vertexCount() << 1;
-    const float* vArray = (const float*)vertices->positions();
-    const float* tArray = (const float*)vertices->texCoords();
-    const int* cArray = (const int*)vertices->colors();
-    // Can remove this cast after changing to SkVertices::VertexMode
-    SkCanvas::VertexMode vmode = static_cast<SkCanvas::VertexMode>(vertices->mode());
-    mCanvas->drawVertices(vmode, floatCount, vArray, tArray, cArray,
-            vertices->indices(), vertices->indexCount(), paint);
+    mCanvas->drawVertices(vertices, bmode, paint);
 }
 
 sk_sp<SkSurface> SkiaCanvasProxy::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
@@ -470,19 +460,13 @@
     if (mFilterHwuiCalls) {
         return;
     }
-    SkPatchUtils::VertexData data;
-
     SkMatrix matrix;
     mCanvas->getMatrix(&matrix);
     SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &matrix);
 
-    // It automatically adjusts lodX and lodY in case it exceeds the number of indices.
-    // If it fails to generate the vertices, then we do not draw.
-    if (SkPatchUtils::getVertexData(&data, cubics, colors, texCoords, lod.width(), lod.height())) {
-        this->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints,
-                           data.fTexCoords, data.fColors, bmode, data.fIndices, data.fIndexCount,
-                           paint);
-    }
+    mCanvas->drawVertices(SkPatchUtils::MakeVertices(cubics, colors, texCoords,
+                                                     lod.width(), lod.height()).get(),
+                          bmode, paint);
 }
 
 void SkiaCanvasProxy::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle) {
diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp
index eed5b24..7a8019a 100644
--- a/libs/hwui/hwui/Bitmap.cpp
+++ b/libs/hwui/hwui/Bitmap.cpp
@@ -486,12 +486,12 @@
         return;
     }
     outBitmap->setInfo(info(), rowBytes());
-    outBitmap->setPixelRef(this);
+    outBitmap->setPixelRef(sk_ref_sp(this), 0, 0);
 }
 
 void Bitmap::getSkBitmapForShaders(SkBitmap* outBitmap) {
     outBitmap->setInfo(info(), rowBytes());
-    outBitmap->setPixelRef(this);
+    outBitmap->setPixelRef(sk_ref_sp(this), 0, 0);
     outBitmap->setHasHardwareMipMap(mHasHardwareMipMap);
 }
 
diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h
index d645600..ab768cf 100644
--- a/libs/hwui/hwui/Canvas.h
+++ b/libs/hwui/hwui/Canvas.h
@@ -27,6 +27,8 @@
 #include <SkCanvas.h>
 #include <SkMatrix.h>
 
+class SkVertices;
+
 namespace minikin {
     class Layout;
 }
@@ -214,9 +216,7 @@
     virtual void drawArc(float left, float top, float right, float bottom,
             float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) = 0;
     virtual void drawPath(const SkPath& path, const SkPaint& paint) = 0;
-    virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
-                              const float* verts, const float* tex, const int* colors,
-                              const uint16_t* indices, int indexCount, const SkPaint& paint) = 0;
+    virtual void drawVertices(const SkVertices*, SkBlendMode, const SkPaint& paint) = 0;
 
     // Bitmap-based
     virtual void drawBitmap(Bitmap& bitmap, float left, float top,