1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2006 The Android Open Source Project
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "include/private/SkTo.h"
9cb93a386Sopenharmony_ci#include "src/core/SkAnalyticEdge.h"
10cb93a386Sopenharmony_ci#include "src/core/SkFDot6.h"
11cb93a386Sopenharmony_ci#include "src/core/SkMathPriv.h"
12cb93a386Sopenharmony_ci#include <utility>
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cistatic const int kInverseTableSize = 1024; // SK_FDot6One * 16
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_cistatic inline SkFixed quick_inverse(SkFDot6 x) {
17cb93a386Sopenharmony_ci    SkASSERT(SkAbs32(x) < kInverseTableSize);
18cb93a386Sopenharmony_ci    static const int32_t table[kInverseTableSize * 2] = {
19cb93a386Sopenharmony_ci        -4096, -4100, -4104, -4108, -4112, -4116, -4120, -4124, -4128, -4132, -4136,
20cb93a386Sopenharmony_ci        -4140, -4144, -4148, -4152, -4156, -4161, -4165, -4169, -4173, -4177, -4181,
21cb93a386Sopenharmony_ci        -4185, -4190, -4194, -4198, -4202, -4206, -4211, -4215, -4219, -4223, -4228,
22cb93a386Sopenharmony_ci        -4232, -4236, -4240, -4245, -4249, -4253, -4258, -4262, -4266, -4271, -4275,
23cb93a386Sopenharmony_ci        -4279, -4284, -4288, -4293, -4297, -4301, -4306, -4310, -4315, -4319, -4324,
24cb93a386Sopenharmony_ci        -4328, -4332, -4337, -4341, -4346, -4350, -4355, -4359, -4364, -4369, -4373,
25cb93a386Sopenharmony_ci        -4378, -4382, -4387, -4391, -4396, -4401, -4405, -4410, -4415, -4419, -4424,
26cb93a386Sopenharmony_ci        -4429, -4433, -4438, -4443, -4447, -4452, -4457, -4462, -4466, -4471, -4476,
27cb93a386Sopenharmony_ci        -4481, -4485, -4490, -4495, -4500, -4505, -4510, -4514, -4519, -4524, -4529,
28cb93a386Sopenharmony_ci        -4534, -4539, -4544, -4549, -4554, -4559, -4563, -4568, -4573, -4578, -4583,
29cb93a386Sopenharmony_ci        -4588, -4593, -4599, -4604, -4609, -4614, -4619, -4624, -4629, -4634, -4639,
30cb93a386Sopenharmony_ci        -4644, -4650, -4655, -4660, -4665, -4670, -4675, -4681, -4686, -4691, -4696,
31cb93a386Sopenharmony_ci        -4702, -4707, -4712, -4718, -4723, -4728, -4733, -4739, -4744, -4750, -4755,
32cb93a386Sopenharmony_ci        -4760, -4766, -4771, -4777, -4782, -4788, -4793, -4798, -4804, -4809, -4815,
33cb93a386Sopenharmony_ci        -4821, -4826, -4832, -4837, -4843, -4848, -4854, -4860, -4865, -4871, -4877,
34cb93a386Sopenharmony_ci        -4882, -4888, -4894, -4899, -4905, -4911, -4917, -4922, -4928, -4934, -4940,
35cb93a386Sopenharmony_ci        -4946, -4951, -4957, -4963, -4969, -4975, -4981, -4987, -4993, -4999, -5005,
36cb93a386Sopenharmony_ci        -5011, -5017, -5023, -5029, -5035, -5041, -5047, -5053, -5059, -5065, -5071,
37cb93a386Sopenharmony_ci        -5077, -5084, -5090, -5096, -5102, -5108, -5115, -5121, -5127, -5133, -5140,
38cb93a386Sopenharmony_ci        -5146, -5152, -5159, -5165, -5171, -5178, -5184, -5190, -5197, -5203, -5210,
39cb93a386Sopenharmony_ci        -5216, -5223, -5229, -5236, -5242, -5249, -5256, -5262, -5269, -5275, -5282,
40cb93a386Sopenharmony_ci        -5289, -5295, -5302, -5309, -5315, -5322, -5329, -5336, -5343, -5349, -5356,
41cb93a386Sopenharmony_ci        -5363, -5370, -5377, -5384, -5391, -5398, -5405, -5412, -5418, -5426, -5433,
42cb93a386Sopenharmony_ci        -5440, -5447, -5454, -5461, -5468, -5475, -5482, -5489, -5497, -5504, -5511,
43cb93a386Sopenharmony_ci        -5518, -5526, -5533, -5540, -5548, -5555, -5562, -5570, -5577, -5584, -5592,
44cb93a386Sopenharmony_ci        -5599, -5607, -5614, -5622, -5629, -5637, -5645, -5652, -5660, -5667, -5675,
45cb93a386Sopenharmony_ci        -5683, -5691, -5698, -5706, -5714, -5722, -5729, -5737, -5745, -5753, -5761,
46cb93a386Sopenharmony_ci        -5769, -5777, -5785, -5793, -5801, -5809, -5817, -5825, -5833, -5841, -5849,
47cb93a386Sopenharmony_ci        -5857, -5866, -5874, -5882, -5890, -5899, -5907, -5915, -5924, -5932, -5940,
48cb93a386Sopenharmony_ci        -5949, -5957, -5966, -5974, -5983, -5991, -6000, -6009, -6017, -6026, -6034,
49cb93a386Sopenharmony_ci        -6043, -6052, -6061, -6069, -6078, -6087, -6096, -6105, -6114, -6123, -6132,
50cb93a386Sopenharmony_ci        -6141, -6150, -6159, -6168, -6177, -6186, -6195, -6204, -6213, -6223, -6232,
51cb93a386Sopenharmony_ci        -6241, -6250, -6260, -6269, -6278, -6288, -6297, -6307, -6316, -6326, -6335,
52cb93a386Sopenharmony_ci        -6345, -6355, -6364, -6374, -6384, -6393, -6403, -6413, -6423, -6432, -6442,
53cb93a386Sopenharmony_ci        -6452, -6462, -6472, -6482, -6492, -6502, -6512, -6523, -6533, -6543, -6553,
54cb93a386Sopenharmony_ci        -6563, -6574, -6584, -6594, -6605, -6615, -6626, -6636, -6647, -6657, -6668,
55cb93a386Sopenharmony_ci        -6678, -6689, -6700, -6710, -6721, -6732, -6743, -6754, -6765, -6775, -6786,
56cb93a386Sopenharmony_ci        -6797, -6808, -6820, -6831, -6842, -6853, -6864, -6875, -6887, -6898, -6909,
57cb93a386Sopenharmony_ci        -6921, -6932, -6944, -6955, -6967, -6978, -6990, -7002, -7013, -7025, -7037,
58cb93a386Sopenharmony_ci        -7049, -7061, -7073, -7084, -7096, -7108, -7121, -7133, -7145, -7157, -7169,
59cb93a386Sopenharmony_ci        -7182, -7194, -7206, -7219, -7231, -7244, -7256, -7269, -7281, -7294, -7307,
60cb93a386Sopenharmony_ci        -7319, -7332, -7345, -7358, -7371, -7384, -7397, -7410, -7423, -7436, -7449,
61cb93a386Sopenharmony_ci        -7463, -7476, -7489, -7503, -7516, -7530, -7543, -7557, -7570, -7584, -7598,
62cb93a386Sopenharmony_ci        -7612, -7626, -7639, -7653, -7667, -7681, -7695, -7710, -7724, -7738, -7752,
63cb93a386Sopenharmony_ci        -7767, -7781, -7796, -7810, -7825, -7839, -7854, -7869, -7884, -7898, -7913,
64cb93a386Sopenharmony_ci        -7928, -7943, -7958, -7973, -7989, -8004, -8019, -8035, -8050, -8065, -8081,
65cb93a386Sopenharmony_ci        -8097, -8112, -8128, -8144, -8160, -8176, -8192, -8208, -8224, -8240, -8256,
66cb93a386Sopenharmony_ci        -8272, -8289, -8305, -8322, -8338, -8355, -8371, -8388, -8405, -8422, -8439,
67cb93a386Sopenharmony_ci        -8456, -8473, -8490, -8507, -8525, -8542, -8559, -8577, -8594, -8612, -8630,
68cb93a386Sopenharmony_ci        -8648, -8665, -8683, -8701, -8719, -8738, -8756, -8774, -8793, -8811, -8830,
69cb93a386Sopenharmony_ci        -8848, -8867, -8886, -8905, -8924, -8943, -8962, -8981, -9000, -9020, -9039,
70cb93a386Sopenharmony_ci        -9058, -9078, -9098, -9118, -9137, -9157, -9177, -9198, -9218, -9238, -9258,
71cb93a386Sopenharmony_ci        -9279, -9300, -9320, -9341, -9362, -9383, -9404, -9425, -9446, -9467, -9489,
72cb93a386Sopenharmony_ci        -9510, -9532, -9554, -9576, -9597, -9619, -9642, -9664, -9686, -9709, -9731,
73cb93a386Sopenharmony_ci        -9754, -9776, -9799, -9822, -9845, -9868, -9892, -9915, -9939, -9962, -9986,
74cb93a386Sopenharmony_ci        -10010, -10034, -10058, -10082, -10106, -10131, -10155, -10180, -10205, -10230,
75cb93a386Sopenharmony_ci        -10255, -10280, -10305, -10330, -10356, -10381, -10407, -10433, -10459, -10485,
76cb93a386Sopenharmony_ci        -10512, -10538, -10564, -10591, -10618, -10645, -10672, -10699, -10727, -10754,
77cb93a386Sopenharmony_ci        -10782, -10810, -10837, -10866, -10894, -10922, -10951, -10979, -11008, -11037,
78cb93a386Sopenharmony_ci        -11066, -11096, -11125, -11155, -11184, -11214, -11244, -11275, -11305, -11335,
79cb93a386Sopenharmony_ci        -11366, -11397, -11428, -11459, -11491, -11522, -11554, -11586, -11618, -11650,
80cb93a386Sopenharmony_ci        -11683, -11715, -11748, -11781, -11814, -11848, -11881, -11915, -11949, -11983,
81cb93a386Sopenharmony_ci        -12018, -12052, -12087, -12122, -12157, -12192, -12228, -12264, -12300, -12336,
82cb93a386Sopenharmony_ci        -12372, -12409, -12446, -12483, -12520, -12557, -12595, -12633, -12671, -12710,
83cb93a386Sopenharmony_ci        -12748, -12787, -12826, -12865, -12905, -12945, -12985, -13025, -13066, -13107,
84cb93a386Sopenharmony_ci        -13148, -13189, -13231, -13273, -13315, -13357, -13400, -13443, -13486, -13530,
85cb93a386Sopenharmony_ci        -13573, -13617, -13662, -13706, -13751, -13797, -13842, -13888, -13934, -13981,
86cb93a386Sopenharmony_ci        -14027, -14074, -14122, -14169, -14217, -14266, -14315, -14364, -14413, -14463,
87cb93a386Sopenharmony_ci        -14513, -14563, -14614, -14665, -14716, -14768, -14820, -14873, -14926, -14979,
88cb93a386Sopenharmony_ci        -15033, -15087, -15141, -15196, -15252, -15307, -15363, -15420, -15477, -15534,
89cb93a386Sopenharmony_ci        -15592, -15650, -15709, -15768, -15827, -15887, -15947, -16008, -16070, -16131,
90cb93a386Sopenharmony_ci        -16194, -16256, -16320, -16384, -16448, -16513, -16578, -16644, -16710, -16777,
91cb93a386Sopenharmony_ci        -16844, -16912, -16980, -17050, -17119, -17189, -17260, -17331, -17403, -17476,
92cb93a386Sopenharmony_ci        -17549, -17623, -17697, -17772, -17848, -17924, -18001, -18078, -18157, -18236,
93cb93a386Sopenharmony_ci        -18315, -18396, -18477, -18558, -18641, -18724, -18808, -18893, -18978, -19065,
94cb93a386Sopenharmony_ci        -19152, -19239, -19328, -19418, -19508, -19599, -19691, -19784, -19878, -19972,
95cb93a386Sopenharmony_ci        -20068, -20164, -20262, -20360, -20460, -20560, -20661, -20763, -20867, -20971,
96cb93a386Sopenharmony_ci        -21076, -21183, -21290, -21399, -21509, -21620, -21732, -21845, -21959, -22075,
97cb93a386Sopenharmony_ci        -22192, -22310, -22429, -22550, -22671, -22795, -22919, -23045, -23172, -23301,
98cb93a386Sopenharmony_ci        -23431, -23563, -23696, -23831, -23967, -24105, -24244, -24385, -24528, -24672,
99cb93a386Sopenharmony_ci        -24818, -24966, -25115, -25266, -25420, -25575, -25731, -25890, -26051, -26214,
100cb93a386Sopenharmony_ci        -26379, -26546, -26715, -26886, -27060, -27235, -27413, -27594, -27776, -27962,
101cb93a386Sopenharmony_ci        -28149, -28339, -28532, -28728, -28926, -29127, -29330, -29537, -29746, -29959,
102cb93a386Sopenharmony_ci        -30174, -30393, -30615, -30840, -31068, -31300, -31536, -31775, -32017, -32263,
103cb93a386Sopenharmony_ci        -32513, -32768, -33026, -33288, -33554, -33825, -34100, -34379, -34663, -34952,
104cb93a386Sopenharmony_ci        -35246, -35544, -35848, -36157, -36472, -36792, -37117, -37449, -37786, -38130,
105cb93a386Sopenharmony_ci        -38479, -38836, -39199, -39568, -39945, -40329, -40721, -41120, -41527, -41943,
106cb93a386Sopenharmony_ci        -42366, -42799, -43240, -43690, -44150, -44620, -45100, -45590, -46091, -46603,
107cb93a386Sopenharmony_ci        -47127, -47662, -48210, -48770, -49344, -49932, -50533, -51150, -51781, -52428,
108cb93a386Sopenharmony_ci        -53092, -53773, -54471, -55188, -55924, -56679, -57456, -58254, -59074, -59918,
109cb93a386Sopenharmony_ci        -60787, -61680, -62601, -63550, -64527, -65536, -66576, -67650, -68759, -69905,
110cb93a386Sopenharmony_ci        -71089, -72315, -73584, -74898, -76260, -77672, -79137, -80659, -82241, -83886,
111cb93a386Sopenharmony_ci        -85598, -87381, -89240, -91180, -93206, -95325, -97541, -99864, -102300,
112cb93a386Sopenharmony_ci        -104857, -107546, -110376, -113359, -116508, -119837, -123361, -127100, -131072,
113cb93a386Sopenharmony_ci        -135300, -139810, -144631, -149796, -155344, -161319, -167772, -174762, -182361,
114cb93a386Sopenharmony_ci        -190650, -199728, -209715, -220752, -233016, -246723, -262144, -279620, -299593,
115cb93a386Sopenharmony_ci        -322638, -349525, -381300, -419430, -466033, -524288, -599186, -699050, -838860,
116cb93a386Sopenharmony_ci        -1048576, -1398101, -2097152, -4194304, 0, 4194304, 2097152, 1398101, 1048576,
117cb93a386Sopenharmony_ci        838860, 699050, 599186, 524288, 466033, 419430, 381300, 349525, 322638, 299593,
118cb93a386Sopenharmony_ci        279620, 262144, 246723, 233016, 220752, 209715, 199728, 190650, 182361, 174762,
119cb93a386Sopenharmony_ci        167772, 161319, 155344, 149796, 144631, 139810, 135300, 131072, 127100, 123361,
120cb93a386Sopenharmony_ci        119837, 116508, 113359, 110376, 107546, 104857, 102300, 99864, 97541, 95325,
121cb93a386Sopenharmony_ci        93206, 91180, 89240, 87381, 85598, 83886, 82241, 80659, 79137, 77672, 76260,
122cb93a386Sopenharmony_ci        74898, 73584, 72315, 71089, 69905, 68759, 67650, 66576, 65536, 64527, 63550,
123cb93a386Sopenharmony_ci        62601, 61680, 60787, 59918, 59074, 58254, 57456, 56679, 55924, 55188, 54471,
124cb93a386Sopenharmony_ci        53773, 53092, 52428, 51781, 51150, 50533, 49932, 49344, 48770, 48210, 47662,
125cb93a386Sopenharmony_ci        47127, 46603, 46091, 45590, 45100, 44620, 44150, 43690, 43240, 42799, 42366,
126cb93a386Sopenharmony_ci        41943, 41527, 41120, 40721, 40329, 39945, 39568, 39199, 38836, 38479, 38130,
127cb93a386Sopenharmony_ci        37786, 37449, 37117, 36792, 36472, 36157, 35848, 35544, 35246, 34952, 34663,
128cb93a386Sopenharmony_ci        34379, 34100, 33825, 33554, 33288, 33026, 32768, 32513, 32263, 32017, 31775,
129cb93a386Sopenharmony_ci        31536, 31300, 31068, 30840, 30615, 30393, 30174, 29959, 29746, 29537, 29330,
130cb93a386Sopenharmony_ci        29127, 28926, 28728, 28532, 28339, 28149, 27962, 27776, 27594, 27413, 27235,
131cb93a386Sopenharmony_ci        27060, 26886, 26715, 26546, 26379, 26214, 26051, 25890, 25731, 25575, 25420,
132cb93a386Sopenharmony_ci        25266, 25115, 24966, 24818, 24672, 24528, 24385, 24244, 24105, 23967, 23831,
133cb93a386Sopenharmony_ci        23696, 23563, 23431, 23301, 23172, 23045, 22919, 22795, 22671, 22550, 22429,
134cb93a386Sopenharmony_ci        22310, 22192, 22075, 21959, 21845, 21732, 21620, 21509, 21399, 21290, 21183,
135cb93a386Sopenharmony_ci        21076, 20971, 20867, 20763, 20661, 20560, 20460, 20360, 20262, 20164, 20068,
136cb93a386Sopenharmony_ci        19972, 19878, 19784, 19691, 19599, 19508, 19418, 19328, 19239, 19152, 19065,
137cb93a386Sopenharmony_ci        18978, 18893, 18808, 18724, 18641, 18558, 18477, 18396, 18315, 18236, 18157,
138cb93a386Sopenharmony_ci        18078, 18001, 17924, 17848, 17772, 17697, 17623, 17549, 17476, 17403, 17331,
139cb93a386Sopenharmony_ci        17260, 17189, 17119, 17050, 16980, 16912, 16844, 16777, 16710, 16644, 16578,
140cb93a386Sopenharmony_ci        16513, 16448, 16384, 16320, 16256, 16194, 16131, 16070, 16008, 15947, 15887,
141cb93a386Sopenharmony_ci        15827, 15768, 15709, 15650, 15592, 15534, 15477, 15420, 15363, 15307, 15252,
142cb93a386Sopenharmony_ci        15196, 15141, 15087, 15033, 14979, 14926, 14873, 14820, 14768, 14716, 14665,
143cb93a386Sopenharmony_ci        14614, 14563, 14513, 14463, 14413, 14364, 14315, 14266, 14217, 14169, 14122,
144cb93a386Sopenharmony_ci        14074, 14027, 13981, 13934, 13888, 13842, 13797, 13751, 13706, 13662, 13617,
145cb93a386Sopenharmony_ci        13573, 13530, 13486, 13443, 13400, 13357, 13315, 13273, 13231, 13189, 13148,
146cb93a386Sopenharmony_ci        13107, 13066, 13025, 12985, 12945, 12905, 12865, 12826, 12787, 12748, 12710,
147cb93a386Sopenharmony_ci        12671, 12633, 12595, 12557, 12520, 12483, 12446, 12409, 12372, 12336, 12300,
148cb93a386Sopenharmony_ci        12264, 12228, 12192, 12157, 12122, 12087, 12052, 12018, 11983, 11949, 11915,
149cb93a386Sopenharmony_ci        11881, 11848, 11814, 11781, 11748, 11715, 11683, 11650, 11618, 11586, 11554,
150cb93a386Sopenharmony_ci        11522, 11491, 11459, 11428, 11397, 11366, 11335, 11305, 11275, 11244, 11214,
151cb93a386Sopenharmony_ci        11184, 11155, 11125, 11096, 11066, 11037, 11008, 10979, 10951, 10922, 10894,
152cb93a386Sopenharmony_ci        10866, 10837, 10810, 10782, 10754, 10727, 10699, 10672, 10645, 10618, 10591,
153cb93a386Sopenharmony_ci        10564, 10538, 10512, 10485, 10459, 10433, 10407, 10381, 10356, 10330, 10305,
154cb93a386Sopenharmony_ci        10280, 10255, 10230, 10205, 10180, 10155, 10131, 10106, 10082, 10058, 10034,
155cb93a386Sopenharmony_ci        10010, 9986, 9962, 9939, 9915, 9892, 9868, 9845, 9822, 9799, 9776, 9754, 9731,
156cb93a386Sopenharmony_ci        9709, 9686, 9664, 9642, 9619, 9597, 9576, 9554, 9532, 9510, 9489, 9467, 9446,
157cb93a386Sopenharmony_ci        9425, 9404, 9383, 9362, 9341, 9320, 9300, 9279, 9258, 9238, 9218, 9198, 9177,
158cb93a386Sopenharmony_ci        9157, 9137, 9118, 9098, 9078, 9058, 9039, 9020, 9000, 8981, 8962, 8943, 8924,
159cb93a386Sopenharmony_ci        8905, 8886, 8867, 8848, 8830, 8811, 8793, 8774, 8756, 8738, 8719, 8701, 8683,
160cb93a386Sopenharmony_ci        8665, 8648, 8630, 8612, 8594, 8577, 8559, 8542, 8525, 8507, 8490, 8473, 8456,
161cb93a386Sopenharmony_ci        8439, 8422, 8405, 8388, 8371, 8355, 8338, 8322, 8305, 8289, 8272, 8256, 8240,
162cb93a386Sopenharmony_ci        8224, 8208, 8192, 8176, 8160, 8144, 8128, 8112, 8097, 8081, 8065, 8050, 8035,
163cb93a386Sopenharmony_ci        8019, 8004, 7989, 7973, 7958, 7943, 7928, 7913, 7898, 7884, 7869, 7854, 7839,
164cb93a386Sopenharmony_ci        7825, 7810, 7796, 7781, 7767, 7752, 7738, 7724, 7710, 7695, 7681, 7667, 7653,
165cb93a386Sopenharmony_ci        7639, 7626, 7612, 7598, 7584, 7570, 7557, 7543, 7530, 7516, 7503, 7489, 7476,
166cb93a386Sopenharmony_ci        7463, 7449, 7436, 7423, 7410, 7397, 7384, 7371, 7358, 7345, 7332, 7319, 7307,
167cb93a386Sopenharmony_ci        7294, 7281, 7269, 7256, 7244, 7231, 7219, 7206, 7194, 7182, 7169, 7157, 7145,
168cb93a386Sopenharmony_ci        7133, 7121, 7108, 7096, 7084, 7073, 7061, 7049, 7037, 7025, 7013, 7002, 6990,
169cb93a386Sopenharmony_ci        6978, 6967, 6955, 6944, 6932, 6921, 6909, 6898, 6887, 6875, 6864, 6853, 6842,
170cb93a386Sopenharmony_ci        6831, 6820, 6808, 6797, 6786, 6775, 6765, 6754, 6743, 6732, 6721, 6710, 6700,
171cb93a386Sopenharmony_ci        6689, 6678, 6668, 6657, 6647, 6636, 6626, 6615, 6605, 6594, 6584, 6574, 6563,
172cb93a386Sopenharmony_ci        6553, 6543, 6533, 6523, 6512, 6502, 6492, 6482, 6472, 6462, 6452, 6442, 6432,
173cb93a386Sopenharmony_ci        6423, 6413, 6403, 6393, 6384, 6374, 6364, 6355, 6345, 6335, 6326, 6316, 6307,
174cb93a386Sopenharmony_ci        6297, 6288, 6278, 6269, 6260, 6250, 6241, 6232, 6223, 6213, 6204, 6195, 6186,
175cb93a386Sopenharmony_ci        6177, 6168, 6159, 6150, 6141, 6132, 6123, 6114, 6105, 6096, 6087, 6078, 6069,
176cb93a386Sopenharmony_ci        6061, 6052, 6043, 6034, 6026, 6017, 6009, 6000, 5991, 5983, 5974, 5966, 5957,
177cb93a386Sopenharmony_ci        5949, 5940, 5932, 5924, 5915, 5907, 5899, 5890, 5882, 5874, 5866, 5857, 5849,
178cb93a386Sopenharmony_ci        5841, 5833, 5825, 5817, 5809, 5801, 5793, 5785, 5777, 5769, 5761, 5753, 5745,
179cb93a386Sopenharmony_ci        5737, 5729, 5722, 5714, 5706, 5698, 5691, 5683, 5675, 5667, 5660, 5652, 5645,
180cb93a386Sopenharmony_ci        5637, 5629, 5622, 5614, 5607, 5599, 5592, 5584, 5577, 5570, 5562, 5555, 5548,
181cb93a386Sopenharmony_ci        5540, 5533, 5526, 5518, 5511, 5504, 5497, 5489, 5482, 5475, 5468, 5461, 5454,
182cb93a386Sopenharmony_ci        5447, 5440, 5433, 5426, 5418, 5412, 5405, 5398, 5391, 5384, 5377, 5370, 5363,
183cb93a386Sopenharmony_ci        5356, 5349, 5343, 5336, 5329, 5322, 5315, 5309, 5302, 5295, 5289, 5282, 5275,
184cb93a386Sopenharmony_ci        5269, 5262, 5256, 5249, 5242, 5236, 5229, 5223, 5216, 5210, 5203, 5197, 5190,
185cb93a386Sopenharmony_ci        5184, 5178, 5171, 5165, 5159, 5152, 5146, 5140, 5133, 5127, 5121, 5115, 5108,
186cb93a386Sopenharmony_ci        5102, 5096, 5090, 5084, 5077, 5071, 5065, 5059, 5053, 5047, 5041, 5035, 5029,
187cb93a386Sopenharmony_ci        5023, 5017, 5011, 5005, 4999, 4993, 4987, 4981, 4975, 4969, 4963, 4957, 4951,
188cb93a386Sopenharmony_ci        4946, 4940, 4934, 4928, 4922, 4917, 4911, 4905, 4899, 4894, 4888, 4882, 4877,
189cb93a386Sopenharmony_ci        4871, 4865, 4860, 4854, 4848, 4843, 4837, 4832, 4826, 4821, 4815, 4809, 4804,
190cb93a386Sopenharmony_ci        4798, 4793, 4788, 4782, 4777, 4771, 4766, 4760, 4755, 4750, 4744, 4739, 4733,
191cb93a386Sopenharmony_ci        4728, 4723, 4718, 4712, 4707, 4702, 4696, 4691, 4686, 4681, 4675, 4670, 4665,
192cb93a386Sopenharmony_ci        4660, 4655, 4650, 4644, 4639, 4634, 4629, 4624, 4619, 4614, 4609, 4604, 4599,
193cb93a386Sopenharmony_ci        4593, 4588, 4583, 4578, 4573, 4568, 4563, 4559, 4554, 4549, 4544, 4539, 4534,
194cb93a386Sopenharmony_ci        4529, 4524, 4519, 4514, 4510, 4505, 4500, 4495, 4490, 4485, 4481, 4476, 4471,
195cb93a386Sopenharmony_ci        4466, 4462, 4457, 4452, 4447, 4443, 4438, 4433, 4429, 4424, 4419, 4415, 4410,
196cb93a386Sopenharmony_ci        4405, 4401, 4396, 4391, 4387, 4382, 4378, 4373, 4369, 4364, 4359, 4355, 4350,
197cb93a386Sopenharmony_ci        4346, 4341, 4337, 4332, 4328, 4324, 4319, 4315, 4310, 4306, 4301, 4297, 4293,
198cb93a386Sopenharmony_ci        4288, 4284, 4279, 4275, 4271, 4266, 4262, 4258, 4253, 4249, 4245, 4240, 4236,
199cb93a386Sopenharmony_ci        4232, 4228, 4223, 4219, 4215, 4211, 4206, 4202, 4198, 4194, 4190, 4185, 4181,
200cb93a386Sopenharmony_ci        4177, 4173, 4169, 4165, 4161, 4156, 4152, 4148, 4144, 4140, 4136, 4132, 4128,
201cb93a386Sopenharmony_ci        4124, 4120, 4116, 4112, 4108, 4104, 4100
202cb93a386Sopenharmony_ci    };
203cb93a386Sopenharmony_ci    return table[kInverseTableSize + x];
204cb93a386Sopenharmony_ci}
205cb93a386Sopenharmony_ci
206cb93a386Sopenharmony_cistatic inline SkFixed quick_div(SkFDot6 a, SkFDot6 b) {
207cb93a386Sopenharmony_ci    const int kMinBits = 3;  // abs(b) should be at least (1 << kMinBits) for quick division
208cb93a386Sopenharmony_ci    const int kMaxBits = 31; // Number of bits available in signed int
209cb93a386Sopenharmony_ci    // Given abs(b) <= (1 << kMinBits), the inverse of abs(b) is at most 1 << (22 - kMinBits) in
210cb93a386Sopenharmony_ci    // SkFixed format. Hence abs(a) should be less than kMaxAbsA
211cb93a386Sopenharmony_ci    const int kMaxAbsA = 1 << (kMaxBits - (22 - kMinBits));
212cb93a386Sopenharmony_ci    SkFDot6 abs_a = SkAbs32(a);
213cb93a386Sopenharmony_ci    SkFDot6 abs_b = SkAbs32(b);
214cb93a386Sopenharmony_ci    if (abs_b >= (1 << kMinBits) && abs_b < kInverseTableSize && abs_a < kMaxAbsA) {
215cb93a386Sopenharmony_ci        SkASSERT((int64_t)a * quick_inverse(b) <= SK_MaxS32
216cb93a386Sopenharmony_ci              && (int64_t)a * quick_inverse(b) >= SK_MinS32);
217cb93a386Sopenharmony_ci        SkFixed ourAnswer = (a * quick_inverse(b)) >> 6;
218cb93a386Sopenharmony_ci        SkASSERT(
219cb93a386Sopenharmony_ci            (SkFDot6Div(a,b) == 0 && ourAnswer == 0) ||
220cb93a386Sopenharmony_ci            SkFixedDiv(SkAbs32(SkFDot6Div(a,b) - ourAnswer), SkAbs32(SkFDot6Div(a,b))) <= 1 << 10
221cb93a386Sopenharmony_ci        );
222cb93a386Sopenharmony_ci        return ourAnswer;
223cb93a386Sopenharmony_ci    }
224cb93a386Sopenharmony_ci    return SkFDot6Div(a, b);
225cb93a386Sopenharmony_ci}
226cb93a386Sopenharmony_ci
227cb93a386Sopenharmony_cibool SkAnalyticEdge::setLine(const SkPoint& p0, const SkPoint& p1) {
228cb93a386Sopenharmony_ci    fRiteE = nullptr;
229cb93a386Sopenharmony_ci
230cb93a386Sopenharmony_ci    // We must set X/Y using the same way (e.g., times 4, to FDot6, then to Fixed) as Quads/Cubics.
231cb93a386Sopenharmony_ci    // Otherwise the order of the edge might be wrong due to precision limit.
232cb93a386Sopenharmony_ci    const int accuracy = kDefaultAccuracy;
233cb93a386Sopenharmony_ci#ifdef SK_RASTERIZE_EVEN_ROUNDING
234cb93a386Sopenharmony_ci    SkFixed x0 = SkFDot6ToFixed(SkScalarRoundToFDot6(p0.fX, accuracy)) >> accuracy;
235cb93a386Sopenharmony_ci    SkFixed y0 = SnapY(SkFDot6ToFixed(SkScalarRoundToFDot6(p0.fY, accuracy)) >> accuracy);
236cb93a386Sopenharmony_ci    SkFixed x1 = SkFDot6ToFixed(SkScalarRoundToFDot6(p1.fX, accuracy)) >> accuracy;
237cb93a386Sopenharmony_ci    SkFixed y1 = SnapY(SkFDot6ToFixed(SkScalarRoundToFDot6(p1.fY, accuracy)) >> accuracy);
238cb93a386Sopenharmony_ci#else
239cb93a386Sopenharmony_ci    const int multiplier = (1 << kDefaultAccuracy);
240cb93a386Sopenharmony_ci    SkFixed x0 = SkFDot6ToFixed(SkScalarToFDot6(p0.fX * multiplier)) >> accuracy;
241cb93a386Sopenharmony_ci    SkFixed y0 = SnapY(SkFDot6ToFixed(SkScalarToFDot6(p0.fY * multiplier)) >> accuracy);
242cb93a386Sopenharmony_ci    SkFixed x1 = SkFDot6ToFixed(SkScalarToFDot6(p1.fX * multiplier)) >> accuracy;
243cb93a386Sopenharmony_ci    SkFixed y1 = SnapY(SkFDot6ToFixed(SkScalarToFDot6(p1.fY * multiplier)) >> accuracy);
244cb93a386Sopenharmony_ci#endif
245cb93a386Sopenharmony_ci
246cb93a386Sopenharmony_ci    int winding = 1;
247cb93a386Sopenharmony_ci
248cb93a386Sopenharmony_ci    if (y0 > y1) {
249cb93a386Sopenharmony_ci        using std::swap;
250cb93a386Sopenharmony_ci        swap(x0, x1);
251cb93a386Sopenharmony_ci        swap(y0, y1);
252cb93a386Sopenharmony_ci        winding = -1;
253cb93a386Sopenharmony_ci    }
254cb93a386Sopenharmony_ci
255cb93a386Sopenharmony_ci    // are we a zero-height line?
256cb93a386Sopenharmony_ci    SkFDot6 dy = SkFixedToFDot6(y1 - y0);
257cb93a386Sopenharmony_ci    if (dy == 0) {
258cb93a386Sopenharmony_ci        return false;
259cb93a386Sopenharmony_ci    }
260cb93a386Sopenharmony_ci    SkFDot6 dx = SkFixedToFDot6(x1 - x0);
261cb93a386Sopenharmony_ci    SkFixed slope = quick_div(dx, dy);
262cb93a386Sopenharmony_ci    SkFixed absSlope = SkAbs32(slope);
263cb93a386Sopenharmony_ci
264cb93a386Sopenharmony_ci    fX          = x0;
265cb93a386Sopenharmony_ci    fDX         = slope;
266cb93a386Sopenharmony_ci    fUpperX     = x0;
267cb93a386Sopenharmony_ci    fY          = y0;
268cb93a386Sopenharmony_ci    fUpperY     = y0;
269cb93a386Sopenharmony_ci    fLowerY     = y1;
270cb93a386Sopenharmony_ci    fDY         = dx == 0 || slope == 0 ? SK_MaxS32 : absSlope < kInverseTableSize
271cb93a386Sopenharmony_ci                                                    ? quick_inverse(absSlope)
272cb93a386Sopenharmony_ci                                                    : SkAbs32(quick_div(dy, dx));
273cb93a386Sopenharmony_ci    fCurveCount = 0;
274cb93a386Sopenharmony_ci    fWinding    = SkToS8(winding);
275cb93a386Sopenharmony_ci    fCurveShift = 0;
276cb93a386Sopenharmony_ci
277cb93a386Sopenharmony_ci    return true;
278cb93a386Sopenharmony_ci}
279cb93a386Sopenharmony_ci
280cb93a386Sopenharmony_ci// This will become a bottleneck for small ovals rendering if we call SkFixedDiv twice here.
281cb93a386Sopenharmony_ci// Therefore, we'll let the outter function compute the slope once and send in the value.
282cb93a386Sopenharmony_ci// Moreover, we'll compute fDY by quickly lookup the inverse table (if possible).
283cb93a386Sopenharmony_cibool SkAnalyticEdge::updateLine(SkFixed x0, SkFixed y0, SkFixed x1, SkFixed y1, SkFixed slope) {
284cb93a386Sopenharmony_ci    // Since we send in the slope, we can no longer snap y inside this function.
285cb93a386Sopenharmony_ci    // If we don't send in the slope, or we do some more sophisticated snapping, this function
286cb93a386Sopenharmony_ci    // could be a performance bottleneck.
287cb93a386Sopenharmony_ci    SkASSERT(fWinding == 1 || fWinding == -1);
288cb93a386Sopenharmony_ci    SkASSERT(fCurveCount != 0);
289cb93a386Sopenharmony_ci
290cb93a386Sopenharmony_ci    // We don't chop at y extrema for cubics so the y is not guaranteed to be increasing for them.
291cb93a386Sopenharmony_ci    // In that case, we have to swap x/y and negate the winding.
292cb93a386Sopenharmony_ci    if (y0 > y1) {
293cb93a386Sopenharmony_ci        using std::swap;
294cb93a386Sopenharmony_ci        swap(x0, x1);
295cb93a386Sopenharmony_ci        swap(y0, y1);
296cb93a386Sopenharmony_ci        fWinding = -fWinding;
297cb93a386Sopenharmony_ci    }
298cb93a386Sopenharmony_ci
299cb93a386Sopenharmony_ci    SkASSERT(y0 <= y1);
300cb93a386Sopenharmony_ci
301cb93a386Sopenharmony_ci    SkFDot6 dx = SkFixedToFDot6(x1 - x0);
302cb93a386Sopenharmony_ci    SkFDot6 dy = SkFixedToFDot6(y1 - y0);
303cb93a386Sopenharmony_ci
304cb93a386Sopenharmony_ci    // are we a zero-height line?
305cb93a386Sopenharmony_ci    if (dy == 0) {
306cb93a386Sopenharmony_ci        return false;
307cb93a386Sopenharmony_ci    }
308cb93a386Sopenharmony_ci
309cb93a386Sopenharmony_ci    SkASSERT(slope < SK_MaxS32);
310cb93a386Sopenharmony_ci
311cb93a386Sopenharmony_ci    SkFDot6     absSlope = SkAbs32(SkFixedToFDot6(slope));
312cb93a386Sopenharmony_ci    fX          = x0;
313cb93a386Sopenharmony_ci    fDX         = slope;
314cb93a386Sopenharmony_ci    fUpperX     = x0;
315cb93a386Sopenharmony_ci    fY          = y0;
316cb93a386Sopenharmony_ci    fUpperY     = y0;
317cb93a386Sopenharmony_ci    fLowerY     = y1;
318cb93a386Sopenharmony_ci    fDY         = (dx == 0 || slope == 0)
319cb93a386Sopenharmony_ci                  ? SK_MaxS32
320cb93a386Sopenharmony_ci                  : absSlope < kInverseTableSize
321cb93a386Sopenharmony_ci                    ? quick_inverse(absSlope)
322cb93a386Sopenharmony_ci                    : SkAbs32(quick_div(dy, dx));
323cb93a386Sopenharmony_ci
324cb93a386Sopenharmony_ci    return true;
325cb93a386Sopenharmony_ci}
326cb93a386Sopenharmony_ci
327cb93a386Sopenharmony_cibool SkAnalyticEdge::update(SkFixed last_y, bool sortY) {
328cb93a386Sopenharmony_ci    SkASSERT(last_y >= fLowerY); // we shouldn't update edge if last_y < fLowerY
329cb93a386Sopenharmony_ci    if (fCurveCount < 0) {
330cb93a386Sopenharmony_ci        return static_cast<SkAnalyticCubicEdge*>(this)->updateCubic(sortY);
331cb93a386Sopenharmony_ci    } else if (fCurveCount > 0) {
332cb93a386Sopenharmony_ci        return static_cast<SkAnalyticQuadraticEdge*>(this)->updateQuadratic();
333cb93a386Sopenharmony_ci    }
334cb93a386Sopenharmony_ci    return false;
335cb93a386Sopenharmony_ci}
336cb93a386Sopenharmony_ci
337cb93a386Sopenharmony_cibool SkAnalyticQuadraticEdge::setQuadratic(const SkPoint pts[3]) {
338cb93a386Sopenharmony_ci    fRiteE = nullptr;
339cb93a386Sopenharmony_ci
340cb93a386Sopenharmony_ci    if (!fQEdge.setQuadraticWithoutUpdate(pts, kDefaultAccuracy)) {
341cb93a386Sopenharmony_ci        return false;
342cb93a386Sopenharmony_ci    }
343cb93a386Sopenharmony_ci    fQEdge.fQx >>= kDefaultAccuracy;
344cb93a386Sopenharmony_ci    fQEdge.fQy >>= kDefaultAccuracy;
345cb93a386Sopenharmony_ci    fQEdge.fQDx >>= kDefaultAccuracy;
346cb93a386Sopenharmony_ci    fQEdge.fQDy >>= kDefaultAccuracy;
347cb93a386Sopenharmony_ci    fQEdge.fQDDx >>= kDefaultAccuracy;
348cb93a386Sopenharmony_ci    fQEdge.fQDDy >>= kDefaultAccuracy;
349cb93a386Sopenharmony_ci    fQEdge.fQLastX >>= kDefaultAccuracy;
350cb93a386Sopenharmony_ci    fQEdge.fQLastY >>= kDefaultAccuracy;
351cb93a386Sopenharmony_ci    fQEdge.fQy = SnapY(fQEdge.fQy);
352cb93a386Sopenharmony_ci    fQEdge.fQLastY = SnapY(fQEdge.fQLastY);
353cb93a386Sopenharmony_ci
354cb93a386Sopenharmony_ci    fWinding = fQEdge.fWinding;
355cb93a386Sopenharmony_ci    fCurveCount = fQEdge.fCurveCount;
356cb93a386Sopenharmony_ci    fCurveShift = fQEdge.fCurveShift;
357cb93a386Sopenharmony_ci
358cb93a386Sopenharmony_ci    fSnappedX = fQEdge.fQx;
359cb93a386Sopenharmony_ci    fSnappedY = fQEdge.fQy;
360cb93a386Sopenharmony_ci
361cb93a386Sopenharmony_ci    return this->updateQuadratic();
362cb93a386Sopenharmony_ci}
363cb93a386Sopenharmony_ci
364cb93a386Sopenharmony_cibool SkAnalyticQuadraticEdge::updateQuadratic() {
365cb93a386Sopenharmony_ci    int     success = 0; // initialize to fail!
366cb93a386Sopenharmony_ci    int     count = fCurveCount;
367cb93a386Sopenharmony_ci    SkFixed oldx = fQEdge.fQx;
368cb93a386Sopenharmony_ci    SkFixed oldy = fQEdge.fQy;
369cb93a386Sopenharmony_ci    SkFixed dx = fQEdge.fQDx;
370cb93a386Sopenharmony_ci    SkFixed dy = fQEdge.fQDy;
371cb93a386Sopenharmony_ci    SkFixed newx, newy, newSnappedX, newSnappedY;
372cb93a386Sopenharmony_ci    int     shift = fCurveShift;
373cb93a386Sopenharmony_ci
374cb93a386Sopenharmony_ci    SkASSERT(count > 0);
375cb93a386Sopenharmony_ci
376cb93a386Sopenharmony_ci    do {
377cb93a386Sopenharmony_ci        SkFixed slope;
378cb93a386Sopenharmony_ci        if (--count > 0)
379cb93a386Sopenharmony_ci        {
380cb93a386Sopenharmony_ci            newx    = oldx + (dx >> shift);
381cb93a386Sopenharmony_ci            newy    = oldy + (dy >> shift);
382cb93a386Sopenharmony_ci            if (SkAbs32(dy >> shift) >= SK_Fixed1 * 2) { // only snap when dy is large enough
383cb93a386Sopenharmony_ci                SkFDot6 diffY = SkFixedToFDot6(newy - fSnappedY);
384cb93a386Sopenharmony_ci                slope = diffY ? quick_div(SkFixedToFDot6(newx - fSnappedX), diffY)
385cb93a386Sopenharmony_ci                              : SK_MaxS32;
386cb93a386Sopenharmony_ci                newSnappedY = std::min<SkFixed>(fQEdge.fQLastY, SkFixedRoundToFixed(newy));
387cb93a386Sopenharmony_ci                newSnappedX = newx - SkFixedMul(slope, newy - newSnappedY);
388cb93a386Sopenharmony_ci            } else {
389cb93a386Sopenharmony_ci                newSnappedY = std::min(fQEdge.fQLastY, SnapY(newy));
390cb93a386Sopenharmony_ci                newSnappedX = newx;
391cb93a386Sopenharmony_ci                SkFDot6 diffY = SkFixedToFDot6(newSnappedY - fSnappedY);
392cb93a386Sopenharmony_ci                slope = diffY ? quick_div(SkFixedToFDot6(newx - fSnappedX), diffY)
393cb93a386Sopenharmony_ci                              : SK_MaxS32;
394cb93a386Sopenharmony_ci            }
395cb93a386Sopenharmony_ci            dx += fQEdge.fQDDx;
396cb93a386Sopenharmony_ci            dy += fQEdge.fQDDy;
397cb93a386Sopenharmony_ci        }
398cb93a386Sopenharmony_ci        else    // last segment
399cb93a386Sopenharmony_ci        {
400cb93a386Sopenharmony_ci            newx    = fQEdge.fQLastX;
401cb93a386Sopenharmony_ci            newy    = fQEdge.fQLastY;
402cb93a386Sopenharmony_ci            newSnappedY = newy;
403cb93a386Sopenharmony_ci            newSnappedX = newx;
404cb93a386Sopenharmony_ci            SkFDot6 diffY = (newy - fSnappedY) >> 10;
405cb93a386Sopenharmony_ci            slope = diffY ? quick_div((newx - fSnappedX) >> 10, diffY) : SK_MaxS32;
406cb93a386Sopenharmony_ci        }
407cb93a386Sopenharmony_ci        if (slope < SK_MaxS32) {
408cb93a386Sopenharmony_ci            success = this->updateLine(fSnappedX, fSnappedY, newSnappedX, newSnappedY, slope);
409cb93a386Sopenharmony_ci        }
410cb93a386Sopenharmony_ci        oldx = newx;
411cb93a386Sopenharmony_ci        oldy = newy;
412cb93a386Sopenharmony_ci    } while (count > 0 && !success);
413cb93a386Sopenharmony_ci
414cb93a386Sopenharmony_ci    SkASSERT(newSnappedY <= fQEdge.fQLastY);
415cb93a386Sopenharmony_ci
416cb93a386Sopenharmony_ci    fQEdge.fQx  = newx;
417cb93a386Sopenharmony_ci    fQEdge.fQy  = newy;
418cb93a386Sopenharmony_ci    fQEdge.fQDx = dx;
419cb93a386Sopenharmony_ci    fQEdge.fQDy = dy;
420cb93a386Sopenharmony_ci    fSnappedX   = newSnappedX;
421cb93a386Sopenharmony_ci    fSnappedY   = newSnappedY;
422cb93a386Sopenharmony_ci    fCurveCount = SkToS8(count);
423cb93a386Sopenharmony_ci    return success;
424cb93a386Sopenharmony_ci}
425cb93a386Sopenharmony_ci
426cb93a386Sopenharmony_cibool SkAnalyticCubicEdge::setCubic(const SkPoint pts[4], bool sortY) {
427cb93a386Sopenharmony_ci    fRiteE = nullptr;
428cb93a386Sopenharmony_ci
429cb93a386Sopenharmony_ci    if (!fCEdge.setCubicWithoutUpdate(pts, kDefaultAccuracy, sortY)) {
430cb93a386Sopenharmony_ci        return false;
431cb93a386Sopenharmony_ci    }
432cb93a386Sopenharmony_ci
433cb93a386Sopenharmony_ci    fCEdge.fCx >>= kDefaultAccuracy;
434cb93a386Sopenharmony_ci    fCEdge.fCy >>= kDefaultAccuracy;
435cb93a386Sopenharmony_ci    fCEdge.fCDx >>= kDefaultAccuracy;
436cb93a386Sopenharmony_ci    fCEdge.fCDy >>= kDefaultAccuracy;
437cb93a386Sopenharmony_ci    fCEdge.fCDDx >>= kDefaultAccuracy;
438cb93a386Sopenharmony_ci    fCEdge.fCDDy >>= kDefaultAccuracy;
439cb93a386Sopenharmony_ci    fCEdge.fCDDDx >>= kDefaultAccuracy;
440cb93a386Sopenharmony_ci    fCEdge.fCDDDy >>= kDefaultAccuracy;
441cb93a386Sopenharmony_ci    fCEdge.fCLastX >>= kDefaultAccuracy;
442cb93a386Sopenharmony_ci    fCEdge.fCLastY >>= kDefaultAccuracy;
443cb93a386Sopenharmony_ci    fCEdge.fCy = SnapY(fCEdge.fCy);
444cb93a386Sopenharmony_ci    fCEdge.fCLastY = SnapY(fCEdge.fCLastY);
445cb93a386Sopenharmony_ci
446cb93a386Sopenharmony_ci    fWinding = fCEdge.fWinding;
447cb93a386Sopenharmony_ci    fCurveCount = fCEdge.fCurveCount;
448cb93a386Sopenharmony_ci    fCurveShift = fCEdge.fCurveShift;
449cb93a386Sopenharmony_ci    fCubicDShift = fCEdge.fCubicDShift;
450cb93a386Sopenharmony_ci
451cb93a386Sopenharmony_ci    fSnappedY = fCEdge.fCy;
452cb93a386Sopenharmony_ci
453cb93a386Sopenharmony_ci    return this->updateCubic(sortY);
454cb93a386Sopenharmony_ci}
455cb93a386Sopenharmony_ci
456cb93a386Sopenharmony_cibool SkAnalyticCubicEdge::updateCubic(bool sortY) {
457cb93a386Sopenharmony_ci    int     success;
458cb93a386Sopenharmony_ci    int     count = fCurveCount;
459cb93a386Sopenharmony_ci    SkFixed oldx = fCEdge.fCx;
460cb93a386Sopenharmony_ci    SkFixed oldy = fCEdge.fCy;
461cb93a386Sopenharmony_ci    SkFixed newx, newy;
462cb93a386Sopenharmony_ci    const int ddshift = fCurveShift;
463cb93a386Sopenharmony_ci    const int dshift = fCubicDShift;
464cb93a386Sopenharmony_ci
465cb93a386Sopenharmony_ci    SkASSERT(count < 0);
466cb93a386Sopenharmony_ci
467cb93a386Sopenharmony_ci    do {
468cb93a386Sopenharmony_ci        if (++count < 0) {
469cb93a386Sopenharmony_ci            newx    = oldx + (fCEdge.fCDx >> dshift);
470cb93a386Sopenharmony_ci            fCEdge.fCDx    += fCEdge.fCDDx >> ddshift;
471cb93a386Sopenharmony_ci            fCEdge.fCDDx   += fCEdge.fCDDDx;
472cb93a386Sopenharmony_ci
473cb93a386Sopenharmony_ci            newy    = oldy + (fCEdge.fCDy >> dshift);
474cb93a386Sopenharmony_ci            fCEdge.fCDy    += fCEdge.fCDDy >> ddshift;
475cb93a386Sopenharmony_ci            fCEdge.fCDDy   += fCEdge.fCDDDy;
476cb93a386Sopenharmony_ci        }
477cb93a386Sopenharmony_ci        else {    // last segment
478cb93a386Sopenharmony_ci            newx    = fCEdge.fCLastX;
479cb93a386Sopenharmony_ci            newy    = fCEdge.fCLastY;
480cb93a386Sopenharmony_ci        }
481cb93a386Sopenharmony_ci
482cb93a386Sopenharmony_ci        // we want to say SkASSERT(oldy <= newy), but our finite fixedpoint
483cb93a386Sopenharmony_ci        // doesn't always achieve that, so we have to explicitly pin it here.
484cb93a386Sopenharmony_ci        if (sortY && newy < oldy) {
485cb93a386Sopenharmony_ci            newy = oldy;
486cb93a386Sopenharmony_ci        }
487cb93a386Sopenharmony_ci
488cb93a386Sopenharmony_ci        SkFixed newSnappedY = SnapY(newy);
489cb93a386Sopenharmony_ci        // we want to SkASSERT(snappedNewY <= fCEdge.fCLastY), but our finite fixedpoint
490cb93a386Sopenharmony_ci        // doesn't always achieve that, so we have to explicitly pin it here.
491cb93a386Sopenharmony_ci        if (sortY && fCEdge.fCLastY < newSnappedY) {
492cb93a386Sopenharmony_ci            newSnappedY = fCEdge.fCLastY;
493cb93a386Sopenharmony_ci            count = 0;
494cb93a386Sopenharmony_ci        }
495cb93a386Sopenharmony_ci
496cb93a386Sopenharmony_ci        SkFixed slope = SkFixedToFDot6(newSnappedY - fSnappedY) == 0
497cb93a386Sopenharmony_ci                        ? SK_MaxS32
498cb93a386Sopenharmony_ci                        : SkFDot6Div(SkFixedToFDot6(newx - oldx),
499cb93a386Sopenharmony_ci                                     SkFixedToFDot6(newSnappedY - fSnappedY));
500cb93a386Sopenharmony_ci
501cb93a386Sopenharmony_ci        success = this->updateLine(oldx, fSnappedY, newx, newSnappedY, slope);
502cb93a386Sopenharmony_ci
503cb93a386Sopenharmony_ci        oldx = newx;
504cb93a386Sopenharmony_ci        oldy = newy;
505cb93a386Sopenharmony_ci        fSnappedY = newSnappedY;
506cb93a386Sopenharmony_ci    } while (count < 0 && !success);
507cb93a386Sopenharmony_ci
508cb93a386Sopenharmony_ci    fCEdge.fCx  = newx;
509cb93a386Sopenharmony_ci    fCEdge.fCy  = newy;
510cb93a386Sopenharmony_ci    fCurveCount = SkToS8(count);
511cb93a386Sopenharmony_ci    return success;
512cb93a386Sopenharmony_ci}
513