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

Side by Side Diff: src/gpu/GrPathUtils.cpp

Issue 22865023: Move gpu conic calculations to GrPathUtils (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/GrPathUtils.h ('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 2011 Google Inc. 2 * Copyright 2011 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 "GrPathUtils.h" 8 #include "GrPathUtils.h"
9 9
10 #include "GrPoint.h" 10 #include "GrPoint.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 fM[0] = m.get(SkMatrix::kMScaleX); 268 fM[0] = m.get(SkMatrix::kMScaleX);
269 fM[1] = m.get(SkMatrix::kMSkewX); 269 fM[1] = m.get(SkMatrix::kMSkewX);
270 fM[2] = m.get(SkMatrix::kMTransX); 270 fM[2] = m.get(SkMatrix::kMTransX);
271 fM[3] = m.get(SkMatrix::kMSkewY); 271 fM[3] = m.get(SkMatrix::kMSkewY);
272 fM[4] = m.get(SkMatrix::kMScaleY); 272 fM[4] = m.get(SkMatrix::kMScaleY);
273 fM[5] = m.get(SkMatrix::kMTransY); 273 fM[5] = m.get(SkMatrix::kMTransY);
274 } 274 }
275 } 275 }
276 } 276 }
277 277
278 ////////////////////////////////////////////////////////////////////////////////
279
280 // k = (y2 - y0, x0 - x2, (x2 - x0)*y0 - (y2 - y0)*x0 )
281 // l = (2*w * (y1 - y0), 2*w * (x0 - x1), 2*w * (x1*y0 - x0*y1))
282 // m = (2*w * (y2 - y1), 2*w * (x1 - x2), 2*w * (x2*y1 - x1*y2))
283 void GrPathUtils::getConicKLM(const SkPoint p[3], const SkScalar weight, SkScala r klm[9]) {
284 const SkScalar w2 = 2.f * weight;
285 klm[0] = p[2].fY - p[0].fY;
286 klm[1] = p[0].fX - p[2].fX;
287 klm[2] = (p[2].fX - p[0].fX) * p[0].fY - (p[2].fY - p[0].fY) * p[0].fX;
288
289 klm[3] = w2 * (p[1].fY - p[0].fY);
290 klm[4] = w2 * (p[0].fX - p[1].fX);
291 klm[5] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY);
292
293 klm[6] = w2 * (p[2].fY - p[1].fY);
294 klm[7] = w2 * (p[1].fX - p[2].fX);
295 klm[8] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY);
296
297 // scale the max absolute value of coeffs to 10
298 SkScalar scale = 0.f;
299 for (int i = 0; i < 9; ++i) {
300 scale = SkMaxScalar(scale, SkScalarAbs(klm[i]));
301 }
302 SkASSERT(scale > 0.f);
303 scale = 10.f / scale;
304 for (int i = 0; i < 9; ++i) {
305 klm[i] *= scale;
306 }
307 }
308
309 ////////////////////////////////////////////////////////////////////////////////
310
278 namespace { 311 namespace {
279 312
280 // a is the first control point of the cubic. 313 // a is the first control point of the cubic.
281 // ab is the vector from a to the second control point. 314 // ab is the vector from a to the second control point.
282 // dc is the vector from the fourth to the third control point. 315 // dc is the vector from the fourth to the third control point.
283 // d is the fourth control point. 316 // d is the fourth control point.
284 // p is the candidate quadratic control point. 317 // p is the candidate quadratic control point.
285 // this assumes that the cubic doesn't inflect and is simple 318 // this assumes that the cubic doesn't inflect and is simple
286 bool is_point_within_cubic_tangents(const SkPoint& a, 319 bool is_point_within_cubic_tangents(const SkPoint& a,
287 const SkVector& ab, 320 const SkVector& ab,
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 set_loop_klm(d, controlK, controlL, controlM); 831 set_loop_klm(d, controlK, controlL, controlM);
799 } else if (kCusp_CubicType == cType) { 832 } else if (kCusp_CubicType == cType) {
800 SkASSERT(0.f == d[0]); 833 SkASSERT(0.f == d[0]);
801 set_cusp_klm(d, controlK, controlL, controlM); 834 set_cusp_klm(d, controlK, controlL, controlM);
802 } else if (kQuadratic_CubicType == cType) { 835 } else if (kQuadratic_CubicType == cType) {
803 set_quadratic_klm(d, controlK, controlL, controlM); 836 set_quadratic_klm(d, controlK, controlL, controlM);
804 } 837 }
805 838
806 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]); 839 calc_cubic_klm(p, controlK, controlL, controlM, klm, &klm[3], &klm[6]);
807 } 840 }
OLDNEW
« no previous file with comments | « src/gpu/GrPathUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698