Validate per-vertex vertices data against effect in SkCanvas

Updates the vertices_data GM to work on the GPU backend, too. For now,
it still works on the CPU via the original hack.

Bug: skia:9984
Change-Id: I2e11bd01e3cc953d2837ecd6ca8b2305b060e5fc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/278857
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 01ca4b0..61e7b89 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -17,6 +17,7 @@
 #include "include/core/SkString.h"
 #include "include/core/SkTextBlob.h"
 #include "include/core/SkVertices.h"
+#include "include/effects/SkRuntimeEffect.h"
 #include "include/private/SkNx.h"
 #include "include/private/SkTo.h"
 #include "include/utils/SkNoDrawCanvas.h"
@@ -1984,8 +1985,20 @@
 void SkCanvas::drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint) {
     TRACE_EVENT0("skia", TRACE_FUNC);
     RETURN_ON_NULL(vertices);
+
+    SkVertices::Info info;
+    vertices->getInfo(&info);
+
     // We expect fans to be converted to triangles when building or deserializing SkVertices.
-    SkASSERT(SkVerticesPriv::Mode(vertices) != SkVertices::kTriangleFan_VertexMode);
+    SkASSERT(info.fMode != SkVertices::kTriangleFan_VertexMode);
+
+    // If the vertices contain custom attributes, ensure they line up with the paint's shader
+    const SkRuntimeEffect* effect =
+            paint.getShader() ? as_SB(paint.getShader())->asRuntimeEffect() : nullptr;
+    if (info.fPerVertexDataCount != (effect ? effect->varyingCount() : 0)) {
+        return;
+    }
+
     this->onDrawVerticesObject(vertices, mode, paint);
 }