GrAAConvexPathRenderer.cpp revision 5d01bec07a0740b30e4ebc51eec9057009a09bc2
1 2/* 3 * Copyright 2012 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#include "GrAAConvexPathRenderer.h" 10 11#include "GrContext.h" 12#include "GrDrawState.h" 13#include "GrDrawTargetCaps.h" 14#include "GrEffect.h" 15#include "GrPathUtils.h" 16#include "GrTBackendEffectFactory.h" 17#include "SkString.h" 18#include "SkStrokeRec.h" 19#include "SkTrace.h" 20 21#include "gl/GrGLEffect.h" 22#include "gl/GrGLSL.h" 23 24GrAAConvexPathRenderer::GrAAConvexPathRenderer() { 25} 26 27namespace { 28 29struct Segment { 30 enum { 31 // These enum values are assumed in member functions below. 32 kLine = 0, 33 kQuad = 1, 34 } fType; 35 36 // line uses one pt, quad uses 2 pts 37 GrPoint fPts[2]; 38 // normal to edge ending at each pt 39 GrVec fNorms[2]; 40 // is the corner where the previous segment meets this segment 41 // sharp. If so, fMid is a normalized bisector facing outward. 42 GrVec fMid; 43 44 int countPoints() { 45 GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); 46 return fType + 1; 47 } 48 const SkPoint& endPt() const { 49 GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); 50 return fPts[fType]; 51 }; 52 const SkPoint& endNorm() const { 53 GR_STATIC_ASSERT(0 == kLine && 1 == kQuad); 54 return fNorms[fType]; 55 }; 56}; 57 58typedef SkTArray<Segment, true> SegmentArray; 59 60void center_of_mass(const SegmentArray& segments, SkPoint* c) { 61 SkScalar area = 0; 62 SkPoint center = {0, 0}; 63 int count = segments.count(); 64 SkPoint p0 = {0, 0}; 65 if (count > 2) { 66 // We translate the polygon so that the first point is at the origin. 67 // This avoids some precision issues with small area polygons far away 68 // from the origin. 69 p0 = segments[0].endPt(); 70 SkPoint pi; 71 SkPoint pj; 72 // the first and last iteration of the below loop would compute 73 // zeros since the starting / ending point is (0,0). So instead we start 74 // at i=1 and make the last iteration i=count-2. 75 pj = segments[1].endPt() - p0; 76 for (int i = 1; i < count - 1; ++i) { 77 pi = pj; 78 const SkPoint pj = segments[i + 1].endPt() - p0; 79 80 SkScalar t = SkScalarMul(pi.fX, pj.fY) - SkScalarMul(pj.fX, pi.fY); 81 area += t; 82 center.fX += (pi.fX + pj.fX) * t; 83 center.fY += (pi.fY + pj.fY) * t; 84 85 } 86 } 87 // If the poly has no area then we instead return the average of 88 // its points. 89 if (SkScalarNearlyZero(area)) { 90 SkPoint avg; 91 avg.set(0, 0); 92 for (int i = 0; i < count; ++i) { 93 const SkPoint& pt = segments[i].endPt(); 94 avg.fX += pt.fX; 95 avg.fY += pt.fY; 96 } 97 SkScalar denom = SK_Scalar1 / count; 98 avg.scale(denom); 99 *c = avg; 100 } else { 101 area *= 3; 102 area = SkScalarDiv(SK_Scalar1, area); 103 center.fX = SkScalarMul(center.fX, area); 104 center.fY = SkScalarMul(center.fY, area); 105 // undo the translate of p0 to the origin. 106 *c = center + p0; 107 } 108 GrAssert(!SkScalarIsNaN(c->fX) && !SkScalarIsNaN(c->fY)); 109} 110 111void compute_vectors(SegmentArray* segments, 112 SkPoint* fanPt, 113 SkPath::Direction dir, 114 int* vCount, 115 int* iCount) { 116 center_of_mass(*segments, fanPt); 117 int count = segments->count(); 118 119 // Make the normals point towards the outside 120 GrPoint::Side normSide; 121 if (dir == SkPath::kCCW_Direction) { 122 normSide = GrPoint::kRight_Side; 123 } else { 124 normSide = GrPoint::kLeft_Side; 125 } 126 127 *vCount = 0; 128 *iCount = 0; 129 // compute normals at all points 130 for (int a = 0; a < count; ++a) { 131 const Segment& sega = (*segments)[a]; 132 int b = (a + 1) % count; 133 Segment& segb = (*segments)[b]; 134 135 const GrPoint* prevPt = &sega.endPt(); 136 int n = segb.countPoints(); 137 for (int p = 0; p < n; ++p) { 138 segb.fNorms[p] = segb.fPts[p] - *prevPt; 139 segb.fNorms[p].normalize(); 140 segb.fNorms[p].setOrthog(segb.fNorms[p], normSide); 141 prevPt = &segb.fPts[p]; 142 } 143 if (Segment::kLine == segb.fType) { 144 *vCount += 5; 145 *iCount += 9; 146 } else { 147 *vCount += 6; 148 *iCount += 12; 149 } 150 } 151 152 // compute mid-vectors where segments meet. TODO: Detect shallow corners 153 // and leave out the wedges and close gaps by stitching segments together. 154 for (int a = 0; a < count; ++a) { 155 const Segment& sega = (*segments)[a]; 156 int b = (a + 1) % count; 157 Segment& segb = (*segments)[b]; 158 segb.fMid = segb.fNorms[0] + sega.endNorm(); 159 segb.fMid.normalize(); 160 // corner wedges 161 *vCount += 4; 162 *iCount += 6; 163 } 164} 165 166struct DegenerateTestData { 167 DegenerateTestData() { fStage = kInitial; } 168 bool isDegenerate() const { return kNonDegenerate != fStage; } 169 enum { 170 kInitial, 171 kPoint, 172 kLine, 173 kNonDegenerate 174 } fStage; 175 GrPoint fFirstPoint; 176 GrVec fLineNormal; 177 SkScalar fLineC; 178}; 179 180void update_degenerate_test(DegenerateTestData* data, const GrPoint& pt) { 181 static const SkScalar TOL = (SK_Scalar1 / 16); 182 static const SkScalar TOL_SQD = SkScalarMul(TOL, TOL); 183 184 switch (data->fStage) { 185 case DegenerateTestData::kInitial: 186 data->fFirstPoint = pt; 187 data->fStage = DegenerateTestData::kPoint; 188 break; 189 case DegenerateTestData::kPoint: 190 if (pt.distanceToSqd(data->fFirstPoint) > TOL_SQD) { 191 data->fLineNormal = pt - data->fFirstPoint; 192 data->fLineNormal.normalize(); 193 data->fLineNormal.setOrthog(data->fLineNormal); 194 data->fLineC = -data->fLineNormal.dot(data->fFirstPoint); 195 data->fStage = DegenerateTestData::kLine; 196 } 197 break; 198 case DegenerateTestData::kLine: 199 if (SkScalarAbs(data->fLineNormal.dot(pt) + data->fLineC) > TOL) { 200 data->fStage = DegenerateTestData::kNonDegenerate; 201 } 202 case DegenerateTestData::kNonDegenerate: 203 break; 204 default: 205 GrCrash("Unexpected degenerate test stage."); 206 } 207} 208 209inline bool get_direction(const SkPath& path, const SkMatrix& m, SkPath::Direction* dir) { 210 if (!path.cheapComputeDirection(dir)) { 211 return false; 212 } 213 // check whether m reverses the orientation 214 GrAssert(!m.hasPerspective()); 215 SkScalar det2x2 = SkScalarMul(m.get(SkMatrix::kMScaleX), m.get(SkMatrix::kMScaleY)) - 216 SkScalarMul(m.get(SkMatrix::kMSkewX), m.get(SkMatrix::kMSkewY)); 217 if (det2x2 < 0) { 218 *dir = SkPath::OppositeDirection(*dir); 219 } 220 return true; 221} 222 223bool get_segments(const SkPath& path, 224 const SkMatrix& m, 225 SegmentArray* segments, 226 SkPoint* fanPt, 227 int* vCount, 228 int* iCount) { 229 SkPath::Iter iter(path, true); 230 // This renderer over-emphasizes very thin path regions. We use the distance 231 // to the path from the sample to compute coverage. Every pixel intersected 232 // by the path will be hit and the maximum distance is sqrt(2)/2. We don't 233 // notice that the sample may be close to a very thin area of the path and 234 // thus should be very light. This is particularly egregious for degenerate 235 // line paths. We detect paths that are very close to a line (zero area) and 236 // draw nothing. 237 DegenerateTestData degenerateData; 238 SkPath::Direction dir; 239 // get_direction can fail for some degenerate paths. 240 if (!get_direction(path, m, &dir)) { 241 return false; 242 } 243 244 for (;;) { 245 GrPoint pts[4]; 246 GrPathCmd cmd = (GrPathCmd)iter.next(pts); 247 switch (cmd) { 248 case kMove_PathCmd: 249 m.mapPoints(pts, 1); 250 update_degenerate_test(°enerateData, pts[0]); 251 break; 252 case kLine_PathCmd: { 253 m.mapPoints(pts + 1, 1); 254 update_degenerate_test(°enerateData, pts[1]); 255 segments->push_back(); 256 segments->back().fType = Segment::kLine; 257 segments->back().fPts[0] = pts[1]; 258 break; 259 } 260 case kQuadratic_PathCmd: 261 m.mapPoints(pts + 1, 2); 262 update_degenerate_test(°enerateData, pts[1]); 263 update_degenerate_test(°enerateData, pts[2]); 264 segments->push_back(); 265 segments->back().fType = Segment::kQuad; 266 segments->back().fPts[0] = pts[1]; 267 segments->back().fPts[1] = pts[2]; 268 break; 269 case kCubic_PathCmd: { 270 m.mapPoints(pts, 4); 271 update_degenerate_test(°enerateData, pts[1]); 272 update_degenerate_test(°enerateData, pts[2]); 273 update_degenerate_test(°enerateData, pts[3]); 274 // unlike quads and lines, the pts[0] will also be read (in 275 // convertCubicToQuads). 276 SkSTArray<15, SkPoint, true> quads; 277 GrPathUtils::convertCubicToQuads(pts, SK_Scalar1, true, dir, &quads); 278 int count = quads.count(); 279 for (int q = 0; q < count; q += 3) { 280 segments->push_back(); 281 segments->back().fType = Segment::kQuad; 282 segments->back().fPts[0] = quads[q + 1]; 283 segments->back().fPts[1] = quads[q + 2]; 284 } 285 break; 286 }; 287 case kEnd_PathCmd: 288 if (degenerateData.isDegenerate()) { 289 return false; 290 } else { 291 compute_vectors(segments, fanPt, dir, vCount, iCount); 292 return true; 293 } 294 default: 295 break; 296 } 297 } 298} 299 300struct QuadVertex { 301 GrPoint fPos; 302 GrPoint fUV; 303 SkScalar fD0; 304 SkScalar fD1; 305}; 306 307void create_vertices(const SegmentArray& segments, 308 const SkPoint& fanPt, 309 QuadVertex* verts, 310 uint16_t* idxs) { 311 int v = 0; 312 int i = 0; 313 314 int count = segments.count(); 315 for (int a = 0; a < count; ++a) { 316 const Segment& sega = segments[a]; 317 int b = (a + 1) % count; 318 const Segment& segb = segments[b]; 319 320 // FIXME: These tris are inset in the 1 unit arc around the corner 321 verts[v + 0].fPos = sega.endPt(); 322 verts[v + 1].fPos = verts[v + 0].fPos + sega.endNorm(); 323 verts[v + 2].fPos = verts[v + 0].fPos + segb.fMid; 324 verts[v + 3].fPos = verts[v + 0].fPos + segb.fNorms[0]; 325 verts[v + 0].fUV.set(0,0); 326 verts[v + 1].fUV.set(0,-SK_Scalar1); 327 verts[v + 2].fUV.set(0,-SK_Scalar1); 328 verts[v + 3].fUV.set(0,-SK_Scalar1); 329 verts[v + 0].fD0 = verts[v + 0].fD1 = -SK_Scalar1; 330 verts[v + 1].fD0 = verts[v + 1].fD1 = -SK_Scalar1; 331 verts[v + 2].fD0 = verts[v + 2].fD1 = -SK_Scalar1; 332 verts[v + 3].fD0 = verts[v + 3].fD1 = -SK_Scalar1; 333 334 idxs[i + 0] = v + 0; 335 idxs[i + 1] = v + 2; 336 idxs[i + 2] = v + 1; 337 idxs[i + 3] = v + 0; 338 idxs[i + 4] = v + 3; 339 idxs[i + 5] = v + 2; 340 341 v += 4; 342 i += 6; 343 344 if (Segment::kLine == segb.fType) { 345 verts[v + 0].fPos = fanPt; 346 verts[v + 1].fPos = sega.endPt(); 347 verts[v + 2].fPos = segb.fPts[0]; 348 349 verts[v + 3].fPos = verts[v + 1].fPos + segb.fNorms[0]; 350 verts[v + 4].fPos = verts[v + 2].fPos + segb.fNorms[0]; 351 352 // we draw the line edge as a degenerate quad (u is 0, v is the 353 // signed distance to the edge) 354 SkScalar dist = fanPt.distanceToLineBetween(verts[v + 1].fPos, 355 verts[v + 2].fPos); 356 verts[v + 0].fUV.set(0, dist); 357 verts[v + 1].fUV.set(0, 0); 358 verts[v + 2].fUV.set(0, 0); 359 verts[v + 3].fUV.set(0, -SK_Scalar1); 360 verts[v + 4].fUV.set(0, -SK_Scalar1); 361 362 verts[v + 0].fD0 = verts[v + 0].fD1 = -SK_Scalar1; 363 verts[v + 1].fD0 = verts[v + 1].fD1 = -SK_Scalar1; 364 verts[v + 2].fD0 = verts[v + 2].fD1 = -SK_Scalar1; 365 verts[v + 3].fD0 = verts[v + 3].fD1 = -SK_Scalar1; 366 verts[v + 4].fD0 = verts[v + 4].fD1 = -SK_Scalar1; 367 368 idxs[i + 0] = v + 0; 369 idxs[i + 1] = v + 2; 370 idxs[i + 2] = v + 1; 371 372 idxs[i + 3] = v + 3; 373 idxs[i + 4] = v + 1; 374 idxs[i + 5] = v + 2; 375 376 idxs[i + 6] = v + 4; 377 idxs[i + 7] = v + 3; 378 idxs[i + 8] = v + 2; 379 380 v += 5; 381 i += 9; 382 } else { 383 GrPoint qpts[] = {sega.endPt(), segb.fPts[0], segb.fPts[1]}; 384 385 GrVec midVec = segb.fNorms[0] + segb.fNorms[1]; 386 midVec.normalize(); 387 388 verts[v + 0].fPos = fanPt; 389 verts[v + 1].fPos = qpts[0]; 390 verts[v + 2].fPos = qpts[2]; 391 verts[v + 3].fPos = qpts[0] + segb.fNorms[0]; 392 verts[v + 4].fPos = qpts[2] + segb.fNorms[1]; 393 verts[v + 5].fPos = qpts[1] + midVec; 394 395 SkScalar c = segb.fNorms[0].dot(qpts[0]); 396 verts[v + 0].fD0 = -segb.fNorms[0].dot(fanPt) + c; 397 verts[v + 1].fD0 = 0.f; 398 verts[v + 2].fD0 = -segb.fNorms[0].dot(qpts[2]) + c; 399 verts[v + 3].fD0 = -SK_ScalarMax/100; 400 verts[v + 4].fD0 = -SK_ScalarMax/100; 401 verts[v + 5].fD0 = -SK_ScalarMax/100; 402 403 c = segb.fNorms[1].dot(qpts[2]); 404 verts[v + 0].fD1 = -segb.fNorms[1].dot(fanPt) + c; 405 verts[v + 1].fD1 = -segb.fNorms[1].dot(qpts[0]) + c; 406 verts[v + 2].fD1 = 0.f; 407 verts[v + 3].fD1 = -SK_ScalarMax/100; 408 verts[v + 4].fD1 = -SK_ScalarMax/100; 409 verts[v + 5].fD1 = -SK_ScalarMax/100; 410 411 GrPathUtils::QuadUVMatrix toUV(qpts); 412 toUV.apply<6, sizeof(QuadVertex), sizeof(GrPoint)>(verts + v); 413 414 idxs[i + 0] = v + 3; 415 idxs[i + 1] = v + 1; 416 idxs[i + 2] = v + 2; 417 idxs[i + 3] = v + 4; 418 idxs[i + 4] = v + 3; 419 idxs[i + 5] = v + 2; 420 421 idxs[i + 6] = v + 5; 422 idxs[i + 7] = v + 3; 423 idxs[i + 8] = v + 4; 424 425 idxs[i + 9] = v + 0; 426 idxs[i + 10] = v + 2; 427 idxs[i + 11] = v + 1; 428 429 v += 6; 430 i += 12; 431 } 432 } 433} 434 435} 436 437/////////////////////////////////////////////////////////////////////////////// 438 439/* 440 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first 441 * two components of the vertex attribute. Coverage is based on signed 442 * distance with negative being inside, positive outside. The edge is specified in 443 * window space (y-down). If either the third or fourth component of the interpolated 444 * vertex coord is > 0 then the pixel is considered outside the edge. This is used to 445 * attempt to trim to a portion of the infinite quad. 446 * Requires shader derivative instruction support. 447 */ 448 449class QuadEdgeEffect : public GrEffect { 450public: 451 452 static GrEffectRef* Create() { 453 // we go through this so we only have one copy of each effect 454 static SkAutoTUnref<GrEffectRef> gQuadEdgeEffectRef( 455 CreateEffectRef(AutoEffectUnref(SkNEW(QuadEdgeEffect)))); 456 457 gQuadEdgeEffectRef.get()->ref(); 458 return gQuadEdgeEffectRef; 459 } 460 461 virtual ~QuadEdgeEffect() {} 462 463 static const char* Name() { return "QuadEdge"; } 464 465 virtual void getConstantColorComponents(GrColor* color, 466 uint32_t* validFlags) const SK_OVERRIDE { 467 *validFlags = 0; 468 } 469 470 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { 471 return GrTBackendEffectFactory<QuadEdgeEffect>::getInstance(); 472 } 473 474 class GLEffect : public GrGLEffect { 475 public: 476 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) 477 : INHERITED (factory) {} 478 479 virtual void emitCode(GrGLShaderBuilder* builder, 480 const GrDrawEffect& drawEffect, 481 EffectKey key, 482 const char* outputColor, 483 const char* inputColor, 484 const TextureSamplerArray& samplers) SK_OVERRIDE { 485 const char *vsName, *fsName; 486 const SkString* attrName = 487 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); 488 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); 489 490 SkAssertResult(builder->enableFeature( 491 GrGLShaderBuilder::kStandardDerivatives_GLSLFeature)); 492 builder->addVarying(kVec4f_GrSLType, "QuadEdge", &vsName, &fsName); 493 494 // keep the derivative instructions outside the conditional 495 builder->fsCodeAppendf("\t\tvec2 duvdx = dFdx(%s.xy);\n", fsName); 496 builder->fsCodeAppendf("\t\tvec2 duvdy = dFdy(%s.xy);\n", fsName); 497 builder->fsCodeAppendf("\t\tif (%s.z > 0.0 && %s.w > 0.0) {\n", fsName, fsName); 498 // today we know z and w are in device space. We could use derivatives 499 builder->fsCodeAppendf("\t\t\tedgeAlpha = min(min(%s.z, %s.w) + 0.5, 1.0);\n", fsName, 500 fsName); 501 builder->fsCodeAppendf ("\t\t} else {\n"); 502 builder->fsCodeAppendf("\t\t\tvec2 gF = vec2(2.0*%s.x*duvdx.x - duvdx.y,\n" 503 "\t\t\t 2.0*%s.x*duvdy.x - duvdy.y);\n", 504 fsName, fsName); 505 builder->fsCodeAppendf("\t\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, 506 fsName); 507 builder->fsCodeAppendf("\t\t\tedgeAlpha = " 508 "clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n\t\t}\n"); 509 510 SkString modulate; 511 GrGLSLModulate4f(&modulate, inputColor, "edgeAlpha"); 512 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()); 513 514 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); 515 } 516 517 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) { 518 return 0x0; 519 } 520 521 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {} 522 523 private: 524 typedef GrGLEffect INHERITED; 525 }; 526 527private: 528 QuadEdgeEffect() { 529 this->addVertexAttrib(kVec4f_GrSLType); 530 } 531 532 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE { 533 return true; 534 } 535 536 GR_DECLARE_EFFECT_TEST; 537 538 typedef GrEffect INHERITED; 539}; 540 541GR_DEFINE_EFFECT_TEST(QuadEdgeEffect); 542 543GrEffectRef* QuadEdgeEffect::TestCreate(SkMWCRandom* random, 544 GrContext*, 545 const GrDrawTargetCaps& caps, 546 GrTexture*[]) { 547 // Doesn't work without derivative instructions. 548 return caps.shaderDerivativeSupport() ? QuadEdgeEffect::Create() : NULL; 549} 550 551/////////////////////////////////////////////////////////////////////////////// 552 553bool GrAAConvexPathRenderer::canDrawPath(const SkPath& path, 554 const SkStrokeRec& stroke, 555 const GrDrawTarget* target, 556 bool antiAlias) const { 557 return (target->caps()->shaderDerivativeSupport() && antiAlias && 558 stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()); 559} 560 561bool GrAAConvexPathRenderer::onDrawPath(const SkPath& origPath, 562 const SkStrokeRec&, 563 GrDrawTarget* target, 564 bool antiAlias) { 565 566 const SkPath* path = &origPath; 567 if (path->isEmpty()) { 568 return true; 569 } 570 571 GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kPreserve_ASRInit); 572 GrDrawState* drawState = target->drawState(); 573 574 GrDrawState::AutoDeviceCoordDraw adcd(drawState); 575 if (!adcd.succeeded()) { 576 return false; 577 } 578 const SkMatrix* vm = &adcd.getOriginalMatrix(); 579 580 // We use the fact that SkPath::transform path does subdivision based on 581 // perspective. Otherwise, we apply the view matrix when copying to the 582 // segment representation. 583 SkPath tmpPath; 584 if (vm->hasPerspective()) { 585 origPath.transform(*vm, &tmpPath); 586 path = &tmpPath; 587 vm = &SkMatrix::I(); 588 } 589 590 QuadVertex *verts; 591 uint16_t* idxs; 592 593 int vCount; 594 int iCount; 595 enum { 596 kPreallocSegmentCnt = 512 / sizeof(Segment), 597 }; 598 SkSTArray<kPreallocSegmentCnt, Segment, true> segments; 599 SkPoint fanPt; 600 601 if (!get_segments(*path, *vm, &segments, &fanPt, &vCount, &iCount)) { 602 return false; 603 } 604 605 // position + edge 606 static const GrVertexAttrib kAttribs[] = { 607 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 608 {kVec4f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} 609 }; 610 drawState->setVertexAttribs(kAttribs, SK_ARRAY_COUNT(kAttribs)); 611 612 enum { 613 // the edge effects share this stage with glyph rendering 614 // (kGlyphMaskStage in GrTextContext) && SW path rendering 615 // (kPathMaskStage in GrSWMaskHelper) 616 kEdgeEffectStage = GrPaint::kTotalStages, 617 }; 618 static const int kEdgeAttrIndex = 1; 619 GrEffectRef* quadEffect = QuadEdgeEffect::Create(); 620 drawState->setEffect(kEdgeEffectStage, quadEffect, kEdgeAttrIndex)->unref(); 621 622 GrDrawTarget::AutoReleaseGeometry arg(target, vCount, iCount); 623 if (!arg.succeeded()) { 624 return false; 625 } 626 GrAssert(sizeof(QuadVertex) == drawState->getVertexSize()); 627 verts = reinterpret_cast<QuadVertex*>(arg.vertices()); 628 idxs = reinterpret_cast<uint16_t*>(arg.indices()); 629 630 create_vertices(segments, fanPt, verts, idxs); 631 632 target->drawIndexed(kTriangles_GrPrimitiveType, 633 0, // start vertex 634 0, // start index 635 vCount, 636 iCount); 637 638 return true; 639} 640