OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkEdge.h" | 10 #include "SkEdge.h" |
11 #include "SkFDot6.h" | 11 #include "SkFDot6.h" |
12 #include "SkMath.h" | 12 #include "SkMath.h" |
13 | 13 |
14 /* | 14 /* |
15 In setLine, setQuadratic, setCubic, the first thing we do is to convert | 15 In setLine, setQuadratic, setCubic, the first thing we do is to convert |
16 the points into FDot6. This is modulated by the shift parameter, which | 16 the points into FDot6. This is modulated by the shift parameter, which |
17 will either be 0, or something like 2 for antialiasing. | 17 will either be 0, or something like 2 for antialiasing. |
18 | 18 |
19 In the float case, we want to turn the float into .6 by saying pt * 64, | 19 In the float case, we want to turn the float into .6 by saying pt * 64, |
20 or pt * 256 for antialiasing. This is implemented as 1 << (shift + 6). | 20 or pt * 256 for antialiasing. This is implemented as 1 << (shift + 6). |
21 | 21 |
22 In the fixed case, we want to turn the fixed into .6 by saying pt >> 10, | 22 In the fixed case, we want to turn the fixed into .6 by saying pt >> 10, |
23 or pt >> 8 for antialiasing. This is implemented as pt >> (10 - shift). | 23 or pt >> 8 for antialiasing. This is implemented as pt >> (10 - shift). |
24 */ | 24 */ |
25 | 25 |
26 static inline SkFixed SkFDot6ToFixedDiv2(SkFDot6 value) { | 26 static inline SkFixed SkFDot6ToFixedDiv2(SkFDot6 value) { |
27 // we want to return SkFDot6ToFixed(value >> 1), but we don't want to throw | 27 // we want to return SkFDot6ToFixed(value >> 1), but we don't want to throw |
28 // away data in value, so just perform a modify up-shift | 28 // away data in value, so just perform a modify up-shift |
29 return value << (16 - 6 - 1); | 29 return SkLeftShift(value, 16 - 6 - 1); |
30 } | 30 } |
31 | 31 |
32 ///////////////////////////////////////////////////////////////////////// | 32 ///////////////////////////////////////////////////////////////////////// |
33 | 33 |
34 int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, | 34 int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip, |
35 int shift) { | 35 int shift) { |
36 SkFDot6 x0, y0, x1, y1; | 36 SkFDot6 x0, y0, x1, y1; |
37 | 37 |
38 { | 38 { |
39 #ifdef SK_RASTERIZE_EVEN_ROUNDING | 39 #ifdef SK_RASTERIZE_EVEN_ROUNDING |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 int top = SkFDot6Round(y0); | 208 int top = SkFDot6Round(y0); |
209 int bot = SkFDot6Round(y2); | 209 int bot = SkFDot6Round(y2); |
210 | 210 |
211 // are we a zero-height quad (line)? | 211 // are we a zero-height quad (line)? |
212 if (top == bot) | 212 if (top == bot) |
213 return 0; | 213 return 0; |
214 | 214 |
215 // compute number of steps needed (1 << shift) | 215 // compute number of steps needed (1 << shift) |
216 { | 216 { |
217 SkFDot6 dx = ((x1 << 1) - x0 - x2) >> 2; | 217 SkFDot6 dx = (SkLeftShift(x1, 1) - x0 - x2) >> 2; |
218 SkFDot6 dy = ((y1 << 1) - y0 - y2) >> 2; | 218 SkFDot6 dy = (SkLeftShift(y1, 1) - y0 - y2) >> 2; |
219 shift = diff_to_shift(dx, dy); | 219 shift = diff_to_shift(dx, dy); |
220 SkASSERT(shift >= 0); | 220 SkASSERT(shift >= 0); |
221 } | 221 } |
222 // need at least 1 subdivision for our bias trick | 222 // need at least 1 subdivision for our bias trick |
223 if (shift == 0) { | 223 if (shift == 0) { |
224 shift = 1; | 224 shift = 1; |
225 } else if (shift > MAX_COEFF_SHIFT) { | 225 } else if (shift > MAX_COEFF_SHIFT) { |
226 shift = MAX_COEFF_SHIFT; | 226 shift = MAX_COEFF_SHIFT; |
227 } | 227 } |
228 | 228 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 fQy = newy; | 305 fQy = newy; |
306 fQDx = dx; | 306 fQDx = dx; |
307 fQDy = dy; | 307 fQDy = dy; |
308 fCurveCount = SkToS8(count); | 308 fCurveCount = SkToS8(count); |
309 return success; | 309 return success; |
310 } | 310 } |
311 | 311 |
312 ///////////////////////////////////////////////////////////////////////// | 312 ///////////////////////////////////////////////////////////////////////// |
313 | 313 |
314 static inline int SkFDot6UpShift(SkFDot6 x, int upShift) { | 314 static inline int SkFDot6UpShift(SkFDot6 x, int upShift) { |
315 SkASSERT((x << upShift >> upShift) == x); | 315 SkASSERT((SkLeftShift(x, upShift) >> upShift) == x); |
316 return x << upShift; | 316 return SkLeftShift(x, upShift); |
317 } | 317 } |
318 | 318 |
319 /* f(1/3) = (8a + 12b + 6c + d) / 27 | 319 /* f(1/3) = (8a + 12b + 6c + d) / 27 |
320 f(2/3) = (a + 6b + 12c + 8d) / 27 | 320 f(2/3) = (a + 6b + 12c + 8d) / 27 |
321 | 321 |
322 f(1/3)-b = (8a - 15b + 6c + d) / 27 | 322 f(1/3)-b = (8a - 15b + 6c + d) / 27 |
323 f(2/3)-c = (a + 6b - 15c + 8d) / 27 | 323 f(2/3)-c = (a + 6b - 15c + 8d) / 27 |
324 | 324 |
325 use 16/512 to approximate 1/27 | 325 use 16/512 to approximate 1/27 |
326 */ | 326 */ |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 compute coefficients with a 3*, so the safest upshift is really 6 | 396 compute coefficients with a 3*, so the safest upshift is really 6 |
397 */ | 397 */ |
398 int upShift = 6; // largest safe value | 398 int upShift = 6; // largest safe value |
399 int downShift = shift + upShift - 10; | 399 int downShift = shift + upShift - 10; |
400 if (downShift < 0) { | 400 if (downShift < 0) { |
401 downShift = 0; | 401 downShift = 0; |
402 upShift = 10 - shift; | 402 upShift = 10 - shift; |
403 } | 403 } |
404 | 404 |
405 fWinding = SkToS8(winding); | 405 fWinding = SkToS8(winding); |
406 fCurveCount = SkToS8(-1 << shift); | 406 fCurveCount = SkToS8(SkLeftShift(-1, shift)); |
407 fCurveShift = SkToU8(shift); | 407 fCurveShift = SkToU8(shift); |
408 fCubicDShift = SkToU8(downShift); | 408 fCubicDShift = SkToU8(downShift); |
409 | 409 |
410 SkFixed B = SkFDot6UpShift(3 * (x1 - x0), upShift); | 410 SkFixed B = SkFDot6UpShift(3 * (x1 - x0), upShift); |
411 SkFixed C = SkFDot6UpShift(3 * (x0 - x1 - x1 + x2), upShift); | 411 SkFixed C = SkFDot6UpShift(3 * (x0 - x1 - x1 + x2), upShift); |
412 SkFixed D = SkFDot6UpShift(x3 + 3 * (x1 - x2) - x0, upShift); | 412 SkFixed D = SkFDot6UpShift(x3 + 3 * (x1 - x2) - x0, upShift); |
413 | 413 |
414 fCx = SkFDot6ToFixed(x0); | 414 fCx = SkFDot6ToFixed(x0); |
415 fCDx = B + (C >> shift) + (D >> 2*shift); // biased by shift | 415 fCDx = B + (C >> shift) + (D >> 2*shift); // biased by shift |
416 fCDDx = 2*C + (3*D >> (shift - 1)); // biased by 2*shift | 416 fCDDx = 2*C + (3*D >> (shift - 1)); // biased by 2*shift |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 success = this->updateLine(oldx, oldy, newx, newy); | 470 success = this->updateLine(oldx, oldy, newx, newy); |
471 oldx = newx; | 471 oldx = newx; |
472 oldy = newy; | 472 oldy = newy; |
473 } while (count < 0 && !success); | 473 } while (count < 0 && !success); |
474 | 474 |
475 fCx = newx; | 475 fCx = newx; |
476 fCy = newy; | 476 fCy = newy; |
477 fCurveCount = SkToS8(count); | 477 fCurveCount = SkToS8(count); |
478 return success; | 478 return success; |
479 } | 479 } |
OLD | NEW |