Particles: Improvements to SkCurve

Added explicit Linear segment type, merge math evaluation helpers for
scalar and color curves. Add logic to visitFields that cuts down on the
serialized size of simple curves, and makes the GUI easier to work with.

Remove the curve plot from the GUI. It was incorrect (wrong points at
cubic handle locations), not terribly helpful, and difficult to
maintain.

Bug: skia:
Change-Id: I190cb5d118b1f4b910984e4df50ee3351c8be895
Reviewed-on: https://skia-review.googlesource.com/c/195884
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/particles/default.json b/particles/default.json
index 3e7a72d..f9da78f 100644
--- a/particles/default.json
+++ b/particles/default.json
@@ -6,17 +6,11 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": true,
             "Bidirectional": false,
             "A0": 1,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 3,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A1": 3
          }
       ]
    },
@@ -39,17 +33,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": -30,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 30,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 30
                }
             ]
          },
@@ -57,17 +45,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 10,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 30,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 30
                }
             ]
          }
@@ -81,16 +63,10 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "A0": [ 1, 0.196078, 0.0784314, 1 ],
-                  "B0": [ 1, 0.392157, 0.0784314, 1 ],
-                  "C0": [ 1, 0.588235, 0.0784314, 1 ],
-                  "D0": [ 1, 0.784314, 0.0784314, 1 ],
-                  "A1": [ 0, 0, 0, 0 ],
-                  "B1": [ 0, 0, 0, 0 ],
-                  "C1": [ 0, 0, 0, 0 ],
-                  "D1": [ 0, 0, 0, 0 ]
+                  "D0": [ 1, 0.784314, 0.0784314, 1 ]
                }
             ]
          }
diff --git a/particles/explosion.json b/particles/explosion.json
index 970a0d6..e403d3c 100644
--- a/particles/explosion.json
+++ b/particles/explosion.json
@@ -6,17 +6,11 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": true,
             "Bidirectional": false,
             "A0": 1,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 3,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A1": 3
          }
       ]
    },
@@ -47,17 +41,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "Bidirectional": false,
                   "A0": 0,
-                  "B0": 0.333,
-                  "C0": 0.666,
-                  "D0": 1,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": 1
                }
             ]
          }
diff --git a/particles/penguin_cannon.json b/particles/penguin_cannon.json
index 69f94c0..17415b9 100644
--- a/particles/penguin_cannon.json
+++ b/particles/penguin_cannon.json
@@ -6,17 +6,10 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": false,
             "Bidirectional": false,
-            "A0": 20,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 0,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A0": 20
          }
       ]
    },
@@ -41,17 +34,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 10,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 70,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 70
                }
             ]
          },
@@ -59,17 +46,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 140,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 200,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 200
                }
             ]
          }
@@ -85,17 +66,10 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": false,
                   "Bidirectional": false,
-                  "A0": 180,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A0": 180
                }
             ]
          },
@@ -103,17 +77,10 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": false,
                   "Bidirectional": false,
-                  "A0": 50,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A0": 50
                }
             ]
          }
@@ -126,17 +93,10 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": false,
                   "Bidirectional": false,
-                  "A0": 0,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A0": 0
                }
             ]
          }
diff --git a/particles/snowfall.json b/particles/snowfall.json
index aa8b0bb..843e65f 100644
--- a/particles/snowfall.json
+++ b/particles/snowfall.json
@@ -6,17 +6,10 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": false,
             "Bidirectional": false,
-            "A0": 10,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 0,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A0": 10
          }
       ]
    },
@@ -39,17 +32,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 170,
-                  "B0": 1,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 190,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 190
                }
             ]
          },
@@ -57,17 +44,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 10,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 30,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 30
                }
             ]
          }
@@ -81,7 +62,7 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Cubic",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 10,
diff --git a/particles/spiral.json b/particles/spiral.json
index 9257d53..b13df1f 100644
--- a/particles/spiral.json
+++ b/particles/spiral.json
@@ -6,17 +6,11 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": true,
             "Bidirectional": false,
             "A0": 2,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 3,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A1": 3
          }
       ]
    },
@@ -39,17 +33,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "Bidirectional": false,
                   "A0": 0,
