| 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "effects/GrBicubicEffect.h" | 10 #include "effects/GrBicubicEffect.h" |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 SkScalar width = paint.getStrokeWidth(); | 336 SkScalar width = paint.getStrokeWidth(); |
| 337 if (width < 0) { | 337 if (width < 0) { |
| 338 return; | 338 return; |
| 339 } | 339 } |
| 340 | 340 |
| 341 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 341 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
| 342 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 342 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
| 343 GrPaint grPaint; | 343 GrPaint grPaint; |
| 344 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 344 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 345 SkPath path; | 345 SkPath path; |
| 346 path.setIsVolatile(true); |
| 346 path.moveTo(pts[0]); | 347 path.moveTo(pts[0]); |
| 347 path.lineTo(pts[1]); | 348 path.lineTo(pts[1]); |
| 348 fContext->drawPath(grPaint, path, strokeInfo); | 349 fContext->drawPath(grPaint, path, strokeInfo); |
| 349 return; | 350 return; |
| 350 } | 351 } |
| 351 | 352 |
| 352 // we only handle hairlines and paints without path effects or mask filters, | 353 // we only handle hairlines and paints without path effects or mask filters, |
| 353 // else we let the SkDraw call our drawPath() | 354 // else we let the SkDraw call our drawPath() |
| 354 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { | 355 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { |
| 355 draw.drawPoints(mode, count, pts, paint, true); | 356 draw.drawPoints(mode, count, pts, paint, true); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 413 |
| 413 GrStrokeInfo strokeInfo(paint); | 414 GrStrokeInfo strokeInfo(paint); |
| 414 | 415 |
| 415 const SkPathEffect* pe = paint.getPathEffect(); | 416 const SkPathEffect* pe = paint.getPathEffect(); |
| 416 if (!usePath && pe && !strokeInfo.isDashed()) { | 417 if (!usePath && pe && !strokeInfo.isDashed()) { |
| 417 usePath = true; | 418 usePath = true; |
| 418 } | 419 } |
| 419 | 420 |
| 420 if (usePath) { | 421 if (usePath) { |
| 421 SkPath path; | 422 SkPath path; |
| 423 path.setIsVolatile(true); |
| 422 path.addRect(rect); | 424 path.addRect(rect); |
| 423 this->drawPath(draw, path, paint, NULL, true); | 425 this->drawPath(draw, path, paint, NULL, true); |
| 424 return; | 426 return; |
| 425 } | 427 } |
| 426 | 428 |
| 427 GrPaint grPaint; | 429 GrPaint grPaint; |
| 428 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 430 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 429 | 431 |
| 430 fContext->drawRect(grPaint, rect, &strokeInfo); | 432 fContext->drawRect(grPaint, rect, &strokeInfo); |
| 431 } | 433 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } else { | 480 } else { |
| 479 const SkPathEffect* pe = paint.getPathEffect(); | 481 const SkPathEffect* pe = paint.getPathEffect(); |
| 480 if (pe && !strokeInfo.isDashed()) { | 482 if (pe && !strokeInfo.isDashed()) { |
| 481 usePath = true; | 483 usePath = true; |
| 482 } | 484 } |
| 483 } | 485 } |
| 484 | 486 |
| 485 | 487 |
| 486 if (usePath) { | 488 if (usePath) { |
| 487 SkPath path; | 489 SkPath path; |
| 490 path.setIsVolatile(true); |
| 488 path.addRRect(rect); | 491 path.addRRect(rect); |
| 489 this->drawPath(draw, path, paint, NULL, true); | 492 this->drawPath(draw, path, paint, NULL, true); |
| 490 return; | 493 return; |
| 491 } | 494 } |
| 492 | 495 |
| 493 fContext->drawRRect(grPaint, rect, strokeInfo); | 496 fContext->drawRRect(grPaint, rect, strokeInfo); |
| 494 } | 497 } |
| 495 | 498 |
| 496 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 499 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
| 497 const SkRRect& inner, const SkPaint& paint) { | 500 const SkRRect& inner, const SkPaint& paint) { |
| 498 SkStrokeRec stroke(paint); | 501 SkStrokeRec stroke(paint); |
| 499 if (stroke.isFillStyle()) { | 502 if (stroke.isFillStyle()) { |
| 500 | 503 |
| 501 CHECK_FOR_ANNOTATION(paint); | 504 CHECK_FOR_ANNOTATION(paint); |
| 502 CHECK_SHOULD_DRAW(draw, false); | 505 CHECK_SHOULD_DRAW(draw, false); |
| 503 | 506 |
| 504 GrPaint grPaint; | 507 GrPaint grPaint; |
| 505 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 508 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 506 | 509 |
| 507 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { | 510 if (NULL == paint.getMaskFilter() && NULL == paint.getPathEffect()) { |
| 508 fContext->drawDRRect(grPaint, outer, inner); | 511 fContext->drawDRRect(grPaint, outer, inner); |
| 509 return; | 512 return; |
| 510 } | 513 } |
| 511 } | 514 } |
| 512 | 515 |
| 513 SkPath path; | 516 SkPath path; |
| 517 path.setIsVolatile(true); |
| 514 path.addRRect(outer); | 518 path.addRRect(outer); |
| 515 path.addRRect(inner); | 519 path.addRRect(inner); |
| 516 path.setFillType(SkPath::kEvenOdd_FillType); | 520 path.setFillType(SkPath::kEvenOdd_FillType); |
| 517 | 521 |
| 518 this->drawPath(draw, path, paint, NULL, true); | 522 this->drawPath(draw, path, paint, NULL, true); |
| 519 } | 523 } |
| 520 | 524 |
| 521 | 525 |
| 522 ///////////////////////////////////////////////////////////////////////////// | 526 ///////////////////////////////////////////////////////////////////////////// |
| 523 | 527 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 535 usePath = true; | 539 usePath = true; |
| 536 } else { | 540 } else { |
| 537 const SkPathEffect* pe = paint.getPathEffect(); | 541 const SkPathEffect* pe = paint.getPathEffect(); |
| 538 if (pe && !strokeInfo.isDashed()) { | 542 if (pe && !strokeInfo.isDashed()) { |
| 539 usePath = true; | 543 usePath = true; |
| 540 } | 544 } |
| 541 } | 545 } |
| 542 | 546 |
| 543 if (usePath) { | 547 if (usePath) { |
| 544 SkPath path; | 548 SkPath path; |
| 549 path.setIsVolatile(true); |
| 545 path.addOval(oval); | 550 path.addOval(oval); |
| 546 this->drawPath(draw, path, paint, NULL, true); | 551 this->drawPath(draw, path, paint, NULL, true); |
| 547 return; | 552 return; |
| 548 } | 553 } |
| 549 | 554 |
| 550 GrPaint grPaint; | 555 GrPaint grPaint; |
| 551 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 556 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 552 | 557 |
| 553 fContext->drawOval(grPaint, oval, strokeInfo); | 558 fContext->drawOval(grPaint, oval, strokeInfo); |
| 554 } | 559 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 | 689 |
| 685 }; | 690 }; |
| 686 | 691 |
| 687 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 692 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
| 688 const SkPaint& paint, const SkMatrix* prePathMatrix, | 693 const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 689 bool pathIsMutable) { | 694 bool pathIsMutable) { |
| 690 CHECK_FOR_ANNOTATION(paint); | 695 CHECK_FOR_ANNOTATION(paint); |
| 691 CHECK_SHOULD_DRAW(draw, false); | 696 CHECK_SHOULD_DRAW(draw, false); |
| 692 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); | 697 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); |
| 693 | 698 |
| 699 SkASSERT(!pathIsMutable || origSrcPath.isVolatile()); |
| 700 |
| 694 GrPaint grPaint; | 701 GrPaint grPaint; |
| 695 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 702 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 696 | 703 |
| 697 // If we have a prematrix, apply it to the path, optimizing for the case | 704 // If we have a prematrix, apply it to the path, optimizing for the case |
| 698 // where the original path can in fact be modified in place (even though | 705 // where the original path can in fact be modified in place (even though |
| 699 // its parameter type is const). | 706 // its parameter type is const). |
| 700 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 707 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
| 701 SkTLazy<SkPath> tmpPath; | 708 SkTLazy<SkPath> tmpPath; |
| 702 SkTLazy<SkPath> effectPath; | 709 SkTLazy<SkPath> effectPath; |
| 703 | 710 |
| 704 if (prePathMatrix) { | 711 if (prePathMatrix) { |
| 705 SkPath* result = pathPtr; | 712 SkPath* result = pathPtr; |
| 706 | 713 |
| 707 if (!pathIsMutable) { | 714 if (!pathIsMutable) { |
| 708 result = tmpPath.init(); | 715 result = tmpPath.init(); |
| 716 result->setIsVolatile(true); |
| 709 pathIsMutable = true; | 717 pathIsMutable = true; |
| 710 } | 718 } |
| 711 // should I push prePathMatrix on our MV stack temporarily, instead | 719 // should I push prePathMatrix on our MV stack temporarily, instead |
| 712 // of applying it here? See SkDraw.cpp | 720 // of applying it here? See SkDraw.cpp |
| 713 pathPtr->transform(*prePathMatrix, result); | 721 pathPtr->transform(*prePathMatrix, result); |
| 714 pathPtr = result; | 722 pathPtr = result; |
| 715 } | 723 } |
| 716 // at this point we're done with prePathMatrix | 724 // at this point we're done with prePathMatrix |
| 717 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) | 725 SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
| 718 | 726 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 733 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); | 741 SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init(); |
| 734 if (stroke.applyToPath(strokedPath, *pathPtr)) { | 742 if (stroke.applyToPath(strokedPath, *pathPtr)) { |
| 735 pathPtr = strokedPath; | 743 pathPtr = strokedPath; |
| 736 pathIsMutable = true; | 744 pathIsMutable = true; |
| 737 strokeInfo.setFillStyle(); | 745 strokeInfo.setFillStyle(); |
| 738 } | 746 } |
| 739 } | 747 } |
| 740 | 748 |
| 741 // avoid possibly allocating a new path in transform if we can | 749 // avoid possibly allocating a new path in transform if we can |
| 742 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); | 750 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); |
| 751 if (!pathIsMutable) { |
| 752 devPathPtr->setIsVolatile(true); |
| 753 } |
| 743 | 754 |
| 744 // transform the path into device space | 755 // transform the path into device space |
| 745 pathPtr->transform(fContext->getMatrix(), devPathPtr); | 756 pathPtr->transform(fContext->getMatrix(), devPathPtr); |
| 746 | 757 |
| 747 SkRect maskRect; | 758 SkRect maskRect; |
| 748 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), | 759 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), |
| 749 draw.fClip->getBounds(), | 760 draw.fClip->getBounds(), |
| 750 fContext->getMatrix(), | 761 fContext->getMatrix(), |
| 751 &maskRect)) { | 762 &maskRect)) { |
| 752 // The context's matrix may change while creating the mask, so save
the CTM here to | 763 // The context's matrix may change while creating the mask, so save
the CTM here to |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 GrLayerHoister::UnlockLayers(fContext, atlased, nonAtlased, recycled); | 1835 GrLayerHoister::UnlockLayers(fContext, atlased, nonAtlased, recycled); |
| 1825 | 1836 |
| 1826 return true; | 1837 return true; |
| 1827 } | 1838 } |
| 1828 | 1839 |
| 1829 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1840 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1830 // We always return a transient cache, so it is freed after each | 1841 // We always return a transient cache, so it is freed after each |
| 1831 // filter traversal. | 1842 // filter traversal. |
| 1832 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1843 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1833 } | 1844 } |
| OLD | NEW |