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

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

Issue 1078413003: Speeup hairline curves (quads and cubics) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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/SkGeometry.h ('k') | src/core/SkScan_Hairline.cpp » ('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 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGeometry.h" 8 #include "SkGeometry.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 #include "SkNx.h" 10 #include "SkNx.h"
11 11
12 #if 0
12 static Sk2s from_point(const SkPoint& point) { 13 static Sk2s from_point(const SkPoint& point) {
13 return Sk2s::Load(&point.fX); 14 return Sk2s::Load(&point.fX);
14 } 15 }
15 16
16 static SkPoint to_point(const Sk2s& x) { 17 static SkPoint to_point(const Sk2s& x) {
17 SkPoint point; 18 SkPoint point;
18 x.store(&point.fX); 19 x.store(&point.fX);
19 return point; 20 return point;
20 } 21 }
22 #endif
21 23
22 static SkVector to_vector(const Sk2s& x) { 24 static SkVector to_vector(const Sk2s& x) {
23 SkVector vector; 25 SkVector vector;
24 x.store(&vector.fX); 26 x.store(&vector.fX);
25 return vector; 27 return vector;
26 } 28 }
27 29
28 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes 30 /** If defined, this makes eval_quad and eval_cubic do more setup (sometimes
29 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul. 31 involving integer multiplies by 2 or 3, but fewer calls to SkScalarMul.
30 May also introduce overflow of fixed when we compute our setup. 32 May also introduce overflow of fixed when we compute our setup.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 #endif 130 #endif
129 } 131 }
130 132
131 static SkScalar eval_quad_derivative(const SkScalar src[], SkScalar t) { 133 static SkScalar eval_quad_derivative(const SkScalar src[], SkScalar t) {
132 SkScalar A = src[4] - 2 * src[2] + src[0]; 134 SkScalar A = src[4] - 2 * src[2] + src[0];
133 SkScalar B = src[2] - src[0]; 135 SkScalar B = src[2] - src[0];
134 136
135 return 2 * SkScalarMulAdd(A, t, B); 137 return 2 * SkScalarMulAdd(A, t, B);
136 } 138 }
137 139
140 void SkQuadToCoeff(const SkPoint pts[3], SkPoint coeff[3]) {
141 Sk2s p0 = from_point(pts[0]);
142 Sk2s p1 = from_point(pts[1]);
143 Sk2s p2 = from_point(pts[2]);
144
145 Sk2s p1minus2 = p1 - p0;
146
147 coeff[0] = to_point(p2 - p1 - p1 + p0); // A * t^2
148 coeff[1] = to_point(p1minus2 + p1minus2); // B * t
149 coeff[2] = pts[0]; // C
150 }
151
138 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange nt) { 152 void SkEvalQuadAt(const SkPoint src[3], SkScalar t, SkPoint* pt, SkVector* tange nt) {
139 SkASSERT(src); 153 SkASSERT(src);
140 SkASSERT(t >= 0 && t <= SK_Scalar1); 154 SkASSERT(t >= 0 && t <= SK_Scalar1);
141 155
142 if (pt) { 156 if (pt) {
143 pt->set(eval_quad(&src[0].fX, t), eval_quad(&src[0].fY, t)); 157 pt->set(eval_quad(&src[0].fX, t), eval_quad(&src[0].fY, t));
144 } 158 }
145 if (tangent) { 159 if (tangent) {
146 tangent->set(eval_quad_derivative(&src[0].fX, t), 160 tangent->set(eval_quad_derivative(&src[0].fX, t),
147 eval_quad_derivative(&src[0].fY, t)); 161 eval_quad_derivative(&src[0].fY, t));
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 459
446 dst[0] = src[0]; 460 dst[0] = src[0];
447 dst[1] = to_point(ab); 461 dst[1] = to_point(ab);
448 dst[2] = to_point(abc); 462 dst[2] = to_point(abc);
449 dst[3] = to_point(abcd); 463 dst[3] = to_point(abcd);
450 dst[4] = to_point(bcd); 464 dst[4] = to_point(bcd);
451 dst[5] = to_point(cd); 465 dst[5] = to_point(cd);
452 dst[6] = src[3]; 466 dst[6] = src[3];
453 } 467 }
454 468
469 void SkCubicToCoeff(const SkPoint pts[4], SkPoint coeff[4]) {
470 Sk2s p0 = from_point(pts[0]);
471 Sk2s p1 = from_point(pts[1]);
472 Sk2s p2 = from_point(pts[2]);
473 Sk2s p3 = from_point(pts[3]);
474
475 const Sk2s three(3);
476 Sk2s p1minusp2 = p1 - p2;
477
478 Sk2s D = p0;
479 Sk2s A = p3 + three * p1minusp2 - D;
480 Sk2s B = three * (D - p1minusp2 - p1);
481 Sk2s C = three * (p1 - D);
482
483 coeff[0] = to_point(A);
484 coeff[1] = to_point(B);
485 coeff[2] = to_point(C);
486 coeff[3] = to_point(D);
487 }
488
455 /* http://code.google.com/p/skia/issues/detail?id=32 489 /* http://code.google.com/p/skia/issues/detail?id=32
456 490
457 This test code would fail when we didn't check the return result of 491 This test code would fail when we didn't check the return result of
458 valid_unit_divide in SkChopCubicAt(... tValues[], int roots). The reason is 492 valid_unit_divide in SkChopCubicAt(... tValues[], int roots). The reason is
459 that after the first chop, the parameters to valid_unit_divide are equal 493 that after the first chop, the parameters to valid_unit_divide are equal
460 (thanks to finite float precision and rounding in the subtracts). Thus 494 (thanks to finite float precision and rounding in the subtracts). Thus
461 even though the 2nd tValue looks < 1.0, after we renormalize it, we end 495 even though the 2nd tValue looks < 1.0, after we renormalize it, we end
462 up with 1.0, hence the need to check and just return the last cubic as 496 up with 1.0, hence the need to check and just return the last cubic as
463 a degenerate clump of 4 points in the sampe place. 497 a degenerate clump of 4 points in the sampe place.
464 498
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 matrix.preScale(SK_Scalar1, -SK_Scalar1); 1568 matrix.preScale(SK_Scalar1, -SK_Scalar1);
1535 } 1569 }
1536 if (userMatrix) { 1570 if (userMatrix) {
1537 matrix.postConcat(*userMatrix); 1571 matrix.postConcat(*userMatrix);
1538 } 1572 }
1539 for (int i = 0; i < conicCount; ++i) { 1573 for (int i = 0; i < conicCount; ++i) {
1540 matrix.mapPoints(dst[i].fPts, 3); 1574 matrix.mapPoints(dst[i].fPts, 3);
1541 } 1575 }
1542 return conicCount; 1576 return conicCount;
1543 } 1577 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.h ('k') | src/core/SkScan_Hairline.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698