diff options
author | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-03-28 20:47:09 +0000 |
---|---|---|
committer | senorblanco@chromium.org <senorblanco@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-03-28 20:47:09 +0000 |
commit | 9d18b7873ce9b44f130a41e0cbd0a3df76ab9adf (patch) | |
tree | 5f5f96e33ea96bdaf6c0dc4fbb32f78db26a4642 /gpu/src | |
parent | cae5fba82e687d674b076b10cdc8aba46e1ac3b3 (diff) |
This CL implements a tesselated path renderer, using GLU's libtess. All of the
fill modes except hairline are supported. Note that the path renderer is not
enabled by default; to enable it, replace "GrCreatePathRenderer_none.cpp" with
"GrCreatePathRenderer_tesselated.cpp" in skia.gyp, and run gyp_skia, and build.
This change also contains a number of build fixes for Win32 (for building
SampleApp on VS2008) and Mac (for my ancient Mac Pro which supports
GL_EXT_framebuffer_object but not GL_ARB_framebuffer_object). Also,
priorityq-heap.c was removed from the SampleApp build, since it's #included by
priorityq.c (weird, I know).
NB: When this change is rolled into chrome, some modifications to chromium's
skia.gyp will be necessary.
Review URL: http://codereview.appspot.com/4289072/
git-svn-id: http://skia.googlecode.com/svn/trunk@1012 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/src')
-rw-r--r-- | gpu/src/GrCreatePathRenderer_tesselated.cpp | 20 | ||||
-rw-r--r-- | gpu/src/GrGLInterface.cpp | 2 | ||||
-rw-r--r-- | gpu/src/GrGpu.cpp | 2 | ||||
-rw-r--r-- | gpu/src/GrPathRenderer.cpp | 148 | ||||
-rw-r--r-- | gpu/src/GrPathUtils.cpp | 144 | ||||
-rw-r--r-- | gpu/src/GrPathUtils.h | 52 | ||||
-rw-r--r-- | gpu/src/GrTesselatedPathRenderer.cpp | 276 |
7 files changed, 507 insertions, 137 deletions
diff --git a/gpu/src/GrCreatePathRenderer_tesselated.cpp b/gpu/src/GrCreatePathRenderer_tesselated.cpp new file mode 100644 index 0000000000..b00cf35cdc --- /dev/null +++ b/gpu/src/GrCreatePathRenderer_tesselated.cpp @@ -0,0 +1,20 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "GrTesselatedPathRenderer.h" + + +GrPathRenderer* GrPathRenderer::CreatePathRenderer() { return new GrTesselatedPathRenderer(); } diff --git a/gpu/src/GrGLInterface.cpp b/gpu/src/GrGLInterface.cpp index 9c3d5bbd6b..8be0f2bf13 100644 --- a/gpu/src/GrGLInterface.cpp +++ b/gpu/src/GrGLInterface.cpp @@ -147,7 +147,7 @@ void InitializeGLInterfaceExtensions(GrGLInterface* glBindings) { fboFound = true; } - #if GL_EXT_framebuffer_object && !GR_MAC_BUILD + #if GL_EXT_framebuffer_object if (!fboFound && has_gl_extension_from_string("GL_EXT_framebuffer_object", extensionString)) { diff --git a/gpu/src/GrGpu.cpp b/gpu/src/GrGpu.cpp index 4b52fd879c..1db92522c6 100644 --- a/gpu/src/GrGpu.cpp +++ b/gpu/src/GrGpu.cpp @@ -610,7 +610,7 @@ void GrGpu::prepareVertexPool() { } void GrGpu::prepareIndexPool() { - if (NULL == fVertexPool) { + if (NULL == fIndexPool) { fIndexPool = new GrIndexBufferAllocPool(this, true, 0, 1); } else if (!fIndexPoolInUse) { // the client doesn't have valid data in the pool diff --git a/gpu/src/GrPathRenderer.cpp b/gpu/src/GrPathRenderer.cpp index fc3c124ee0..f226a99873 100644 --- a/gpu/src/GrPathRenderer.cpp +++ b/gpu/src/GrPathRenderer.cpp @@ -3,6 +3,7 @@ #include "GrPoint.h" #include "GrDrawTarget.h" #include "GrPathIter.h" +#include "GrPathUtils.h" #include "GrMemory.h" #include "GrTexture.h" @@ -147,127 +148,6 @@ static const GrStencilSettings gDirectToStencil = { // Helpers for drawPath #define STENCIL_OFF 0 // Always disable stencil (even when needed) -static const GrScalar gTolerance = GR_Scalar1; - -static const uint32_t MAX_POINTS_PER_CURVE = 1 << 10; - -static uint32_t quadratic_point_count(const GrPoint points[], GrScalar tol) { - GrScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); - if (d < tol) { - return 1; - } else { - // Each time we subdivide, d should be cut in 4. So we need to - // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) - // points. - // 2^(log4(x)) = sqrt(x); - d = ceilf(sqrtf(d/tol)); - return GrMin(GrNextPow2((uint32_t)d), MAX_POINTS_PER_CURVE); - } -} - -static uint32_t generate_quadratic_points(const GrPoint& p0, - const GrPoint& p1, - const GrPoint& p2, - GrScalar tolSqd, - GrPoint** points, - uint32_t pointsLeft) { - if (pointsLeft < 2 || - (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) { - (*points)[0] = p2; - *points += 1; - return 1; - } - - GrPoint q[] = { - GrPoint(GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY)), - GrPoint(GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY)), - }; - GrPoint r(GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY)); - - pointsLeft >>= 1; - uint32_t a = generate_quadratic_points(p0, q[0], r, tolSqd, points, pointsLeft); - uint32_t b = generate_quadratic_points(r, q[1], p2, tolSqd, points, pointsLeft); - return a + b; -} - -static uint32_t cubic_point_count(const GrPoint points[], GrScalar tol) { - GrScalar d = GrMax(points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), - points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); - d = sqrtf(d); - if (d < tol) { - return 1; - } else { - d = ceilf(sqrtf(d/tol)); - return GrMin(GrNextPow2((uint32_t)d), MAX_POINTS_PER_CURVE); - } -} - -static uint32_t generate_cubic_points(const GrPoint& p0, - const GrPoint& p1, - const GrPoint& p2, - const GrPoint& p3, - GrScalar tolSqd, - GrPoint** points, - uint32_t pointsLeft) { - if (pointsLeft < 2 || - (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd && - p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) { - (*points)[0] = p3; - *points += 1; - return 1; - } - GrPoint q[] = { - GrPoint(GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY)), - GrPoint(GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY)), - GrPoint(GrScalarAve(p2.fX, p3.fX), GrScalarAve(p2.fY, p3.fY)) - }; - GrPoint r[] = { - GrPoint(GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY)), - GrPoint(GrScalarAve(q[1].fX, q[2].fX), GrScalarAve(q[1].fY, q[2].fY)) - }; - GrPoint s(GrScalarAve(r[0].fX, r[1].fX), GrScalarAve(r[0].fY, r[1].fY)); - pointsLeft >>= 1; - uint32_t a = generate_cubic_points(p0, q[0], r[0], s, tolSqd, points, pointsLeft); - uint32_t b = generate_cubic_points(s, r[1], q[2], p3, tolSqd, points, pointsLeft); - return a + b; -} - -static int worst_case_point_count(GrPathIter* path, - int* subpaths, - GrScalar tol) { - int pointCount = 0; - *subpaths = 1; - - bool first = true; - - GrPathCmd cmd; - - GrPoint pts[4]; - while ((cmd = path->next(pts)) != kEnd_PathCmd) { - - switch (cmd) { - case kLine_PathCmd: - pointCount += 1; - break; - case kQuadratic_PathCmd: - pointCount += quadratic_point_count(pts, tol); - break; - case kCubic_PathCmd: - pointCount += cubic_point_count(pts, tol); - break; - case kMove_PathCmd: - pointCount += 1; - if (!first) { - ++(*subpaths); - } - break; - default: - break; - } - first = false; - } - return pointCount; -} static inline bool single_pass_path(const GrDrawTarget& target, const GrPathIter& path, @@ -314,7 +194,7 @@ void GrDefaultPathRenderer::drawPathHelper(GrDrawTarget* target, // stretch when mapping to screen coordinates. GrScalar stretch = viewM.getMaxStretch(); bool useStretch = stretch > 0; - GrScalar tol = gTolerance; + GrScalar tol = GrPathUtils::gTolerance; if (!useStretch) { // TODO: deal with perspective in some better way. @@ -328,9 +208,7 @@ void GrDefaultPathRenderer::drawPathHelper(GrDrawTarget* target, path->rewind(); int subpathCnt; - int maxPts = worst_case_point_count(path, - &subpathCnt, - tol); + int maxPts = GrPathUtils::worstCasePointCount(path, &subpathCnt, tol); GrVertexLayout layout = 0; for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { @@ -468,15 +346,15 @@ void GrDefaultPathRenderer::drawPathHelper(GrDrawTarget* target, vert++; break; case kQuadratic_PathCmd: { - generate_quadratic_points(pts[0], pts[1], pts[2], - tolSqd, &vert, - quadratic_point_count(pts, tol)); + GrPathUtils::generateQuadraticPoints(pts[0], pts[1], pts[2], + tolSqd, &vert, + GrPathUtils::quadraticPointCount(pts, tol)); break; } case kCubic_PathCmd: { - generate_cubic_points(pts[0], pts[1], pts[2], pts[3], - tolSqd, &vert, - cubic_point_count(pts, tol)); + GrPathUtils::generateCubicPoints(pts[0], pts[1], pts[2], pts[3], + tolSqd, &vert, + GrPathUtils::cubicPointCount(pts, tol)); break; } case kClose_PathCmd: @@ -563,7 +441,7 @@ void GrDefaultPathRenderer::drawPathToStencil(GrDrawTarget* target, GrPathIter* path, GrPathFill fill, const GrPoint* translate) { - GrAssert(kInverseEvenOdd_PathFill != fill); - GrAssert(kInverseWinding_PathFill != fill); - this->drawPathHelper(target, 0, path, fill, translate, true); - } + GrAssert(kInverseEvenOdd_PathFill != fill); + GrAssert(kInverseWinding_PathFill != fill); + this->drawPathHelper(target, 0, path, fill, translate, true); +} diff --git a/gpu/src/GrPathUtils.cpp b/gpu/src/GrPathUtils.cpp new file mode 100644 index 0000000000..274dc49a57 --- /dev/null +++ b/gpu/src/GrPathUtils.cpp @@ -0,0 +1,144 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "GrPathUtils.h" + +#include "GrPathIter.h" +#include "GrPoint.h" + +const GrScalar GrPathUtils::gTolerance = GR_Scalar1; + +static const uint32_t MAX_POINTS_PER_CURVE = 1 << 10; + +uint32_t GrPathUtils::quadraticPointCount(const GrPoint points[], + GrScalar tol) { + GrScalar d = points[1].distanceToLineSegmentBetween(points[0], points[2]); + if (d < tol) { + return 1; + } else { + // Each time we subdivide, d should be cut in 4. So we need to + // subdivide x = log4(d/tol) times. x subdivisions creates 2^(x) + // points. + // 2^(log4(x)) = sqrt(x); + d = ceilf(sqrtf(d/tol)); + return GrMin(GrNextPow2((uint32_t)d), MAX_POINTS_PER_CURVE); + } +} + +uint32_t GrPathUtils::generateQuadraticPoints(const GrPoint& p0, + const GrPoint& p1, + const GrPoint& p2, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft) { + if (pointsLeft < 2 || + (p1.distanceToLineSegmentBetweenSqd(p0, p2)) < tolSqd) { + (*points)[0] = p2; + *points += 1; + return 1; + } + + GrPoint q[] = { + GrPoint(GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY)), + GrPoint(GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY)), + }; + GrPoint r(GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY)); + + pointsLeft >>= 1; + uint32_t a = generateQuadraticPoints(p0, q[0], r, tolSqd, points, pointsLeft); + uint32_t b = generateQuadraticPoints(r, q[1], p2, tolSqd, points, pointsLeft); + return a + b; +} + +uint32_t GrPathUtils::cubicPointCount(const GrPoint points[], + GrScalar tol) { + GrScalar d = GrMax(points[1].distanceToLineSegmentBetweenSqd(points[0], points[3]), + points[2].distanceToLineSegmentBetweenSqd(points[0], points[3])); + d = sqrtf(d); + if (d < tol) { + return 1; + } else { + d = ceilf(sqrtf(d/tol)); + return GrMin(GrNextPow2((uint32_t)d), MAX_POINTS_PER_CURVE); + } +} + +uint32_t GrPathUtils::generateCubicPoints(const GrPoint& p0, + const GrPoint& p1, + const GrPoint& p2, + const GrPoint& p3, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft) { + if (pointsLeft < 2 || + (p1.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd && + p2.distanceToLineSegmentBetweenSqd(p0, p3) < tolSqd)) { + (*points)[0] = p3; + *points += 1; + return 1; + } + GrPoint q[] = { + GrPoint(GrScalarAve(p0.fX, p1.fX), GrScalarAve(p0.fY, p1.fY)), + GrPoint(GrScalarAve(p1.fX, p2.fX), GrScalarAve(p1.fY, p2.fY)), + GrPoint(GrScalarAve(p2.fX, p3.fX), GrScalarAve(p2.fY, p3.fY)) + }; + GrPoint r[] = { + GrPoint(GrScalarAve(q[0].fX, q[1].fX), GrScalarAve(q[0].fY, q[1].fY)), + GrPoint(GrScalarAve(q[1].fX, q[2].fX), GrScalarAve(q[1].fY, q[2].fY)) + }; + GrPoint s(GrScalarAve(r[0].fX, r[1].fX), GrScalarAve(r[0].fY, r[1].fY)); + pointsLeft >>= 1; + uint32_t a = generateCubicPoints(p0, q[0], r[0], s, tolSqd, points, pointsLeft); + uint32_t b = generateCubicPoints(s, r[1], q[2], p3, tolSqd, points, pointsLeft); + return a + b; +} + +int GrPathUtils::worstCasePointCount(GrPathIter* path, + int* subpaths, + GrScalar tol) { + int pointCount = 0; + *subpaths = 1; + + bool first = true; + + GrPathCmd cmd; + + GrPoint pts[4]; + while ((cmd = path->next(pts)) != kEnd_PathCmd) { + + switch (cmd) { + case kLine_PathCmd: + pointCount += 1; + break; + case kQuadratic_PathCmd: + pointCount += quadraticPointCount(pts, tol); + break; + case kCubic_PathCmd: + pointCount += cubicPointCount(pts, tol); + break; + case kMove_PathCmd: + pointCount += 1; + if (!first) { + ++(*subpaths); + } + break; + default: + break; + } + first = false; + } + return pointCount; +} diff --git a/gpu/src/GrPathUtils.h b/gpu/src/GrPathUtils.h new file mode 100644 index 0000000000..97841dd1e2 --- /dev/null +++ b/gpu/src/GrPathUtils.h @@ -0,0 +1,52 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#ifndef GrPathUtils_DEFINED +#define GrPathUtils_DEFINED + +#include "GrNoncopyable.h" +#include "GrScalar.h" + +class GrPathIter; +struct GrPoint; + +/** + * Utilities for evaluating paths. + */ +class GrPathUtils : public GrNoncopyable { +public: + static int worstCasePointCount(GrPathIter* path, + int* subpaths, + GrScalar tol); + static uint32_t quadraticPointCount(const GrPoint points[], GrScalar tol); + static uint32_t generateQuadraticPoints(const GrPoint& p0, + const GrPoint& p1, + const GrPoint& p2, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft); + static uint32_t cubicPointCount(const GrPoint points[], GrScalar tol); + static uint32_t generateCubicPoints(const GrPoint& p0, + const GrPoint& p1, + const GrPoint& p2, + const GrPoint& p3, + GrScalar tolSqd, + GrPoint** points, + uint32_t pointsLeft); + + static const GrScalar gTolerance; +}; +#endif diff --git a/gpu/src/GrTesselatedPathRenderer.cpp b/gpu/src/GrTesselatedPathRenderer.cpp new file mode 100644 index 0000000000..95e8abe4ed --- /dev/null +++ b/gpu/src/GrTesselatedPathRenderer.cpp @@ -0,0 +1,276 @@ +/* + Copyright 2011 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "GrTesselatedPathRenderer.h" + +#include "GrMemory.h" +#include "GrPathUtils.h" + +#include <internal_glu.h> + +struct PolygonData { + PolygonData(GrTDArray<GrPoint>* vertices, GrTDArray<short>* indices) + : fVertices(vertices) + , fIndices(indices) + { + } + GrTDArray<GrPoint>* fVertices; + GrTDArray<short>* fIndices; +}; + +static void beginData(GLenum type, void* data) +{ + GR_DEBUGASSERT(type == GL_TRIANGLES); +} + +static void edgeFlagData(GLboolean flag, void* data) +{ +} + +static void vertexData(void* vertexData, void* data) +{ + short* end = static_cast<PolygonData*>(data)->fIndices->append(); + *end = reinterpret_cast<long>(vertexData); +} + +static void endData(void* data) +{ +} + +static void combineData(GLdouble coords[3], void* vertexData[4], + GLfloat weight[4], void **outData, void* data) +{ + PolygonData* polygonData = static_cast<PolygonData*>(data); + int index = polygonData->fVertices->count(); + *polygonData->fVertices->append() = GrPoint(static_cast<float>(coords[0]), + static_cast<float>(coords[1])); + *outData = reinterpret_cast<void*>(index); +} + +typedef void (*TESSCB)(); + +static unsigned fill_type_to_glu_winding_rule(GrPathFill fill) { + switch (fill) { + case kWinding_PathFill: + return GLU_TESS_WINDING_NONZERO; + case kEvenOdd_PathFill: + return GLU_TESS_WINDING_ODD; + case kInverseWinding_PathFill: + return GLU_TESS_WINDING_POSITIVE; + case kInverseEvenOdd_PathFill: + return GLU_TESS_WINDING_ODD; + case kHairLine_PathFill: + return GLU_TESS_WINDING_NONZERO; // FIXME: handle this + default: + GrAssert(!"Unknown path fill!"); + return 0; + } +} + +GrTesselatedPathRenderer::GrTesselatedPathRenderer() { +} + +void GrTesselatedPathRenderer::drawPath(GrDrawTarget* target, + GrDrawTarget::StageBitfield stages, + GrPathIter* path, + GrPathFill fill, + const GrPoint* translate) { + GrDrawTarget::AutoStateRestore asr(target); + bool colorWritesWereDisabled = target->isColorWriteDisabled(); + // face culling doesn't make sense here + GrAssert(GrDrawTarget::kBoth_DrawFace == target->getDrawFace()); + + GrMatrix viewM = target->getViewMatrix(); + // In order to tesselate the path we get a bound on how much the matrix can + // stretch when mapping to screen coordinates. + GrScalar stretch = viewM.getMaxStretch(); + bool useStretch = stretch > 0; + GrScalar tol = GrPathUtils::gTolerance; + + if (!useStretch) { + // TODO: deal with perspective in some better way. + tol /= 10; + } else { + GrScalar sinv = GR_Scalar1 / stretch; + tol = GrMul(tol, sinv); + } + GrScalar tolSqd = GrMul(tol, tol); + + path->rewind(); + + int subpathCnt; + int maxPts = GrPathUtils::worstCasePointCount(path, &subpathCnt, tol); + + GrVertexLayout layout = 0; + for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { + if ((1 << s) & stages) { + layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s); + } + } + + bool inverted = IsFillInverted(fill); + if (inverted) { + maxPts += 4; + subpathCnt++; + } + GrPoint* base = new GrPoint[maxPts]; + GrPoint* vert = base; + GrPoint* subpathBase = base; + + GrAutoSTMalloc<8, uint16_t> subpathVertCount(subpathCnt); + + path->rewind(); + + GrPoint pts[4]; + + bool first = true; + int subpath = 0; + + for (;;) { + GrPathCmd cmd = path->next(pts); + switch (cmd) { + case kMove_PathCmd: + if (!first) { + subpathVertCount[subpath] = vert-subpathBase; + subpathBase = vert; + ++subpath; + } + *vert = pts[0]; + vert++; + break; + case kLine_PathCmd: + *vert = pts[1]; + vert++; + break; + case kQuadratic_PathCmd: { + GrPathUtils::generateQuadraticPoints(pts[0], pts[1], pts[2], + tolSqd, &vert, + GrPathUtils::quadraticPointCount(pts, tol)); + break; + } + case kCubic_PathCmd: { + GrPathUtils::generateCubicPoints(pts[0], pts[1], pts[2], pts[3], + tolSqd, &vert, + GrPathUtils::cubicPointCount(pts, tol)); + break; + } + case kClose_PathCmd: + break; + case kEnd_PathCmd: + subpathVertCount[subpath] = vert-subpathBase; + ++subpath; // this could be only in debug + goto FINISHED; + } + first = false; + } +FINISHED: + if (translate) { + for (int i = 0; i < vert - base; i++) { + base[i].offset(translate->fX, translate->fY); + } + } + + if (inverted) { + GrRect bounds; + GrAssert(NULL != target->getRenderTarget()); + bounds.setLTRB(0, 0, + GrIntToScalar(target->getRenderTarget()->width()), + GrIntToScalar(target->getRenderTarget()->height())); + GrMatrix vmi; + if (target->getViewInverse(&vmi)) { + vmi.mapRect(&bounds); + } + *vert++ = GrPoint(bounds.fLeft, bounds.fTop); + *vert++ = GrPoint(bounds.fLeft, bounds.fBottom); + *vert++ = GrPoint(bounds.fRight, bounds.fBottom); + *vert++ = GrPoint(bounds.fRight, bounds.fTop); + subpathVertCount[subpath++] = 4; + } + + GrAssert(subpath == subpathCnt); + GrAssert((vert - base) <= maxPts); + + size_t count = vert - base; + + // FIXME: This copy could be removed if we had (templated?) versions of + // generate_*_point above that wrote directly into doubles. + double* inVertices = new double[count * 3]; + for (size_t i = 0; i < count; ++i) { + inVertices[i * 3] = base[i].fX; + inVertices[i * 3 + 1] = base[i].fY; + inVertices[i * 3 + 2] = 1.0; + } + + GLUtesselator* tess = internal_gluNewTess(); + unsigned windingRule = fill_type_to_glu_winding_rule(fill); + internal_gluTessProperty(tess, GLU_TESS_WINDING_RULE, windingRule); + internal_gluTessCallback(tess, GLU_TESS_BEGIN_DATA, (TESSCB) &beginData); + internal_gluTessCallback(tess, GLU_TESS_VERTEX_DATA, (TESSCB) &vertexData); + internal_gluTessCallback(tess, GLU_TESS_END_DATA, (TESSCB) &endData); + internal_gluTessCallback(tess, GLU_TESS_EDGE_FLAG_DATA, (TESSCB) &edgeFlagData); + internal_gluTessCallback(tess, GLU_TESS_COMBINE_DATA, (TESSCB) &combineData); + GrTDArray<short> indices; + GrTDArray<GrPoint> vertices; + PolygonData data(&vertices, &indices); + + internal_gluTessBeginPolygon(tess, &data); + size_t i = 0; + for (int sp = 0; sp < subpathCnt; ++sp) { + internal_gluTessBeginContour(tess); + int start = i; + int end = start + subpathVertCount[sp]; + for (; i < end; ++i) { + double* inVertex = &inVertices[i * 3]; + *vertices.append() = GrPoint(inVertex[0], inVertex[1]); + internal_gluTessVertex(tess, inVertex, reinterpret_cast<void*>(i)); + } + internal_gluTessEndContour(tess); + } + + internal_gluTessEndPolygon(tess); + internal_gluDeleteTess(tess); + + // FIXME: If we could figure out the maxIndices before running the + // tesselator, we could allocate the geometry upfront, rather than making + // yet another copy. + GrDrawTarget::AutoReleaseGeometry geom(target, layout, vertices.count(), indices.count()); + + memcpy(geom.vertices(), vertices.begin(), vertices.count() * sizeof(GrPoint)); + memcpy(geom.indices(), indices.begin(), indices.count() * sizeof(short)); + + if (indices.count() > 0) { + target->drawIndexed(kTriangles_PrimitiveType, + 0, + 0, + vertices.count(), + indices.count()); + } + delete[] inVertices; + delete[] base; +} + +bool GrTesselatedPathRenderer::canDrawPath(const GrDrawTarget* target, + GrPathIter* path, + GrPathFill fill) const { + return kHairLine_PathFill != fill; +} + +void GrTesselatedPathRenderer::drawPathToStencil(GrDrawTarget* target, + GrPathIter* path, + GrPathFill fill, + const GrPoint* translate) { + GrAlwaysAssert(!"multipass stencil should not be needed"); +} |