-                  "B0": 360,
-                  "C0": 720,
-                  "D0": 1080,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": 1080
                }
             ]
          },
@@ -57,17 +45,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 50,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 60,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 60
                }
             ]
          }
@@ -81,17 +63,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "Bidirectional": false,
                   "A0": 0.5,
-                  "B0": 1,
-                  "C0": 1.5,
-                  "D0": 2,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": 2
                }
             ]
          }
@@ -103,15 +79,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": true,
                   "A0": [ 0.0999616, 0.140218, 0.784314, 1 ],
-                  "B0": [ 0.183679, 0.183692, 0.764706, 1 ],
-                  "C0": [ 0.242647, 0.43925, 0.916667, 1 ],
                   "D0": [ 0.523837, 0.886396, 0.980392, 1 ],
                   "A1": [ 0.378665, 0.121107, 0.705882, 1 ],
-                  "B1": [ 0.538658, 0.162534, 0.872549, 1 ],
-                  "C1": [ 0.672143, 0.259443, 0.867647, 1 ],
                   "D1": [ 0.934257, 0.229599, 0.955882, 1 ]
                }
             ]
diff --git a/particles/swirl.json b/particles/swirl.json
index fbc2b47..d3ccf5f 100644
--- a/particles/swirl.json
+++ b/particles/swirl.json
@@ -6,17 +6,11 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": true,
             "Bidirectional": false,
             "A0": 1,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 3,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A1": 3
          }
       ]
    },
@@ -39,17 +33,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": -10,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 10,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 10
                }
             ]
          },
@@ -57,17 +45,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": true,
                   "Bidirectional": false,
                   "A0": 50,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 60,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A1": 60
                }
             ]
          }
@@ -83,17 +65,10 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": true,
+                  "Type": "Constant",
                   "Ranged": false,
                   "Bidirectional": false,
-                  "A0": 90,
-                  "B0": 0,
-                  "C0": 0,
-                  "D0": 0,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "A0": 90
                }
             ]
          },
@@ -101,17 +76,13 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Cubic",
                   "Ranged": false,
                   "Bidirectional": true,
                   "A0": 180,
                   "B0": -90,
                   "C0": -120,
-                  "D0": -200,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": -200
                }
             ]
          }
@@ -123,17 +94,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "Bidirectional": false,
                   "A0": 3,
-                  "B0": 2.5,
-                  "C0": 2,
-                  "D0": 1.5,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": 1.5
                }
             ]
          }
@@ -145,15 +110,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": true,
                   "A0": [ 0.0999616, 0.140218, 0.784314, 1 ],
-                  "B0": [ 0.183679, 0.183692, 0.764706, 1 ],
-                  "C0": [ 0.242647, 0.43925, 0.916667, 1 ],
                   "D0": [ 0.523837, 0.886396, 0.980392, 1 ],
                   "A1": [ 0.378665, 0.121107, 0.705882, 1 ],
-                  "B1": [ 0.538658, 0.162534, 0.872549, 1 ],
-                  "C1": [ 0.672143, 0.259443, 0.867647, 1 ],
                   "D1": [ 0.934257, 0.229599, 0.955882, 1 ]
                }
             ]
diff --git a/particles/warp.json b/particles/warp.json
index b96074e..9b81db7 100644
--- a/particles/warp.json
+++ b/particles/warp.json
@@ -6,17 +6,10 @@
       "XValues": [],
       "Segments": [
          {
-            "Constant": true,
+            "Type": "Constant",
             "Ranged": false,
             "Bidirectional": false,
-            "A0": 30,
-            "B0": 0,
-            "C0": 0,
-            "D0": 0,
-            "A1": 0,
-            "B1": 0,
-            "C1": 0,
-            "D1": 0
+            "A0": 30
          }
       ]
    },
@@ -45,17 +38,11 @@
             "XValues": [],
             "Segments": [
                {
-                  "Constant": false,
+                  "Type": "Linear",
                   "Ranged": false,
                   "Bidirectional": false,
                   "A0": 0.25,
-                  "B0": 1,
-                  "C0": 2,
-                  "D0": 3,
-                  "A1": 0,
-                  "B1": 0,
-                  "C1": 0,
-                  "D1": 0
+                  "D0": 3
                }
             ]
          }