From a563162780d589938aef8a4d8b63d2957139313b Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Wed, 28 Oct 2009 14:27:20 +0000 Subject: move boundarypatch into utils git-svn-id: http://skia.googlecode.com/svn/trunk@410 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/utils/SkBoundaryPatch.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/utils/SkBoundaryPatch.cpp (limited to 'src') diff --git a/src/utils/SkBoundaryPatch.cpp b/src/utils/SkBoundaryPatch.cpp new file mode 100644 index 0000000000..cdbc877634 --- /dev/null +++ b/src/utils/SkBoundaryPatch.cpp @@ -0,0 +1,73 @@ +#include "SkBoundaryPatch.h" + +SkBoundaryPatch::SkBoundaryPatch() : fBoundary(NULL) {} + +SkBoundaryPatch::~SkBoundaryPatch() { + SkSafeUnref(fBoundary); +} + +SkBoundary* SkBoundaryPatch::setBoundary(SkBoundary* b) { + SkRefCnt_SafeAssign(fBoundary, b); + return b; +} + +static SkPoint SkMakePoint(SkScalar x, SkScalar y) { + SkPoint pt; + pt.set(x, y); + return pt; +} + +static SkPoint SkPointInterp(const SkPoint& a, const SkPoint& b, SkScalar t) { + return SkMakePoint(SkScalarInterp(a.fX, b.fX, t), + SkScalarInterp(a.fY, b.fY, t)); +} + +SkPoint SkBoundaryPatch::eval(SkScalar unitU, SkScalar unitV) { + SkBoundary* b = fBoundary; + SkPoint u = SkPointInterp(b->eval(SkBoundary::kLeft, SK_Scalar1 - unitV), + b->eval(SkBoundary::kRight, unitV), + unitU); + SkPoint v = SkPointInterp(b->eval(SkBoundary::kTop, unitU), + b->eval(SkBoundary::kBottom, SK_Scalar1 - unitU), + unitV); + return SkMakePoint(SkScalarAve(u.fX, v.fX), + SkScalarAve(u.fY, v.fY)); +} + +bool SkBoundaryPatch::evalPatch(SkPoint verts[], int rows, int cols) { + if (rows < 2 || cols < 2) { + return false; + } + + const SkScalar invR = SkScalarInvert(SkIntToScalar(rows - 1)); + const SkScalar invC = SkScalarInvert(SkIntToScalar(cols - 1)); + + for (int y = 0; y < cols; y++) { + SkScalar yy = y * invC; + for (int x = 0; x < rows; x++) { + *verts++ = this->eval(x * invR, yy); + } + } + return true; +} + +//////////////////////////////////////////////////////////////////////// + +#include "SkGeometry.h" + +SkPoint SkLineBoundary::eval(Edge e, SkScalar t) { + SkASSERT((unsigned)e < 4); + return SkPointInterp(fPts[e], fPts[(e + 1) & 3], t); +} + +SkPoint SkCubicBoundary::eval(Edge e, SkScalar t) { + SkASSERT((unsigned)e < 4); + + // ensure our 4th cubic wraps to the start of the first + fPts[12] = fPts[0]; + + SkPoint loc; + SkEvalCubicAt(&fPts[e * 3], t, &loc, NULL, NULL); + return loc; +} + -- cgit v1.2.3