diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-15 13:51:08 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-03-15 13:51:08 +0000 |
commit | 1971317bb43580330a9e7e9a1c09c5025fe84aac (patch) | |
tree | bf0aa1899f5d47350a8283cc564f5d3813ababaf /src/gpu/GrPathUtils.h | |
parent | 7816a4e840d7b5703d8b90731f80c2d88170d7f9 (diff) |
Allow compiler to optimize applying quadratic UV matrix to verts
Code Review: http://codereview.appspot.com/5833048/
git-svn-id: http://skia.googlecode.com/svn/trunk@3398 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/GrPathUtils.h')
-rw-r--r-- | src/gpu/GrPathUtils.h | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/gpu/GrPathUtils.h b/src/gpu/GrPathUtils.h index df2e16c57c..403f03ae16 100644 --- a/src/gpu/GrPathUtils.h +++ b/src/gpu/GrPathUtils.h @@ -27,18 +27,22 @@ namespace GrPathUtils { int worstCasePointCount(const GrPath&, int* subpaths, GrScalar tol); + /// Since we divide by tol if we're computing exact worst-case bounds, /// very small tolerances will be increased to gMinCurveTol. uint32_t quadraticPointCount(const GrPoint points[], GrScalar tol); + uint32_t generateQuadraticPoints(const GrPoint& p0, const GrPoint& p1, const GrPoint& p2, GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft); + /// Since we divide by tol if we're computing exact worst-case bounds, /// very small tolerances will be increased to gMinCurveTol. uint32_t cubicPointCount(const GrPoint points[], GrScalar tol); + uint32_t generateCubicPoints(const GrPoint& p0, const GrPoint& p1, const GrPoint& p2, @@ -46,10 +50,52 @@ namespace GrPathUtils { GrScalar tolSqd, GrPoint** points, uint32_t pointsLeft); - // Compute a matrix that goes from the 2d space coordinates to UV space - // where u^2-v = 0 specifies the quad. - void quadDesignSpaceToUVCoordsMatrix(const GrPoint qPts[3], - GrMatrix* matrix); + + // A 2x3 matrix that goes from the 2d space coordinates to UV space where + // u^2-v = 0 specifies the quad. The matrix is determined by the control + // points of the quadratic. + class QuadUVMatrix { + public: + QuadUVMatrix() {}; + // Initialize the matrix from the control pts + QuadUVMatrix(const GrPoint controlPts[3]) { this->set(controlPts); } + void set(const GrPoint controlPts[3]); + + /** + * Applies the matrix to vertex positions to compute UV coords. This + * has been templated so that the compiler can easliy unroll the loop + * and reorder to avoid stalling for loads. The assumption is that a + * path renderer will have a small fixed number of vertices that it + * uploads for each quad. + * + * N is the number of vertices. + * STRIDE is the size of each vertex. + * UV_OFFSET is the offset of the UV values within each vertex. + * vertices is a pointer to the first vertex. + */ + template <int N, size_t STRIDE, size_t UV_OFFSET> + void apply(const void* vertices) { + intptr_t xyPtr = reinterpret_cast<intptr_t>(vertices); + intptr_t uvPtr = reinterpret_cast<intptr_t>(vertices) + UV_OFFSET; + float sx = fM[0]; + float kx = fM[1]; + float tx = fM[2]; + float ky = fM[3]; + float sy = fM[4]; + float ty = fM[5]; + for (int i = 0; i < N; ++i) { + const GrPoint* xy = reinterpret_cast<const GrPoint*>(xyPtr); + GrPoint* uv = reinterpret_cast<GrPoint*>(uvPtr); + uv->fX = sx * xy->fX + kx * xy->fY + tx; + uv->fY = ky * xy->fX + sy * xy->fY + ty; + xyPtr += STRIDE; + uvPtr += STRIDE; + } + } + private: + float fM[6]; + }; + // 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 // result is sets of 3 points in quads (TODO: share endpoints in returned |