Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(564)

Side by Side Diff: src/core/SkEdge.cpp

Issue 270263005: Use even rounding for better results when converting from scalar to fdot6 (Closed) Base URL: https://skia.googlesource.com/skia.git@neon
Patch Set: Protect behind an ifdef Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkEdge.h ('k') | src/core/SkFDot6.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 18 matching lines...) Expand all
29 return value << (16 - 6 - 1); 29 return 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
40 x0 = SkScalarRoundToFDot6(p0.fX, shift);
41 y0 = SkScalarRoundToFDot6(p0.fY, shift);
42 x1 = SkScalarRoundToFDot6(p1.fX, shift);
43 y1 = SkScalarRoundToFDot6(p1.fY, shift);
44 #else
39 float scale = float(1 << (shift + 6)); 45 float scale = float(1 << (shift + 6));
40 x0 = int(p0.fX * scale); 46 x0 = int(p0.fX * scale);
41 y0 = int(p0.fY * scale); 47 y0 = int(p0.fY * scale);
42 x1 = int(p1.fX * scale); 48 x1 = int(p1.fX * scale);
43 y1 = int(p1.fY * scale); 49 y1 = int(p1.fY * scale);
50 #endif
44 } 51 }
45 52
46 int winding = 1; 53 int winding = 1;
47 54
48 if (y0 > y1) { 55 if (y0 > y1) {
49 SkTSwap(x0, x1); 56 SkTSwap(x0, x1);
50 SkTSwap(y0, y1); 57 SkTSwap(y0, y1);
51 winding = -1; 58 winding = -1;
52 } 59 }
53 60
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 171
165 // each subdivision (shift value) cuts this dist (error) by 1/4 172 // each subdivision (shift value) cuts this dist (error) by 1/4
166 return (32 - SkCLZ(dist)) >> 1; 173 return (32 - SkCLZ(dist)) >> 1;
167 } 174 }
168 175
169 int SkQuadraticEdge::setQuadratic(const SkPoint pts[3], int shift) 176 int SkQuadraticEdge::setQuadratic(const SkPoint pts[3], int shift)
170 { 177 {
171 SkFDot6 x0, y0, x1, y1, x2, y2; 178 SkFDot6 x0, y0, x1, y1, x2, y2;
172 179
173 { 180 {
181 #ifdef SK_RASTERIZE_EVEN_ROUNDING
182 x0 = SkScalarRoundToFDot6(pts[0].fX, shift);
183 y0 = SkScalarRoundToFDot6(pts[0].fY, shift);
184 x1 = SkScalarRoundToFDot6(pts[1].fX, shift);
185 y1 = SkScalarRoundToFDot6(pts[1].fY, shift);
186 x2 = SkScalarRoundToFDot6(pts[2].fX, shift);
187 y2 = SkScalarRoundToFDot6(pts[2].fY, shift);
188 #else
174 float scale = float(1 << (shift + 6)); 189 float scale = float(1 << (shift + 6));
175 x0 = int(pts[0].fX * scale); 190 x0 = int(pts[0].fX * scale);
176 y0 = int(pts[0].fY * scale); 191 y0 = int(pts[0].fY * scale);
177 x1 = int(pts[1].fX * scale); 192 x1 = int(pts[1].fX * scale);
178 y1 = int(pts[1].fY * scale); 193 y1 = int(pts[1].fY * scale);
179 x2 = int(pts[2].fX * scale); 194 x2 = int(pts[2].fX * scale);
180 y2 = int(pts[2].fY * scale); 195 y2 = int(pts[2].fY * scale);
196 #endif
181 } 197 }
182 198
183 int winding = 1; 199 int winding = 1;
184 if (y0 > y2) 200 if (y0 > y2)
185 { 201 {
186 SkTSwap(x0, x2); 202 SkTSwap(x0, x2);
187 SkTSwap(y0, y2); 203 SkTSwap(y0, y2);
188 winding = -1; 204 winding = -1;
189 } 205 }
190 SkASSERT(y0 <= y1 && y1 <= y2); 206 SkASSERT(y0 <= y1 && y1 <= y2);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 SkFDot6 twoThird = (a + 6*b - ((c << 4) - c) + (d << 3)) * 19 >> 9; 330 SkFDot6 twoThird = (a + 6*b - ((c << 4) - c) + (d << 3)) * 19 >> 9;
315 331
316 return SkMax32(SkAbs32(oneThird), SkAbs32(twoThird)); 332 return SkMax32(SkAbs32(oneThird), SkAbs32(twoThird));
317 } 333 }
318 334
319 int SkCubicEdge::setCubic(const SkPoint pts[4], const SkIRect* clip, int shift) 335 int SkCubicEdge::setCubic(const SkPoint pts[4], const SkIRect* clip, int shift)
320 { 336 {
321 SkFDot6 x0, y0, x1, y1, x2, y2, x3, y3; 337 SkFDot6 x0, y0, x1, y1, x2, y2, x3, y3;
322 338
323 { 339 {
340 #ifdef SK_RASTERIZE_EVEN_ROUNDING
341 x0 = SkScalarRoundToFDot6(pts[0].fX, shift);
342 y0 = SkScalarRoundToFDot6(pts[0].fY, shift);
343 x1 = SkScalarRoundToFDot6(pts[1].fX, shift);
344 y1 = SkScalarRoundToFDot6(pts[1].fY, shift);
345 x2 = SkScalarRoundToFDot6(pts[2].fX, shift);
346 y2 = SkScalarRoundToFDot6(pts[2].fY, shift);
347 x3 = SkScalarRoundToFDot6(pts[3].fX, shift);
348 y3 = SkScalarRoundToFDot6(pts[3].fY, shift);
349 #else
324 float scale = float(1 << (shift + 6)); 350 float scale = float(1 << (shift + 6));
325 x0 = int(pts[0].fX * scale); 351 x0 = int(pts[0].fX * scale);
326 y0 = int(pts[0].fY * scale); 352 y0 = int(pts[0].fY * scale);
327 x1 = int(pts[1].fX * scale); 353 x1 = int(pts[1].fX * scale);
328 y1 = int(pts[1].fY * scale); 354 y1 = int(pts[1].fY * scale);
329 x2 = int(pts[2].fX * scale); 355 x2 = int(pts[2].fX * scale);
330 y2 = int(pts[2].fY * scale); 356 y2 = int(pts[2].fY * scale);
331 x3 = int(pts[3].fX * scale); 357 x3 = int(pts[3].fX * scale);
332 y3 = int(pts[3].fY * scale); 358 y3 = int(pts[3].fY * scale);
359 #endif
333 } 360 }
334 361
335 int winding = 1; 362 int winding = 1;
336 if (y0 > y3) 363 if (y0 > y3)
337 { 364 {
338 SkTSwap(x0, x3); 365 SkTSwap(x0, x3);
339 SkTSwap(x1, x2); 366 SkTSwap(x1, x2);
340 SkTSwap(y0, y3); 367 SkTSwap(y0, y3);
341 SkTSwap(y1, y2); 368 SkTSwap(y1, y2);
342 winding = -1; 369 winding = -1;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 success = this->updateLine(oldx, oldy, newx, newy); 485 success = this->updateLine(oldx, oldy, newx, newy);
459 oldx = newx; 486 oldx = newx;
460 oldy = newy; 487 oldy = newy;
461 } while (count < 0 && !success); 488 } while (count < 0 && !success);
462 489
463 fCx = newx; 490 fCx = newx;
464 fCy = newy; 491 fCy = newy;
465 fCurveCount = SkToS8(count); 492 fCurveCount = SkToS8(count);
466 return success; 493 return success;
467 } 494 }
OLDNEW
« no previous file with comments | « src/core/SkEdge.h ('k') | src/core/SkFDot6.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698