From 139484095f014ab08265c32337fddeeec6c0877d Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Tue, 20 Aug 2013 17:55:43 +0000 Subject: [PATCH] Move gpu conic calculations to GrPathUtils BUG= R=bsalomon@google.com, jvanverth@google.com Author: egdaniel@google.com Review URL: https://chromiumcodereview.appspot.com/22865023 git-svn-id: http://skia.googlecode.com/svn/trunk@10832 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrAAHairLinePathRenderer.cpp | 61 ++++++------------------------------ src/gpu/GrPathUtils.cpp | 33 +++++++++++++++++++ src/gpu/GrPathUtils.h | 9 ++++++ 3 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/gpu/GrAAHairLinePathRenderer.cpp b/src/gpu/GrAAHairLinePathRenderer.cpp index 2b5f3cc..f8c47d8 100644 --- a/src/gpu/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/GrAAHairLinePathRenderer.cpp @@ -600,72 +600,29 @@ void bloat_quad(const SkPoint qpts[3], const SkMatrix* toDevice, } } -// Input: -// Three control points: p[0], p[1], p[2] and weight: w -// Output: -// Let: -// l = (2*w * (y1 - y0), 2*w * (x0 - x1), 2*w * (x1*y0 - x0*y1)) -// m = (2*w * (y2 - y1), 2*w * (x1 - x2), 2*w * (x2*y1 - x1*y2)) -// k = (y2 - y0, x0 - x2, (x2 - x0)*y0 - (y2 - y0)*x0 ) -void calc_conic_klm(const SkPoint p[3], const SkScalar weight, - SkScalar k[3], SkScalar l[3], SkScalar m[3]) { - const SkScalar w2 = 2 * weight; - l[0] = w2 * (p[1].fY - p[0].fY); - l[1] = w2 * (p[0].fX - p[1].fX); - l[2] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY); - - m[0] = w2 * (p[2].fY - p[1].fY); - m[1] = w2 * (p[1].fX - p[2].fX); - m[2] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY); - - k[0] = p[2].fY - p[0].fY; - k[1] = p[0].fX - p[2].fX; - k[2] = (p[2].fX - p[0].fX) * p[0].fY - (p[2].fY - p[0].fY) * p[0].fX; - - // scale the max absolute value of coeffs to 10 - SkScalar scale = 0.0f; - for (int i = 0; i < 3; ++i) { - scale = SkMaxScalar(scale, SkScalarAbs(k[i])); - scale = SkMaxScalar(scale, SkScalarAbs(l[i])); - scale = SkMaxScalar(scale, SkScalarAbs(m[i])); - } - SkASSERT(scale > 0); - scale /= 10.0f; - k[0] /= scale; - k[1] /= scale; - k[2] /= scale; - l[0] /= scale; - l[1] /= scale; - l[2] /= scale; - m[0] /= scale; - m[1] /= scale; - m[2] /= scale; -} - // Equations based off of Loop-Blinn Quadratic GPU Rendering // Input Parametric: // P(t) = (P0*(1-t)^2 + 2*w*P1*t*(1-t) + P2*t^2) / (1-t)^2 + 2*w*t*(1-t) + t^2) // Output Implicit: // f(x, y, w) = f(P) = K^2 - LM // K = dot(k, P), L = dot(l, P), M = dot(m, P) -// k, l, m are calculated in function calc_conic_klm -void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kVertsPerQuad], const float weight) { - SkScalar k[3]; - SkScalar l[3]; - SkScalar m[3]; +// k, l, m are calculated in function GrPathUtils::getConicKLM +void set_conic_coeffs(const SkPoint p[3], BezierVertex verts[kVertsPerQuad], + const SkScalar weight) { + SkScalar klm[9]; - calc_conic_klm(p, weight, k, l, m); + GrPathUtils::getConicKLM(p, weight, klm); for (int i = 0; i < kVertsPerQuad; ++i) { const SkPoint pnt = verts[i].fPos; - verts[i].fConic.fK = pnt.fX * k[0] + pnt.fY * k[1] + k[2]; - verts[i].fConic.fL = pnt.fX * l[0] + pnt.fY * l[1] + l[2]; - verts[i].fConic.fM = pnt.fX * m[0] + pnt.fY * m[1] + m[2]; + verts[i].fConic.fK = pnt.fX * klm[0] + pnt.fY * klm[1] + klm[2]; + verts[i].fConic.fL = pnt.fX * klm[3] + pnt.fY * klm[4] + klm[5]; + verts[i].fConic.fM = pnt.fX * klm[6] + pnt.fY * klm[7] + klm[8]; } } void add_conics(const SkPoint p[3], - float weight, + const SkScalar weight, const SkMatrix* toDevice, const SkMatrix* toSrc, BezierVertex** vert, diff --git a/src/gpu/GrPathUtils.cpp b/src/gpu/GrPathUtils.cpp index ca87833..e354e41 100644 --- a/src/gpu/GrPathUtils.cpp +++ b/src/gpu/GrPathUtils.cpp @@ -275,6 +275,39 @@ void GrPathUtils::QuadUVMatrix::set(const GrPoint qPts[3]) { } } +//////////////////////////////////////////////////////////////////////////////// + +// k = (y2 - y0, x0 - x2, (x2 - x0)*y0 - (y2 - y0)*x0 ) +// l = (2*w * (y1 - y0), 2*w * (x0 - x1), 2*w * (x1*y0 - x0*y1)) +// m = (2*w * (y2 - y1), 2*w * (x1 - x2), 2*w * (x2*y1 - x1*y2)) +void GrPathUtils::getConicKLM(const SkPoint p[3], const SkScalar weight, SkScalar klm[9]) { + const SkScalar w2 = 2.f * weight; + klm[0] = p[2].fY - p[0].fY; + klm[1] = p[0].fX - p[2].fX; + klm[2] = (p[2].fX - p[0].fX) * p[0].fY - (p[2].fY - p[0].fY) * p[0].fX; + + klm[3] = w2 * (p[1].fY - p[0].fY); + klm[4] = w2 * (p[0].fX - p[1].fX); + klm[5] = w2 * (p[1].fX * p[0].fY - p[0].fX * p[1].fY); + + klm[6] = w2 * (p[2].fY - p[1].fY); + klm[7] = w2 * (p[1].fX - p[2].fX); + klm[8] = w2 * (p[2].fX * p[1].fY - p[1].fX * p[2].fY); + + // scale the max absolute value of coeffs to 10 + SkScalar scale = 0.f; + for (int i = 0; i < 9; ++i) { + scale = SkMaxScalar(scale, SkScalarAbs(klm[i])); + } + SkASSERT(scale > 0.f); + scale = 10.f / scale; + for (int i = 0; i < 9; ++i) { + klm[i] *= scale; + } +} + +//////////////////////////////////////////////////////////////////////////////// + namespace { // a is the first control point of the cubic. diff --git a/src/gpu/GrPathUtils.h b/src/gpu/GrPathUtils.h index dc4ecd9..71f6e0b 100644 --- a/src/gpu/GrPathUtils.h +++ b/src/gpu/GrPathUtils.h @@ -97,6 +97,15 @@ namespace GrPathUtils { float fM[6]; }; + // Input is 3 control points and a weight for a bezier conic. Calculates the + // three linear functionals (K,L,M) that represent the implicit equation of the + // conic, K^2 - LM. + // + // Output: + // K = (klm[0], klm[1], klm[2]) + // L = (klm[3], klm[4], klm[5]) + // M = (klm[6], klm[7], klm[8]) + void getConicKLM(const SkPoint p[3], const SkScalar weight, SkScalar klm[9]); // Converts a cubic into a sequence of quads. If working in device space // use tolScale = 1, otherwise set based on stretchiness of the matrix. The -- 2.7.4