| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrBatchTest.h" | 8 #include "GrBatchTest.h" |
| 9 #include "GrColor.h" | 9 #include "GrColor.h" |
| 10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 nullptr, nullptr); | 272 nullptr, nullptr); |
| 273 } | 273 } |
| 274 | 274 |
| 275 return batch; | 275 return batch; |
| 276 } | 276 } |
| 277 | 277 |
| 278 void GrDrawContext::drawRect(const GrClip& clip, | 278 void GrDrawContext::drawRect(const GrClip& clip, |
| 279 const GrPaint& paint, | 279 const GrPaint& paint, |
| 280 const SkMatrix& viewMatrix, | 280 const SkMatrix& viewMatrix, |
| 281 const SkRect& rect, | 281 const SkRect& rect, |
| 282 const GrStyle* style) { | 282 const GrStrokeInfo* strokeInfo) { |
| 283 if (!style) { | |
| 284 style = &GrStyle::SimpleFill(); | |
| 285 } | |
| 286 ASSERT_SINGLE_OWNER | 283 ASSERT_SINGLE_OWNER |
| 287 RETURN_IF_ABANDONED | 284 RETURN_IF_ABANDONED |
| 288 SkDEBUGCODE(this->validate();) | 285 SkDEBUGCODE(this->validate();) |
| 289 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); | 286 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRect"); |
| 290 | 287 |
| 291 // Path effects should've been devolved to a path in SkGpuDevice | 288 // Dashing should've been devolved to a path in SkGpuDevice |
| 292 SkASSERT(!style->pathEffect()); | 289 SkASSERT(!strokeInfo || !strokeInfo->isDashed()); |
| 293 | 290 |
| 294 AutoCheckFlush acf(fDrawingManager); | 291 AutoCheckFlush acf(fDrawingManager); |
| 295 | 292 |
| 296 const SkStrokeRec& stroke = style->strokeRec(); | 293 SkScalar width = !strokeInfo ? -1 : strokeInfo->getWidth(); |
| 297 SkScalar width = stroke.getWidth(); | |
| 298 | 294 |
| 299 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking | 295 // Check if this is a full RT draw and can be replaced with a clear. We don'
t bother checking |
| 300 // cases where the RT is fully inside a stroke. | 296 // cases where the RT is fully inside a stroke. |
| 301 if (width < 0) { | 297 if (width < 0) { |
| 302 SkRect rtRect; | 298 SkRect rtRect; |
| 303 fRenderTarget->getBoundsRect(&rtRect); | 299 fRenderTarget->getBoundsRect(&rtRect); |
| 304 SkRect clipSpaceRTRect = rtRect; | 300 SkRect clipSpaceRTRect = rtRect; |
| 305 bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); | 301 bool checkClip = GrClip::kWideOpen_ClipType != clip.clipType(); |
| 306 if (checkClip) { | 302 if (checkClip) { |
| 307 clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), | 303 clipSpaceRTRect.offset(SkIntToScalar(clip.origin().fX), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 334 SkAutoTUnref<GrDrawBatch> batch; | 330 SkAutoTUnref<GrDrawBatch> batch; |
| 335 if (width < 0) { | 331 if (width < 0) { |
| 336 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect)); | 332 batch.reset(this->getFillRectBatch(paint, viewMatrix, rect)); |
| 337 } else { | 333 } else { |
| 338 GrColor color = paint.getColor(); | 334 GrColor color = paint.getColor(); |
| 339 | 335 |
| 340 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 336 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { |
| 341 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). | 337 // The stroke path needs the rect to remain axis aligned (no rotatio
n or skew). |
| 342 if (viewMatrix.rectStaysRect()) { | 338 if (viewMatrix.rectStaysRect()) { |
| 343 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, | 339 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix
, rect, |
| 344 stroke)); | 340 *strokeInfo)); |
| 345 } | 341 } |
| 346 } else { | 342 } else { |
| 347 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit | 343 // Non-AA hairlines are snapped to pixel centers to make which pixel
s are hit |
| 348 // deterministic | 344 // deterministic |
| 349 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); | 345 snapToPixelCenters = (0 == width && !fRenderTarget->isUnifiedMultisa
mpled()); |
| 350 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, | 346 batch.reset(GrRectBatchFactory::CreateNonAAStroke(color, viewMatrix,
rect, |
| 351 width, snapToPixel
Centers)); | 347 width, snapToPixel
Centers)); |
| 352 | 348 |
| 353 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of | 349 // Depending on sub-pixel coordinates and the particular GPU, we may
lose a corner of |
| 354 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not | 350 // hairline rects. We jam all the vertices to pixel centers to avoid
this, but not |
| 355 // when MSAA is enabled because it can cause ugly artifacts. | 351 // when MSAA is enabled because it can cause ugly artifacts. |
| 356 } | 352 } |
| 357 } | 353 } |
| 358 | 354 |
| 359 if (batch) { | 355 if (batch) { |
| 360 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 356 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 361 | 357 |
| 362 if (snapToPixelCenters) { | 358 if (snapToPixelCenters) { |
| 363 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, | 359 pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCent
ers_Flag, |
| 364 snapToPixelCenters); | 360 snapToPixelCenters); |
| 365 } | 361 } |
| 366 | 362 |
| 367 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 363 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 368 return; | 364 return; |
| 369 } | 365 } |
| 370 | 366 |
| 371 SkPath path; | 367 SkPath path; |
| 372 path.setIsVolatile(true); | 368 path.setIsVolatile(true); |
| 373 path.addRect(rect); | 369 path.addRect(rect); |
| 374 this->internalDrawPath(clip, paint, viewMatrix, path, *style); | 370 this->internalDrawPath(clip, paint, viewMatrix, path, |
| 371 strokeInfo ? *strokeInfo : GrStrokeInfo::FillInfo()); |
| 375 } | 372 } |
| 376 | 373 |
| 377 bool GrDrawContextPriv::drawAndStencilRect(const SkIRect* scissorRect, | 374 bool GrDrawContextPriv::drawAndStencilRect(const SkIRect* scissorRect, |
| 378 const GrStencilSettings& ss, | 375 const GrStencilSettings& ss, |
| 379 SkRegion::Op op, | 376 SkRegion::Op op, |
| 380 bool invert, | 377 bool invert, |
| 381 bool doAA, | 378 bool doAA, |
| 382 const SkMatrix& viewMatrix, | 379 const SkMatrix& viewMatrix, |
| 383 const SkRect& rect) { | 380 const SkRect& rect) { |
| 384 ASSERT_SINGLE_OWNER_PRIV | 381 ASSERT_SINGLE_OWNER_PRIV |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 529 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 533 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 530 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 534 } | 531 } |
| 535 | 532 |
| 536 /////////////////////////////////////////////////////////////////////////////// | 533 /////////////////////////////////////////////////////////////////////////////// |
| 537 | 534 |
| 538 void GrDrawContext::drawRRect(const GrClip& clip, | 535 void GrDrawContext::drawRRect(const GrClip& clip, |
| 539 const GrPaint& paint, | 536 const GrPaint& paint, |
| 540 const SkMatrix& viewMatrix, | 537 const SkMatrix& viewMatrix, |
| 541 const SkRRect& rrect, | 538 const SkRRect& rrect, |
| 542 const GrStyle& style) { | 539 const GrStrokeInfo& strokeInfo) { |
| 543 ASSERT_SINGLE_OWNER | 540 ASSERT_SINGLE_OWNER |
| 544 RETURN_IF_ABANDONED | 541 RETURN_IF_ABANDONED |
| 545 SkDEBUGCODE(this->validate();) | 542 SkDEBUGCODE(this->validate();) |
| 546 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); | 543 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawRRect"); |
| 547 | 544 |
| 548 if (rrect.isEmpty()) { | 545 if (rrect.isEmpty()) { |
| 549 return; | 546 return; |
| 550 } | 547 } |
| 551 | 548 |
| 552 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice | 549 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
| 553 const SkStrokeRec stroke = style.strokeRec(); | 550 |
| 554 AutoCheckFlush acf(fDrawingManager); | 551 AutoCheckFlush acf(fDrawingManager); |
| 555 | 552 |
| 556 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 553 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { |
| 557 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 554 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 558 | 555 |
| 559 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g
etColor(), | 556 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.g
etColor(), |
| 560 viewMat
rix, | 557 viewMat
rix, |
| 561 rrect, | 558 rrect, |
| 562 stroke, | 559 strokeI
nfo, |
| 563 shaderC
aps)); | 560 shaderC
aps)); |
| 564 if (batch) { | 561 if (batch) { |
| 565 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 562 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 566 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 563 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 567 return; | 564 return; |
| 568 } | 565 } |
| 569 } | 566 } |
| 570 | 567 |
| 571 SkPath path; | 568 SkPath path; |
| 572 path.setIsVolatile(true); | 569 path.setIsVolatile(true); |
| 573 path.addRRect(rrect); | 570 path.addRRect(rrect); |
| 574 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 571 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 575 } | 572 } |
| 576 | 573 |
| 577 bool GrDrawContext::drawFilledDRRect(const GrClip& clip, | 574 bool GrDrawContext::drawFilledDRRect(const GrClip& clip, |
| 578 const GrPaint& paintIn, | 575 const GrPaint& paintIn, |
| 579 const SkMatrix& viewMatrix, | 576 const SkMatrix& viewMatrix, |
| 580 const SkRRect& origOuter, | 577 const SkRRect& origOuter, |
| 581 const SkRRect& origInner) { | 578 const SkRRect& origInner) { |
| 582 SkASSERT(!origInner.isEmpty()); | 579 SkASSERT(!origInner.isEmpty()); |
| 583 SkASSERT(!origOuter.isEmpty()); | 580 SkASSERT(!origOuter.isEmpty()); |
| 584 | 581 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 return; | 647 return; |
| 651 } | 648 } |
| 652 | 649 |
| 653 SkPath path; | 650 SkPath path; |
| 654 path.setIsVolatile(true); | 651 path.setIsVolatile(true); |
| 655 path.addRRect(inner); | 652 path.addRRect(inner); |
| 656 path.addRRect(outer); | 653 path.addRRect(outer); |
| 657 path.setFillType(SkPath::kEvenOdd_FillType); | 654 path.setFillType(SkPath::kEvenOdd_FillType); |
| 658 | 655 |
| 659 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 656 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 660 this->internalDrawPath(clip, paint, viewMatrix, path, GrStyle::SimpleFill())
; | 657 this->internalDrawPath(clip, paint, viewMatrix, path, GrStrokeInfo::FillInfo
()); |
| 661 } | 658 } |
| 662 | 659 |
| 663 /////////////////////////////////////////////////////////////////////////////// | 660 /////////////////////////////////////////////////////////////////////////////// |
| 664 | 661 |
| 665 void GrDrawContext::drawOval(const GrClip& clip, | 662 void GrDrawContext::drawOval(const GrClip& clip, |
| 666 const GrPaint& paint, | 663 const GrPaint& paint, |
| 667 const SkMatrix& viewMatrix, | 664 const SkMatrix& viewMatrix, |
| 668 const SkRect& oval, | 665 const SkRect& oval, |
| 669 const GrStyle& style) { | 666 const GrStrokeInfo& strokeInfo) { |
| 670 ASSERT_SINGLE_OWNER | 667 ASSERT_SINGLE_OWNER |
| 671 RETURN_IF_ABANDONED | 668 RETURN_IF_ABANDONED |
| 672 SkDEBUGCODE(this->validate();) | 669 SkDEBUGCODE(this->validate();) |
| 673 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); | 670 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawOval"); |
| 674 | 671 |
| 675 if (oval.isEmpty()) { | 672 if (oval.isEmpty()) { |
| 676 return; | 673 return; |
| 677 } | 674 } |
| 678 | 675 |
| 679 SkASSERT(!style.pathEffect()); // this should've been devolved to a path in
SkGpuDevice | 676 SkASSERT(!strokeInfo.isDashed()); // this should've been devolved to a path
in SkGpuDevice |
| 680 | 677 |
| 681 AutoCheckFlush acf(fDrawingManager); | 678 AutoCheckFlush acf(fDrawingManager); |
| 682 const SkStrokeRec& stroke = style.strokeRec(); | 679 |
| 683 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { | 680 if (should_apply_coverage_aa(paint, fRenderTarget.get())) { |
| 684 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 681 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 685 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge
tColor(), | 682 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.ge
tColor(), |
| 686 viewMatr
ix, | 683 viewMatr
ix, |
| 687 oval, | 684 oval, |
| 688 stroke, | 685 strokeIn
fo, |
| 689 shaderCa
ps)); | 686 shaderCa
ps)); |
| 690 if (batch) { | 687 if (batch) { |
| 691 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 688 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 692 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 689 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 693 return; | 690 return; |
| 694 } | 691 } |
| 695 } | 692 } |
| 696 | 693 |
| 697 SkPath path; | 694 SkPath path; |
| 698 path.setIsVolatile(true); | 695 path.setIsVolatile(true); |
| 699 path.addOval(oval); | 696 path.addOval(oval); |
| 700 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 697 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 701 } | 698 } |
| 702 | 699 |
| 703 void GrDrawContext::drawImageNine(const GrClip& clip, | 700 void GrDrawContext::drawImageNine(const GrClip& clip, |
| 704 const GrPaint& paint, | 701 const GrPaint& paint, |
| 705 const SkMatrix& viewMatrix, | 702 const SkMatrix& viewMatrix, |
| 706 int imageWidth, | 703 int imageWidth, |
| 707 int imageHeight, | 704 int imageHeight, |
| 708 const SkIRect& center, | 705 const SkIRect& center, |
| 709 const SkRect& dst) { | 706 const SkRect& dst) { |
| 710 ASSERT_SINGLE_OWNER | 707 ASSERT_SINGLE_OWNER |
| 711 RETURN_IF_ABANDONED | 708 RETURN_IF_ABANDONED |
| 712 SkDEBUGCODE(this->validate();) | 709 SkDEBUGCODE(this->validate();) |
| 713 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); | 710 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawImageNine"); |
| 714 | 711 |
| 715 AutoCheckFlush acf(fDrawingManager); | 712 AutoCheckFlush acf(fDrawingManager); |
| 716 | 713 |
| 717 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v
iewMatrix, | 714 SkAutoTUnref<GrDrawBatch> batch(GrNinePatch::CreateNonAA(paint.getColor(), v
iewMatrix, |
| 718 imageWidth, imageHe
ight, | 715 imageWidth, imageHe
ight, |
| 719 center, dst)); | 716 center, dst)); |
| 720 | 717 |
| 721 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 718 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 722 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 719 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 723 } | 720 } |
| 724 | 721 |
| 725 | 722 |
| 726 // Can 'path' be drawn as a pair of filled nested rectangles? | 723 // Can 'path' be drawn as a pair of filled nested rectangles? |
| 727 static bool fills_as_nested_rects(const SkMatrix& viewMatrix, const SkPath& path
, SkRect rects[2]) { | 724 static bool is_nested_rects(const SkMatrix& viewMatrix, |
| 725 const SkPath& path, |
| 726 const SkStrokeRec& stroke, |
| 727 SkRect rects[2]) { |
| 728 SkASSERT(stroke.isFillStyle()); |
| 728 | 729 |
| 729 if (path.isInverseFillType()) { | 730 if (path.isInverseFillType()) { |
| 730 return false; | 731 return false; |
| 731 } | 732 } |
| 732 | 733 |
| 733 // TODO: this restriction could be lifted if we were willing to apply | 734 // TODO: this restriction could be lifted if we were willing to apply |
| 734 // the matrix to all the points individually rather than just to the rect | 735 // the matrix to all the points individually rather than just to the rect |
| 735 if (!viewMatrix.rectStaysRect()) { | 736 if (!viewMatrix.rectStaysRect()) { |
| 736 return false; | 737 return false; |
| 737 } | 738 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 | 792 |
| 792 AutoCheckFlush acf(fDrawingManager); | 793 AutoCheckFlush acf(fDrawingManager); |
| 793 | 794 |
| 794 this->getDrawTarget()->drawPathBatch(pipelineBuilder, batch); | 795 this->getDrawTarget()->drawPathBatch(pipelineBuilder, batch); |
| 795 } | 796 } |
| 796 | 797 |
| 797 void GrDrawContext::drawPath(const GrClip& clip, | 798 void GrDrawContext::drawPath(const GrClip& clip, |
| 798 const GrPaint& paint, | 799 const GrPaint& paint, |
| 799 const SkMatrix& viewMatrix, | 800 const SkMatrix& viewMatrix, |
| 800 const SkPath& path, | 801 const SkPath& path, |
| 801 const GrStyle& style) { | 802 const GrStrokeInfo& strokeInfo) { |
| 802 ASSERT_SINGLE_OWNER | 803 ASSERT_SINGLE_OWNER |
| 803 RETURN_IF_ABANDONED | 804 RETURN_IF_ABANDONED |
| 804 SkDEBUGCODE(this->validate();) | 805 SkDEBUGCODE(this->validate();) |
| 805 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); | 806 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawPath"); |
| 806 | 807 |
| 807 if (path.isEmpty()) { | 808 if (path.isEmpty()) { |
| 808 if (path.isInverseFillType()) { | 809 if (path.isInverseFillType()) { |
| 809 this->drawPaint(clip, paint, viewMatrix); | 810 this->drawPaint(clip, paint, viewMatrix); |
| 810 } | 811 } |
| 811 return; | 812 return; |
| 812 } | 813 } |
| 813 | 814 |
| 814 AutoCheckFlush acf(fDrawingManager); | 815 AutoCheckFlush acf(fDrawingManager); |
| 815 | 816 |
| 816 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && !style.pathEffec
t()) { | 817 if (should_apply_coverage_aa(paint, fRenderTarget.get()) && !strokeInfo.isDa
shed()) { |
| 817 if (style.isSimpleFill() && !path.isConvex()) { | 818 if (strokeInfo.getWidth() < 0 && !path.isConvex()) { |
| 818 // Concave AA paths are expensive - try to avoid them for special ca
ses | 819 // Concave AA paths are expensive - try to avoid them for special ca
ses |
| 819 SkRect rects[2]; | 820 SkRect rects[2]; |
| 820 | 821 |
| 821 if (fills_as_nested_rects(viewMatrix, path, rects)) { | 822 if (is_nested_rects(viewMatrix, path, strokeInfo, rects)) { |
| 822 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( | 823 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFill
NestedRects( |
| 823 paint.getColor(), viewMatrix, rects)); | 824 paint.getColor(), viewMatrix, rects)); |
| 824 if (batch) { | 825 if (batch) { |
| 825 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get()
, clip); | 826 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get()
, clip); |
| 826 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 827 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 827 } | 828 } |
| 828 return; | 829 return; |
| 829 } | 830 } |
| 830 } | 831 } |
| 831 SkRect ovalRect; | 832 SkRect ovalRect; |
| 832 bool isOval = path.isOval(&ovalRect); | 833 bool isOval = path.isOval(&ovalRect); |
| 833 | 834 |
| 834 if (isOval && !path.isInverseFillType()) { | 835 if (isOval && !path.isInverseFillType()) { |
| 835 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); | 836 GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps(); |
| 836 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain
t.getColor(), | 837 SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(pain
t.getColor(), |
| 837 view
Matrix, | 838 view
Matrix, |
| 838 oval
Rect, | 839 oval
Rect, |
| 839 styl
e.strokeRec(), | 840 stro
keInfo, |
| 840 shad
erCaps)); | 841 shad
erCaps)); |
| 841 if (batch) { | 842 if (batch) { |
| 842 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), cl
ip); | 843 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), cl
ip); |
| 843 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); | 844 this->getDrawTarget()->drawBatch(pipelineBuilder, batch); |
| 844 return; | 845 return; |
| 845 } | 846 } |
| 846 } | 847 } |
| 847 } | 848 } |
| 848 | 849 |
| 849 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. | 850 // Note that internalDrawPath may sw-rasterize the path into a scratch textu
re. |
| 850 // Scratch textures can be recycled after they are returned to the texture | 851 // Scratch textures can be recycled after they are returned to the texture |
| 851 // cache. This presents a potential hazard for buffered drawing. However, | 852 // cache. This presents a potential hazard for buffered drawing. However, |
| 852 // the writePixels that uploads to the scratch will perform a flush so we're | 853 // the writePixels that uploads to the scratch will perform a flush so we're |
| 853 // OK. | 854 // OK. |
| 854 this->internalDrawPath(clip, paint, viewMatrix, path, style); | 855 this->internalDrawPath(clip, paint, viewMatrix, path, strokeInfo); |
| 855 } | 856 } |
| 856 | 857 |
| 857 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, | 858 bool GrDrawContextPriv::drawAndStencilPath(const SkIRect* scissorRect, |
| 858 const GrStencilSettings& ss, | 859 const GrStencilSettings& ss, |
| 859 SkRegion::Op op, | 860 SkRegion::Op op, |
| 860 bool invert, | 861 bool invert, |
| 861 bool doAA, | 862 bool doAA, |
| 862 const SkMatrix& viewMatrix, | 863 const SkMatrix& viewMatrix, |
| 863 const SkPath& path) { | 864 const SkPath& path) { |
| 864 ASSERT_SINGLE_OWNER_PRIV | 865 ASSERT_SINGLE_OWNER_PRIV |
| (...skipping 19 matching lines...) Expand all Loading... |
| 884 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti
sampled(); | 885 bool isStencilBufferMSAA = fDrawContext->fRenderTarget->isStencilBufferMulti
sampled(); |
| 885 | 886 |
| 886 const GrPathRendererChain::DrawType type = | 887 const GrPathRendererChain::DrawType type = |
| 887 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType | 888 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 888 : GrPathRendererChain::kColor_DrawType; | 889 : GrPathRendererChain::kColor_DrawType; |
| 889 | 890 |
| 890 GrPathRenderer::CanDrawPathArgs canDrawArgs; | 891 GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 891 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps(
)->shaderCaps(); | 892 canDrawArgs.fShaderCaps = fDrawContext->fDrawingManager->getContext()->caps(
)->shaderCaps(); |
| 892 canDrawArgs.fViewMatrix = &viewMatrix; | 893 canDrawArgs.fViewMatrix = &viewMatrix; |
| 893 canDrawArgs.fPath = &path; | 894 canDrawArgs.fPath = &path; |
| 894 canDrawArgs.fStyle = &GrStyle::SimpleFill(); | 895 canDrawArgs.fStroke = &GrStrokeInfo::FillInfo(); |
| 895 canDrawArgs.fAntiAlias = useCoverageAA; | 896 canDrawArgs.fAntiAlias = useCoverageAA; |
| 896 canDrawArgs.fIsStencilDisabled = isStencilDisabled; | 897 canDrawArgs.fIsStencilDisabled = isStencilDisabled; |
| 897 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; | 898 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; |
| 898 | 899 |
| 899 // Don't allow the SW renderer | 900 // Don't allow the SW renderer |
| 900 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA
rgs, false, type); | 901 GrPathRenderer* pr = fDrawContext->fDrawingManager->getPathRenderer(canDrawA
rgs, false, type); |
| 901 if (!pr) { | 902 if (!pr) { |
| 902 return false; | 903 return false; |
| 903 } | 904 } |
| 904 | 905 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 915 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(),
clip); | 916 GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(),
clip); |
| 916 pipelineBuilder.setStencil(ss); | 917 pipelineBuilder.setStencil(ss); |
| 917 | 918 |
| 918 GrPathRenderer::DrawPathArgs args; | 919 GrPathRenderer::DrawPathArgs args; |
| 919 args.fTarget = fDrawContext->getDrawTarget(); | 920 args.fTarget = fDrawContext->getDrawTarget(); |
| 920 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour
ceProvider(); | 921 args.fResourceProvider = fDrawContext->fDrawingManager->getContext()->resour
ceProvider(); |
| 921 args.fPipelineBuilder = &pipelineBuilder; | 922 args.fPipelineBuilder = &pipelineBuilder; |
| 922 args.fColor = GrColor_WHITE; | 923 args.fColor = GrColor_WHITE; |
| 923 args.fViewMatrix = &viewMatrix; | 924 args.fViewMatrix = &viewMatrix; |
| 924 args.fPath = &path; | 925 args.fPath = &path; |
| 925 args.fStyle = &GrStyle::SimpleFill(); | 926 args.fStroke = &GrStrokeInfo::FillInfo(); |
| 926 args.fAntiAlias = useCoverageAA; | 927 args.fAntiAlias = useCoverageAA; |
| 927 args.fGammaCorrect = fDrawContext->isGammaCorrect(); | 928 args.fGammaCorrect = fDrawContext->isGammaCorrect(); |
| 928 pr->drawPath(args); | 929 pr->drawPath(args); |
| 929 return true; | 930 return true; |
| 930 } | 931 } |
| 931 | 932 |
| 932 void GrDrawContext::internalDrawPath(const GrClip& clip, | 933 void GrDrawContext::internalDrawPath(const GrClip& clip, |
| 933 const GrPaint& paint, | 934 const GrPaint& paint, |
| 934 const SkMatrix& viewMatrix, | 935 const SkMatrix& viewMatrix, |
| 935 const SkPath& origPath, | 936 const SkPath& path, |
| 936 const GrStyle& origStyle) { | 937 const GrStrokeInfo& strokeInfo) { |
| 937 ASSERT_SINGLE_OWNER | 938 ASSERT_SINGLE_OWNER |
| 938 RETURN_IF_ABANDONED | 939 RETURN_IF_ABANDONED |
| 939 SkASSERT(!origPath.isEmpty()); | 940 SkASSERT(!path.isEmpty()); |
| 940 | 941 |
| 942 // An Assumption here is that path renderer would use some form of tweaking |
| 943 // the src color (either the input alpha or in the frag shader) to implement |
| 944 // aa. If we have some future driver-mojo path AA that can do the right |
| 945 // thing WRT to the blend then we'll need some query on the PR. |
| 941 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); | 946 bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get()); |
| 942 const bool isStencilDisabled = true; | 947 const bool isStencilDisabled = true; |
| 943 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); | 948 bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled(); |
| 944 | 949 |
| 945 const GrPathRendererChain::DrawType type = | 950 const GrPathRendererChain::DrawType type = |
| 946 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType | 951 useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType |
| 947 : GrPathRendererChain::kColor_DrawType; | 952 : GrPathRendererChain::kColor_DrawType; |
| 948 | 953 |
| 954 const SkPath* pathPtr = &path; |
| 949 SkTLazy<SkPath> tmpPath; | 955 SkTLazy<SkPath> tmpPath; |
| 950 SkTLazy<GrStyle> tmpStyle; | 956 const GrStrokeInfo* strokeInfoPtr = &strokeInfo; |
| 951 | 957 |
| 952 GrPathRenderer::CanDrawPathArgs canDrawArgs; | 958 GrPathRenderer::CanDrawPathArgs canDrawArgs; |
| 953 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(
); | 959 canDrawArgs.fShaderCaps = fDrawingManager->getContext()->caps()->shaderCaps(
); |
| 954 canDrawArgs.fViewMatrix = &viewMatrix; | 960 canDrawArgs.fViewMatrix = &viewMatrix; |
| 955 canDrawArgs.fPath = &origPath; | 961 canDrawArgs.fPath = pathPtr; |
| 956 canDrawArgs.fStyle = &origStyle; | 962 canDrawArgs.fStroke = strokeInfoPtr; |
| 957 canDrawArgs.fAntiAlias = useCoverageAA; | 963 canDrawArgs.fAntiAlias = useCoverageAA; |
| 958 canDrawArgs.fIsStencilDisabled = isStencilDisabled; | 964 canDrawArgs.fIsStencilDisabled = isStencilDisabled; |
| 959 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; | 965 canDrawArgs.fIsStencilBufferMSAA = isStencilBufferMSAA; |
| 960 | 966 |
| 961 // Try a 1st time without applying any of the style to the geometry (and bar
ring sw) | 967 // Try a 1st time without stroking the path and without allowing the SW rend
erer |
| 962 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty
pe); | 968 GrPathRenderer* pr = fDrawingManager->getPathRenderer(canDrawArgs, false, ty
pe); |
| 963 SkScalar styleScale = GrStyle::MatrixToScaleFactor(viewMatrix); | |
| 964 | 969 |
| 965 if (!pr && canDrawArgs.fStyle->pathEffect()) { | 970 GrStrokeInfo dashlessStrokeInfo(strokeInfo, false); |
| 966 // It didn't work above, so try again with the path effect applied. | 971 if (nullptr == pr && strokeInfo.isDashed()) { |
| 967 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); | 972 // It didn't work above, so try again with dashed stroke converted to a
dashless stroke. |
| 968 if (!canDrawArgs.fStyle->applyPathEffectToPath(tmpPath.init(), &rec, *ca
nDrawArgs.fPath, | 973 if (!strokeInfo.applyDashToPath(tmpPath.init(), &dashlessStrokeInfo, *pa
thPtr)) { |
| 969 styleScale)) { | |
| 970 GrStyle noPathEffect(canDrawArgs.fStyle->strokeRec(), nullptr); | |
| 971 this->internalDrawPath(clip, paint, viewMatrix, *canDrawArgs.fPath,
noPathEffect); | |
| 972 return; | 974 return; |
| 973 } | 975 } |
| 974 tmpStyle.init(rec, nullptr); | 976 pathPtr = tmpPath.get(); |
| 975 canDrawArgs.fPath = tmpPath.get(); | 977 if (pathPtr->isEmpty()) { |
| 976 canDrawArgs.fStyle = tmpStyle.get(); | |
| 977 if (canDrawArgs.fPath->isEmpty()) { | |
| 978 return; | 978 return; |
| 979 } | 979 } |
| 980 strokeInfoPtr = &dashlessStrokeInfo; |
| 981 |
| 982 canDrawArgs.fPath = pathPtr; |
| 983 canDrawArgs.fStroke = strokeInfoPtr; |
| 980 | 984 |
| 981 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); | 985 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); |
| 982 } | 986 } |
| 983 if (!pr) { | 987 |
| 984 SkASSERT(!canDrawArgs.fStyle->pathEffect()); | 988 if (nullptr == pr) { |
| 985 if (canDrawArgs.fStyle->strokeRec().needToApply()) { | 989 if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*strokeInfoPtr, viewMa
trix, nullptr) && |
| 990 !strokeInfoPtr->isFillStyle()) { |
| 991 // It didn't work above, so try again with stroke converted to a fil
l. |
| 986 if (!tmpPath.isValid()) { | 992 if (!tmpPath.isValid()) { |
| 987 tmpPath.init(); | 993 tmpPath.init(); |
| 988 } | 994 } |
| 989 // It didn't work above, so try again by applying the stroke to the
geometry. | 995 dashlessStrokeInfo.setResScale(SkScalarAbs(viewMatrix.getMaxScale())
); |
| 990 SkStrokeRec::InitStyle fillOrHairline; | 996 if (!dashlessStrokeInfo.applyToPath(tmpPath.get(), *pathPtr)) { |
| 991 if (!canDrawArgs.fStyle->applyToPath(tmpPath.get(), &fillOrHairline, | |
| 992 *canDrawArgs.fPath, styleScale)
) { | |
| 993 return; | 997 return; |
| 994 } | 998 } |
| 995 if (!tmpStyle.isValid()) { | 999 pathPtr = tmpPath.get(); |
| 996 tmpStyle.init(fillOrHairline); | 1000 if (pathPtr->isEmpty()) { |
| 997 } else { | |
| 998 tmpStyle.get()->resetToInitStyle(fillOrHairline); | |
| 999 } | |
| 1000 canDrawArgs.fPath = tmpPath.get(); | |
| 1001 canDrawArgs.fStyle = tmpStyle.get(); | |
| 1002 if (canDrawArgs.fPath->isEmpty()) { | |
| 1003 return; | 1001 return; |
| 1004 } | 1002 } |
| 1003 dashlessStrokeInfo.setFillStyle(); |
| 1004 strokeInfoPtr = &dashlessStrokeInfo; |
| 1005 } |
| 1005 | 1006 |
| 1006 pr = fDrawingManager->getPathRenderer(canDrawArgs, false, type); | 1007 canDrawArgs.fPath = pathPtr; |
| 1007 } | 1008 canDrawArgs.fStroke = strokeInfoPtr; |
| 1008 | 1009 |
| 1009 // This time, allow SW renderer | 1010 // This time, allow SW renderer |
| 1010 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); | 1011 pr = fDrawingManager->getPathRenderer(canDrawArgs, true, type); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 if (nullptr == pr) { | 1014 if (nullptr == pr) { |
| 1014 #ifdef SK_DEBUG | 1015 #ifdef SK_DEBUG |
| 1015 SkDebugf("Unable to find path renderer compatible with path.\n"); | 1016 SkDebugf("Unable to find path renderer compatible with path.\n"); |
| 1016 #endif | 1017 #endif |
| 1017 return; | 1018 return; |
| 1018 } | 1019 } |
| 1019 | 1020 |
| 1020 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); | 1021 GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip); |
| 1021 | 1022 |
| 1022 GrPathRenderer::DrawPathArgs args; | 1023 GrPathRenderer::DrawPathArgs args; |
| 1023 args.fTarget = this->getDrawTarget(); | 1024 args.fTarget = this->getDrawTarget(); |
| 1024 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); | 1025 args.fResourceProvider = fDrawingManager->getContext()->resourceProvider(); |
| 1025 args.fPipelineBuilder = &pipelineBuilder; | 1026 args.fPipelineBuilder = &pipelineBuilder; |
| 1026 args.fColor = paint.getColor(); | 1027 args.fColor = paint.getColor(); |
| 1027 args.fViewMatrix = &viewMatrix; | 1028 args.fViewMatrix = &viewMatrix; |
| 1028 args.fPath = canDrawArgs.fPath; | 1029 args.fPath = pathPtr; |
| 1029 args.fStyle = canDrawArgs.fStyle; | 1030 args.fStroke = strokeInfoPtr; |
| 1030 args.fAntiAlias = useCoverageAA; | 1031 args.fAntiAlias = useCoverageAA; |
| 1031 args.fGammaCorrect = this->isGammaCorrect(); | 1032 args.fGammaCorrect = this->isGammaCorrect(); |
| 1032 pr->drawPath(args); | 1033 pr->drawPath(args); |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { | 1036 void GrDrawContext::drawBatch(GrPipelineBuilder* pipelineBuilder, GrDrawBatch* b
atch) { |
| 1036 ASSERT_SINGLE_OWNER | 1037 ASSERT_SINGLE_OWNER |
| 1037 RETURN_IF_ABANDONED | 1038 RETURN_IF_ABANDONED |
| 1038 SkDEBUGCODE(this->validate();) | 1039 SkDEBUGCODE(this->validate();) |
| 1039 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); | 1040 GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::drawBatch"); |
| 1040 | 1041 |
| 1041 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); | 1042 this->getDrawTarget()->drawBatch(*pipelineBuilder, batch); |
| 1042 } | 1043 } |
| OLD | NEW |