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

Side by Side Diff: src/utils/SkPatchUtils.cpp

Issue 1633143002: move more geometry to simd (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: confirmed that only gm tests that call cubic eval change Created 4 years, 10 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/SkScan_Hairline.cpp ('k') | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 Google Inc.
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 "SkPatchUtils.h" 8 #include "SkPatchUtils.h"
9 9
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 12 matching lines...) Expand all
23 * For the cubic case the first difference gives as a result a quadratic polynom ial to which we can 23 * For the cubic case the first difference gives as a result a quadratic polynom ial to which we can
24 * apply again forward differences and get linear function to which we can apply again forward 24 * apply again forward differences and get linear function to which we can apply again forward
25 * differences to get a constant difference. This is why we keep an array of siz e 4, the 0th 25 * differences to get a constant difference. This is why we keep an array of siz e 4, the 0th
26 * position keeps the sampled value while the next ones keep the quadratic, line ar and constant 26 * position keeps the sampled value while the next ones keep the quadratic, line ar and constant
27 * difference values. 27 * difference values.
28 */ 28 */
29 29
30 class FwDCubicEvaluator { 30 class FwDCubicEvaluator {
31 31
32 public: 32 public:
33 FwDCubicEvaluator()
34 : fMax(0)
35 , fCurrent(0)
36 , fDivisions(0) {
37 memset(fPoints, 0, 4 * sizeof(SkPoint));
38 memset(fPoints, 0, 4 * sizeof(SkPoint));
39 memset(fPoints, 0, 4 * sizeof(SkPoint));
40 }
41 33
42 /** 34 /**
43 * Receives the 4 control points of the cubic bezier. 35 * Receives the 4 control points of the cubic bezier.
44 */ 36 */
45 FwDCubicEvaluator(SkPoint a, SkPoint b, SkPoint c, SkPoint d) { 37
46 fPoints[0] = a; 38 explicit FwDCubicEvaluator(const SkPoint points[4])
47 fPoints[1] = b; 39 : fCoefs(points) {
48 fPoints[2] = c; 40 memcpy(fPoints, points, 4 * sizeof(SkPoint));
49 fPoints[3] = d;
50
51 SkCubicToCoeff(fPoints, fCoefs);
52 41
53 this->restart(1); 42 this->restart(1);
54 } 43 }
55 44
56 explicit FwDCubicEvaluator(const SkPoint points[4]) {
57 memcpy(fPoints, points, 4 * sizeof(SkPoint));
58
59 SkCubicToCoeff(fPoints, fCoefs);
60
61 this->restart(1);
62 }
63
64 /** 45 /**
65 * Restarts the forward differences evaluator to the first value of t = 0. 46 * Restarts the forward differences evaluator to the first value of t = 0.
66 */ 47 */
67 void restart(int divisions) { 48 void restart(int divisions) {
68 fDivisions = divisions; 49 fDivisions = divisions;
69 SkScalar h = 1.f / fDivisions;
70 fCurrent = 0; 50 fCurrent = 0;
71 fMax = fDivisions + 1; 51 fMax = fDivisions + 1;
72 fFwDiff[0] = fCoefs[3]; 52 Sk2s h = Sk2s(1.f / fDivisions);
73 SkScalar h2 = h * h; 53 Sk2s h2 = h * h;
74 SkScalar h3 = h2 * h; 54 Sk2s h3 = h2 * h;
75 55 Sk2s fwDiff3 = Sk2s(6) * fCoefs.fA * h3;
76 fFwDiff[3].set(6.f * fCoefs[0].x() * h3, 6.f * fCoefs[0].y() * h3); //6a h^3 56 fFwDiff[3] = to_point(fwDiff3);
77 fFwDiff[2].set(fFwDiff[3].x() + 2.f * fCoefs[1].x() * h2, //6ah^3 + 2bh^ 2 57 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
78 fFwDiff[3].y() + 2.f * fCoefs[1].y() * h2); 58 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
79 fFwDiff[1].set(fCoefs[0].x() * h3 + fCoefs[1].x() * h2 + fCoefs[2].x() * h,//ah^3 + bh^2 +ch 59 fFwDiff[0] = to_point(fCoefs.fD);
80 fCoefs[0].y() * h3 + fCoefs[1].y() * h2 + fCoefs[2].y() * h);
81 } 60 }
82 61
83 /** 62 /**
84 * Check if the evaluator is still within the range of 0<=t<=1 63 * Check if the evaluator is still within the range of 0<=t<=1
85 */ 64 */
86 bool done() const { 65 bool done() const {
87 return fCurrent > fMax; 66 return fCurrent > fMax;
88 } 67 }
89 68
90 /** 69 /**
91 * Call next to obtain the SkPoint sampled and move to the next one. 70 * Call next to obtain the SkPoint sampled and move to the next one.
92 */ 71 */
93 SkPoint next() { 72 SkPoint next() {
94 SkPoint point = fFwDiff[0]; 73 SkPoint point = fFwDiff[0];
95 fFwDiff[0] += fFwDiff[1]; 74 fFwDiff[0] += fFwDiff[1];
96 fFwDiff[1] += fFwDiff[2]; 75 fFwDiff[1] += fFwDiff[2];
97 fFwDiff[2] += fFwDiff[3]; 76 fFwDiff[2] += fFwDiff[3];
98 fCurrent++; 77 fCurrent++;
99 return point; 78 return point;
100 } 79 }
101 80
102 const SkPoint* getCtrlPoints() const { 81 const SkPoint* getCtrlPoints() const {
103 return fPoints; 82 return fPoints;
104 } 83 }
105 84
106 private: 85 private:
86 SkCubicCoeff fCoefs;
107 int fMax, fCurrent, fDivisions; 87 int fMax, fCurrent, fDivisions;
108 SkPoint fFwDiff[4], fCoefs[4], fPoints[4]; 88 SkPoint fFwDiff[4], fPoints[4];
109 }; 89 };
110 90
111 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
112 92
113 // size in pixels of each partition per axis, adjust this knob 93 // size in pixels of each partition per axis, adjust this knob
114 static const int kPartitionSize = 10; 94 static const int kPartitionSize = 10;
115 95
116 /** 96 /**
117 * Calculate the approximate arc length given a bezier curve's control points. 97 * Calculate the approximate arc length given a bezier curve's control points.
118 */ 98 */
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 data->fIndices[i + 4] = data->fIndices[i + 2]; 302 data->fIndices[i + 4] = data->fIndices[i + 2];
323 data->fIndices[i + 5] = (x + 1) * stride + y; 303 data->fIndices[i + 5] = (x + 1) * stride + y;
324 } 304 }
325 v = SkScalarClampMax(v + 1.f / lodY, 1); 305 v = SkScalarClampMax(v + 1.f / lodY, 1);
326 } 306 }
327 u = SkScalarClampMax(u + 1.f / lodX, 1); 307 u = SkScalarClampMax(u + 1.f / lodX, 1);
328 } 308 }
329 return true; 309 return true;
330 310
331 } 311 }
OLDNEW
« no previous file with comments | « src/core/SkScan_Hairline.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698