| 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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 return true; | 155 return true; |
| 156 #else | 156 #else |
| 157 if (!stroke.isHairlineStyle() && !path.isInverseFillType()) { | 157 if (!stroke.isHairlineStyle() && !path.isInverseFillType()) { |
| 158 return path.isConvex(); | 158 return path.isConvex(); |
| 159 } | 159 } |
| 160 return false; | 160 return false; |
| 161 #endif | 161 #endif |
| 162 } | 162 } |
| 163 | 163 |
| 164 GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport( | 164 GrPathRenderer::StencilSupport GrDefaultPathRenderer::onGetStencilSupport( |
| 165 const SkPath& path, | |
| 166 const SkStrokeRec& s
troke, | 165 const SkStrokeRec& s
troke, |
| 167 const GrDrawTarget*)
const { | 166 const GrDrawTarget*)
const { |
| 168 if (single_pass_path(path, stroke)) { | 167 if (single_pass_path(fPath, stroke)) { |
| 169 return GrPathRenderer::kNoRestriction_StencilSupport; | 168 return GrPathRenderer::kNoRestriction_StencilSupport; |
| 170 } else { | 169 } else { |
| 171 return GrPathRenderer::kStencilOnly_StencilSupport; | 170 return GrPathRenderer::kStencilOnly_StencilSupport; |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 | 173 |
| 175 static inline void append_countour_edge_indices(bool hairLine, | 174 static inline void append_countour_edge_indices(bool hairLine, |
| 176 uint16_t fanCenterIdx, | 175 uint16_t fanCenterIdx, |
| 177 uint16_t edgeV0Idx, | 176 uint16_t edgeV0Idx, |
| 178 uint16_t** indices) { | 177 uint16_t** indices) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 SkASSERT((vert - base) <= maxPts); | 316 SkASSERT((vert - base) <= maxPts); |
| 318 SkASSERT((idx - idxBase) <= maxIdxs); | 317 SkASSERT((idx - idxBase) <= maxIdxs); |
| 319 | 318 |
| 320 *vertexCnt = vert - base; | 319 *vertexCnt = vert - base; |
| 321 *indexCnt = idx - idxBase; | 320 *indexCnt = idx - idxBase; |
| 322 | 321 |
| 323 } | 322 } |
| 324 return true; | 323 return true; |
| 325 } | 324 } |
| 326 | 325 |
| 327 bool GrDefaultPathRenderer::internalDrawPath(const SkPath& path, | 326 bool GrDefaultPathRenderer::internalDrawPath(const SkStrokeRec& stroke, |
| 328 const SkStrokeRec& stroke, | |
| 329 GrDrawTarget* target, | 327 GrDrawTarget* target, |
| 330 bool stencilOnly) { | 328 bool stencilOnly) { |
| 331 | 329 |
| 332 SkMatrix viewM = target->getDrawState().getViewMatrix(); | 330 SkMatrix viewM = target->getDrawState().getViewMatrix(); |
| 333 SkScalar tol = SK_Scalar1; | 331 SkScalar tol = SK_Scalar1; |
| 334 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, path.getBounds()); | 332 tol = GrPathUtils::scaleToleranceToSrc(tol, viewM, fPath.getBounds()); |
| 335 | 333 |
| 336 int vertexCnt; | 334 int vertexCnt; |
| 337 int indexCnt; | 335 int indexCnt; |
| 338 GrPrimitiveType primType; | 336 GrPrimitiveType primType; |
| 339 GrDrawTarget::AutoReleaseGeometry arg; | 337 GrDrawTarget::AutoReleaseGeometry arg; |
| 340 if (!this->createGeom(path, | 338 if (!this->createGeom(fPath, |
| 341 stroke, | 339 stroke, |
| 342 tol, | 340 tol, |
| 343 target, | 341 target, |
| 344 &primType, | 342 &primType, |
| 345 &vertexCnt, | 343 &vertexCnt, |
| 346 &indexCnt, | 344 &indexCnt, |
| 347 &arg)) { | 345 &arg)) { |
| 348 return false; | 346 return false; |
| 349 } | 347 } |
| 350 | 348 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 364 if (stroke.isHairlineStyle()) { | 362 if (stroke.isHairlineStyle()) { |
| 365 passCount = 1; | 363 passCount = 1; |
| 366 if (stencilOnly) { | 364 if (stencilOnly) { |
| 367 passes[0] = &gDirectToStencil; | 365 passes[0] = &gDirectToStencil; |
| 368 } else { | 366 } else { |
| 369 passes[0] = NULL; | 367 passes[0] = NULL; |
| 370 } | 368 } |
| 371 lastPassIsBounds = false; | 369 lastPassIsBounds = false; |
| 372 drawFace[0] = GrDrawState::kBoth_DrawFace; | 370 drawFace[0] = GrDrawState::kBoth_DrawFace; |
| 373 } else { | 371 } else { |
| 374 if (single_pass_path(path, stroke)) { | 372 if (single_pass_path(fPath, stroke)) { |
| 375 passCount = 1; | 373 passCount = 1; |
| 376 if (stencilOnly) { | 374 if (stencilOnly) { |
| 377 passes[0] = &gDirectToStencil; | 375 passes[0] = &gDirectToStencil; |
| 378 } else { | 376 } else { |
| 379 passes[0] = NULL; | 377 passes[0] = NULL; |
| 380 } | 378 } |
| 381 drawFace[0] = GrDrawState::kBoth_DrawFace; | 379 drawFace[0] = GrDrawState::kBoth_DrawFace; |
| 382 lastPassIsBounds = false; | 380 lastPassIsBounds = false; |
| 383 } else { | 381 } else { |
| 384 switch (path.getFillType()) { | 382 switch (fPath.getFillType()) { |
| 385 case SkPath::kInverseEvenOdd_FillType: | 383 case SkPath::kInverseEvenOdd_FillType: |
| 386 reverse = true; | 384 reverse = true; |
| 387 // fallthrough | 385 // fallthrough |
| 388 case SkPath::kEvenOdd_FillType: | 386 case SkPath::kEvenOdd_FillType: |
| 389 passes[0] = &gEOStencilPass; | 387 passes[0] = &gEOStencilPass; |
| 390 if (stencilOnly) { | 388 if (stencilOnly) { |
| 391 passCount = 1; | 389 passCount = 1; |
| 392 lastPassIsBounds = false; | 390 lastPassIsBounds = false; |
| 393 } else { | 391 } else { |
| 394 passCount = 2; | 392 passCount = 2; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 } | 439 } |
| 442 break; | 440 break; |
| 443 default: | 441 default: |
| 444 SkDEBUGFAIL("Unknown path fFill!"); | 442 SkDEBUGFAIL("Unknown path fFill!"); |
| 445 return false; | 443 return false; |
| 446 } | 444 } |
| 447 } | 445 } |
| 448 } | 446 } |
| 449 | 447 |
| 450 SkRect devBounds; | 448 SkRect devBounds; |
| 451 GetPathDevBounds(path, drawState->getRenderTarget(), viewM, &devBounds); | 449 GetPathDevBounds(fPath, drawState->getRenderTarget(), viewM, &devBounds); |
| 452 | 450 |
| 453 for (int p = 0; p < passCount; ++p) { | 451 for (int p = 0; p < passCount; ++p) { |
| 454 drawState->setDrawFace(drawFace[p]); | 452 drawState->setDrawFace(drawFace[p]); |
| 455 if (NULL != passes[p]) { | 453 if (NULL != passes[p]) { |
| 456 *drawState->stencil() = *passes[p]; | 454 *drawState->stencil() = *passes[p]; |
| 457 } | 455 } |
| 458 | 456 |
| 459 if (lastPassIsBounds && (p == passCount-1)) { | 457 if (lastPassIsBounds && (p == passCount-1)) { |
| 460 if (!colorWritesWereDisabled) { | 458 if (!colorWritesWereDisabled) { |
| 461 drawState->disableState(GrDrawState::kNoColorWrites_StateBit); | 459 drawState->disableState(GrDrawState::kNoColorWrites_StateBit); |
| 462 } | 460 } |
| 463 SkRect bounds; | 461 SkRect bounds; |
| 464 GrDrawState::AutoViewMatrixRestore avmr; | 462 GrDrawState::AutoViewMatrixRestore avmr; |
| 465 if (reverse) { | 463 if (reverse) { |
| 466 SkASSERT(NULL != drawState->getRenderTarget()); | 464 SkASSERT(NULL != drawState->getRenderTarget()); |
| 467 // draw over the dev bounds (which will be the whole dst surface
for inv fill). | 465 // draw over the dev bounds (which will be the whole dst surface
for inv fill). |
| 468 bounds = devBounds; | 466 bounds = devBounds; |
| 469 SkMatrix vmi; | 467 SkMatrix vmi; |
| 470 // mapRect through persp matrix may not be correct | 468 // mapRect through persp matrix may not be correct |
| 471 if (!drawState->getViewMatrix().hasPerspective() && | 469 if (!drawState->getViewMatrix().hasPerspective() && |
| 472 drawState->getViewInverse(&vmi)) { | 470 drawState->getViewInverse(&vmi)) { |
| 473 vmi.mapRect(&bounds); | 471 vmi.mapRect(&bounds); |
| 474 } else { | 472 } else { |
| 475 avmr.setIdentity(drawState); | 473 avmr.setIdentity(drawState); |
| 476 } | 474 } |
| 477 } else { | 475 } else { |
| 478 bounds = path.getBounds(); | 476 bounds = fPath.getBounds(); |
| 479 } | 477 } |
| 480 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k
Preserve_ASRInit); | 478 GrDrawTarget::AutoGeometryAndStatePush agasp(target, GrDrawTarget::k
Preserve_ASRInit); |
| 481 target->drawSimpleRect(bounds, NULL); | 479 target->drawSimpleRect(bounds, NULL); |
| 482 } else { | 480 } else { |
| 483 if (passCount > 1) { | 481 if (passCount > 1) { |
| 484 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); | 482 drawState->enableState(GrDrawState::kNoColorWrites_StateBit); |
| 485 } | 483 } |
| 486 if (indexCnt) { | 484 if (indexCnt) { |
| 487 target->drawIndexed(primType, 0, 0, | 485 target->drawIndexed(primType, 0, 0, |
| 488 vertexCnt, indexCnt, &devBounds); | 486 vertexCnt, indexCnt, &devBounds); |
| 489 } else { | 487 } else { |
| 490 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds); | 488 target->drawNonIndexed(primType, 0, vertexCnt, &devBounds); |
| 491 } | 489 } |
| 492 } | 490 } |
| 493 } | 491 } |
| 494 return true; | 492 return true; |
| 495 } | 493 } |
| 496 | 494 |
| 497 bool GrDefaultPathRenderer::canDrawPath(const SkPath& path, | 495 bool GrDefaultPathRenderer::canDrawPath(const SkStrokeRec& stroke, |
| 498 const SkStrokeRec& stroke, | |
| 499 const GrDrawTarget* target, | 496 const GrDrawTarget* target, |
| 500 bool antiAlias) const { | 497 bool antiAlias) const { |
| 501 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. | 498 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
| 502 return (stroke.isFillStyle() || stroke.isHairlineStyle()) && !antiAlias; | 499 return (stroke.isFillStyle() || stroke.isHairlineStyle()) && !antiAlias; |
| 503 } | 500 } |
| 504 | 501 |
| 505 bool GrDefaultPathRenderer::onDrawPath(const SkPath& path, | 502 bool GrDefaultPathRenderer::onDrawPath(const SkStrokeRec& stroke, |
| 506 const SkStrokeRec& stroke, | |
| 507 GrDrawTarget* target, | 503 GrDrawTarget* target, |
| 508 bool antiAlias) { | 504 bool antiAlias) { |
| 509 return this->internalDrawPath(path, | 505 return this->internalDrawPath(stroke, target, false); |
| 510 stroke, | |
| 511 target, | |
| 512 false); | |
| 513 } | 506 } |
| 514 | 507 |
| 515 void GrDefaultPathRenderer::onStencilPath(const SkPath& path, | 508 void GrDefaultPathRenderer::onStencilPath(const SkStrokeRec& stroke, |
| 516 const SkStrokeRec& stroke, | |
| 517 GrDrawTarget* target) { | 509 GrDrawTarget* target) { |
| 518 SkASSERT(SkPath::kInverseEvenOdd_FillType != path.getFillType()); | 510 SkASSERT(SkPath::kInverseEvenOdd_FillType != fPath.getFillType()); |
| 519 SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); | 511 SkASSERT(SkPath::kInverseWinding_FillType != fPath.getFillType()); |
| 520 this->internalDrawPath(path, stroke, target, true); | 512 this->internalDrawPath(stroke, target, true); |
| 521 } | 513 } |
| OLD | NEW |