[SVGDom] Factor out common gradient logic

In preparation of radial gradient support, move common logic into an
abstract base class (SkSVGGradient).

Change-Id: Ie5361048ca8fddd9070c573c8daef0d0f57dc95e
Reviewed-on: https://skia-review.googlesource.com/57108
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/experimental/svg/model/SkSVGGradient.h b/experimental/svg/model/SkSVGGradient.h
new file mode 100644
index 0000000..75ffba9
--- /dev/null
+++ b/experimental/svg/model/SkSVGGradient.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkSVGGradient_DEFINED
+#define SkSVGGradient_DEFINED
+
+#include "SkShader.h"
+#include "SkSVGHiddenContainer.h"
+#include "SkSVGTypes.h"
+
+class SkMatrix;
+class SkSVGRenderContext;
+
+class SkSVGGradient : public SkSVGHiddenContainer {
+public:
+    ~SkSVGGradient() override = default;
+
+    void setHref(const SkSVGStringType&);
+    void setGradientTransform(const SkSVGTransformType&);
+    void setSpreadMethod(const SkSVGSpreadMethod&);
+
+protected:
+    explicit SkSVGGradient(SkSVGTag t) : INHERITED(t) {}
+
+    void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
+
+    bool onAsPaint(const SkSVGRenderContext&, SkPaint*) const final;
+
+    virtual sk_sp<SkShader> onMakeShader(const SkSVGRenderContext&,
+                                         const SkColor*, const SkScalar*, int count,
+                                         SkShader::TileMode, const SkMatrix& localMatrix) const = 0;
+
+private:
+    using StopPositionArray = SkSTArray<2, SkScalar, true>;
+    using    StopColorArray = SkSTArray<2,  SkColor, true>;
+    void collectColorStops(const SkSVGRenderContext&, StopPositionArray*, StopColorArray*) const;
+
+    SkSVGStringType    fHref;
+    SkSVGTransformType fGradientTransform = SkSVGTransformType(SkMatrix::I());
+    SkSVGSpreadMethod  fSpreadMethod = SkSVGSpreadMethod(SkSVGSpreadMethod::Type::kPad);
+
+    typedef SkSVGHiddenContainer INHERITED;
+};
+
+#endif // SkSVGGradient_DEFINED