Change how GPs configure attributes

Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.

The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.

Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.

Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.

Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/ccpr/GrCCStroker.cpp b/src/gpu/ccpr/GrCCStroker.cpp
index 98f8cef..f836774 100644
--- a/src/gpu/ccpr/GrCCStroker.cpp
+++ b/src/gpu/ccpr/GrCCStroker.cpp
@@ -70,15 +70,10 @@
 class LinearStrokeProcessor : public GrGeometryProcessor {
 public:
     LinearStrokeProcessor() : GrGeometryProcessor(kLinearStrokeProcessor_ClassID) {
-        this->setInstanceAttributeCnt(2);
+        this->setInstanceAttributes(kInstanceAttribs, 2);
 #ifdef SK_DEBUG
-        // Check that instance attributes exactly match the LinearStrokeInstance struct layout.
         using Instance = LinearStrokeInstance;
-        SkASSERT(!strcmp(this->instanceAttribute(0).name(), "endpts"));
-        SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fEndpoints));
-        SkASSERT(!strcmp(this->instanceAttribute(1).name(), "stroke_radius"));
-        SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fStrokeRadius));
-        SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
+        SkASSERT(this->instanceStride() == sizeof(Instance));
 #endif
     }
 
@@ -91,8 +86,6 @@
             {"stroke_radius", kFloat_GrVertexAttribType, kFloat_GrSLType}
     };
 
-    const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
-
     class Impl : public GrGLSLGeometryProcessor {
         void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
                      FPCoordTransformIter&&) override {}
@@ -167,17 +160,10 @@
 class CubicStrokeProcessor : public GrGeometryProcessor {
 public:
     CubicStrokeProcessor() : GrGeometryProcessor(kCubicStrokeProcessor_ClassID) {
-        this->setInstanceAttributeCnt(3);
+        this->setInstanceAttributes(kInstanceAttribs, 3);
 #ifdef SK_DEBUG
-        // Check that instance attributes exactly match the CubicStrokeInstance struct layout.
         using Instance = CubicStrokeInstance;
-        SkASSERT(!strcmp(this->instanceAttribute(0).name(), "X"));
-        SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fX));
-        SkASSERT(!strcmp(this->instanceAttribute(1).name(), "Y"));
-        SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fY));
-        SkASSERT(!strcmp(this->instanceAttribute(2).name(), "stroke_info"));
-        SkASSERT(this->debugOnly_instanceAttributeOffset(2) == offsetof(Instance, fStrokeRadius));
-        SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
+        SkASSERT(this->instanceStride() == sizeof(Instance));
 #endif
     }
 
@@ -191,8 +177,6 @@
             {"stroke_info", kFloat2_GrVertexAttribType, kFloat2_GrSLType}
     };
 
-    const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
-
     class Impl : public GrGLSLGeometryProcessor {
         void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
                      FPCoordTransformIter&&) override {}