| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrDefaultPathRenderer.h" | 8 #include "GrDefaultPathRenderer.h" |
| 9 | 9 |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 *vertexCnt = static_cast<int>(vert - base); | 322 *vertexCnt = static_cast<int>(vert - base); |
| 323 *indexCnt = static_cast<int>(idx - idxBase); | 323 *indexCnt = static_cast<int>(idx - idxBase); |
| 324 | 324 |
| 325 } | 325 } |
| 326 return true; | 326 return true; |
| 327 } | 327 } |
| 328 | 328 |
| 329 bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, | 329 bool GrDefaultPathRenderer::internalDrawPath(GrDrawTarget* target, |
| 330 GrDrawState* drawState, | 330 GrDrawState* drawState, |
| 331 GrColor color, | 331 GrColor color, |
| 332 const SkMatrix& viewMatrix, |
| 332 const SkPath& path, | 333 const SkPath& path, |
| 333 const SkStrokeRec& origStroke, | 334 const SkStrokeRec& origStroke, |
| 334 bool stencilOnly) { | 335 bool stencilOnly) { |
| 335 SkMatrix viewM = drawState->getViewMatrix(); | |
| 336 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); | 336 SkTCopyOnFirstWrite<SkStrokeRec> stroke(origStroke); |
| 337 | 337 |
| 338 SkScalar hairlineCoverage; | 338 SkScalar hairlineCoverage; |
| 339 uint8_t newCoverage = 0xff; | 339 uint8_t newCoverage = 0xff; |
| 340 if (IsStrokeHairlineOrEquivalent(*stroke, drawState->getViewMatrix(), | 340 if (IsStrokeHairlineOrEquivalent(*stroke, viewMatrix, &hairlineCoverage)) { |
| 341 &hairlineCoverage)) { | |
| 342 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | 341 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
| 343 | 342 |
| 344 if (!stroke->isHairlineStyle()) { | 343 if (!stroke->isHairlineStyle()) { |
| 345 stroke.writable()->setHairlineStyle(); | 344 stroke.writable()->setHairlineStyle(); |
| 346 } | 345 } |
| 347 } | 346 } |
| 348 | 347 |
| 349 SkScalar tol = SK_Scalar1; | 348 SkScalar tol = SK_Scalar1; |
| 350 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); | 349 tol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, path.getBounds()); |
| 351 | 350 |
| 352 int vertexCnt; | 351 int vertexCnt; |
| 353 int indexCnt; | 352 int indexCnt; |
| 354 GrPrimitiveType primType; | 353 GrPrimitiveType primType; |
| 355 GrDrawTarget::AutoReleaseGeometry arg; | 354 GrDrawTarget::AutoReleaseGeometry arg; |
| 356 if (!this->createGeom(target, | 355 if (!this->createGeom(target, |
| 357 drawState, | 356 drawState, |
| 358 &primType, | 357 &primType, |
| 359 &vertexCnt, | 358 &vertexCnt, |
| 360 &indexCnt, | 359 &indexCnt, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 454 } |
| 456 break; | 455 break; |
| 457 default: | 456 default: |
| 458 SkDEBUGFAIL("Unknown path fFill!"); | 457 SkDEBUGFAIL("Unknown path fFill!"); |
| 459 return false; | 458 return false; |
| 460 } | 459 } |
| 461 } | 460 } |
| 462 } | 461 } |
| 463 | 462 |
| 464 SkRect devBounds; | 463 SkRect devBounds; |
| 465 GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds); | 464 GetPathDevBounds(path, drawState->getRenderTarget(), viewMatrix, &devBounds)
; |
| 466 | 465 |
| 467 for (int p = 0; p < passCount; ++p) { | 466 for (int p = 0; p < passCount; ++p) { |
| 468 drawState->setDrawFace(drawFace[p]); | 467 drawState->setDrawFace(drawFace[p]); |
| 469 if (passes[p]) { | 468 if (passes[p]) { |
| 470 *drawState->stencil() = *passes[p]; | 469 *drawState->stencil() = *passes[p]; |
| 471 } | 470 } |
| 472 | 471 |
| 473 if (lastPassIsBounds && (p == passCount-1)) { | 472 if (lastPassIsBounds && (p == passCount-1)) { |
| 474 // Reset the XP Factory on drawState | 473 // Reset the XP Factory on drawState |
| 475 drawState->setXPFactory(backupXPFactory); | 474 drawState->setXPFactory(backupXPFactory); |
| 476 SkRect bounds; | 475 SkRect bounds; |
| 477 GrDrawState::AutoViewMatrixRestore avmr; | |
| 478 const SkMatrix& viewMatrix = drawState->getViewMatrix(); | |
| 479 SkMatrix localMatrix = SkMatrix::I(); | 476 SkMatrix localMatrix = SkMatrix::I(); |
| 480 if (reverse) { | 477 if (reverse) { |
| 481 SkASSERT(drawState->getRenderTarget()); | 478 SkASSERT(drawState->getRenderTarget()); |
| 482 // draw over the dev bounds (which will be the whole dst surface
for inv fill). | 479 // draw over the dev bounds (which will be the whole dst surface
for inv fill). |
| 483 bounds = devBounds; | 480 bounds = devBounds; |
| 484 SkMatrix vmi; | 481 SkMatrix vmi; |
| 485 // mapRect through persp matrix may not be correct | 482 // mapRect through persp matrix may not be correct |
| 486 if (!drawState->getViewMatrix().hasPerspective() && | 483 if (!viewMatrix.hasPerspective() && viewMatrix.invert(&vmi)) { |
| 487 drawState->getViewInverse(&vmi)) { | |
| 488 vmi.mapRect(&bounds); | 484 vmi.mapRect(&bounds); |
| 489 } else { | 485 } else { |
| 490 if (!viewMatrix.invert(&localMatrix)) { | 486 if (!viewMatrix.invert(&localMatrix)) { |
| 491 return false; | 487 return false; |
| 492 } | 488 } |
| 493 avmr.setIdentity(drawState); | |
| 494 } | 489 } |
| 495 } else { | 490 } else { |
| 496 bounds = path.getBounds(); | 491 bounds = path.getBounds(); |
| 497 } | 492 } |
| 498 GrDrawTarget::AutoGeometryPush agp(target); | 493 GrDrawTarget::AutoGeometryPush agp(target); |
| 499 target->drawRect(drawState, color, bounds, NULL, &localMatrix); | 494 const SkMatrix& viewM = (reverse && viewMatrix.hasPerspective()) ? S
kMatrix::I() : |
| 495 v
iewMatrix; |
| 496 target->drawRect(drawState, color, viewM, bounds, NULL, &localMatrix
); |
| 500 } else { | 497 } else { |
| 501 if (passCount > 1) { | 498 if (passCount > 1) { |
| 502 drawState->setDisableColorXPFactory(); | 499 drawState->setDisableColorXPFactory(); |
| 503 } | 500 } |
| 504 GrDrawState::AutoRestoreEffects are(drawState); | 501 GrDrawState::AutoRestoreEffects are(drawState); |
| 505 SkAutoTUnref<const GrGeometryProcessor> gp( | 502 SkAutoTUnref<const GrGeometryProcessor> gp( |
| 506 GrDefaultGeoProcFactory::Create(color, | 503 GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPo
sition_GPType, |
| 507 GrDefaultGeoProcFactory::kPo
sition_GPType, | 504 color, |
| 505 viewMatrix, |
| 506 SkMatrix::I(), |
| 508 false, | 507 false, |
| 509 newCoverage)); | 508 newCoverage)); |
| 510 if (indexCnt) { | 509 if (indexCnt) { |
| 511 target->drawIndexed(drawState, | 510 target->drawIndexed(drawState, |
| 512 gp, | 511 gp, |
| 513 primType, | 512 primType, |
| 514 0, | 513 0, |
| 515 0, | 514 0, |
| 516 vertexCnt, | 515 vertexCnt, |
| 517 indexCnt, | 516 indexCnt, |
| 518 &devBounds); | 517 &devBounds); |
| 519 } else { | 518 } else { |
| 520 target->drawNonIndexed(drawState, gp, primType, 0, vertexCnt, &d
evBounds); | 519 target->drawNonIndexed(drawState, gp, primType, 0, vertexCnt, &d
evBounds); |
| 521 } | 520 } |
| 522 } | 521 } |
| 523 } | 522 } |
| 524 return true; | 523 return true; |
| 525 } | 524 } |
| 526 | 525 |
| 527 bool GrDefaultPathRenderer::canDrawPath(const GrDrawTarget* target, | 526 bool GrDefaultPathRenderer::canDrawPath(const GrDrawTarget* target, |
| 528 const GrDrawState* drawState, | 527 const GrDrawState* drawState, |
| 528 const SkMatrix& viewMatrix, |
| 529 const SkPath& path, | 529 const SkPath& path, |
| 530 const SkStrokeRec& stroke, | 530 const SkStrokeRec& stroke, |
| 531 bool antiAlias) const { | 531 bool antiAlias) const { |
| 532 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. | 532 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
| 533 | 533 |
| 534 return !antiAlias && !(SkPath::kConic_SegmentMask & path.getSegmentMasks())
&& | 534 return !antiAlias && !(SkPath::kConic_SegmentMask & path.getSegmentMasks())
&& |
| 535 (stroke.isFillStyle() || | 535 (stroke.isFillStyle() || IsStrokeHairlineOrEquivalent(stroke, viewMatrix
, NULL)); |
| 536 IsStrokeHairlineOrEquivalent(stroke, drawState->getViewMatrix(), NULL))
; | |
| 537 } | 536 } |
| 538 | 537 |
| 539 bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, | 538 bool GrDefaultPathRenderer::onDrawPath(GrDrawTarget* target, |
| 540 GrDrawState* drawState, | 539 GrDrawState* drawState, |
| 541 GrColor color, | 540 GrColor color, |
| 541 const SkMatrix& viewMatrix, |
| 542 const SkPath& path, | 542 const SkPath& path, |
| 543 const SkStrokeRec& stroke, | 543 const SkStrokeRec& stroke, |
| 544 bool antiAlias) { | 544 bool antiAlias) { |
| 545 return this->internalDrawPath(target, | 545 return this->internalDrawPath(target, |
| 546 drawState, | 546 drawState, |
| 547 color, | 547 color, |
| 548 viewMatrix, |
| 548 path, | 549 path, |
| 549 stroke, | 550 stroke, |
| 550 false); | 551 false); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, | 554 void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, |
| 554 GrDrawState* drawState, | 555 GrDrawState* drawState, |
| 556 const SkMatrix& viewMatrix, |
| 555 const SkPath& path, | 557 const SkPath& path, |
| 556 const SkStrokeRec& stroke) { | 558 const SkStrokeRec& stroke) { |
| 557 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); | 559 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); |
| 558 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); | 560 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); |
| 559 this->internalDrawPath(target, drawState, GrColor_WHITE, path, stroke, true)
; | 561 this->internalDrawPath(target, drawState, GrColor_WHITE, viewMatrix, path, s
troke, true); |
| 560 } | 562 } |
| OLD | NEW |