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 "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "SkStroke.h" | 37 #include "SkStroke.h" |
38 #include "SkSurface.h" | 38 #include "SkSurface.h" |
39 #include "SkSurface_Gpu.h" | 39 #include "SkSurface_Gpu.h" |
40 #include "SkTLazy.h" | 40 #include "SkTLazy.h" |
41 #include "SkUtils.h" | 41 #include "SkUtils.h" |
42 #include "SkVertState.h" | 42 #include "SkVertState.h" |
43 #include "SkXfermode.h" | 43 #include "SkXfermode.h" |
44 #include "batches/GrRectBatchFactory.h" | 44 #include "batches/GrRectBatchFactory.h" |
45 #include "effects/GrBicubicEffect.h" | 45 #include "effects/GrBicubicEffect.h" |
46 #include "effects/GrDashingEffect.h" | 46 #include "effects/GrDashingEffect.h" |
| 47 #include "effects/GrRRectEffect.h" |
47 #include "effects/GrSimpleTextureEffect.h" | 48 #include "effects/GrSimpleTextureEffect.h" |
48 #include "effects/GrTextureDomain.h" | 49 #include "effects/GrTextureDomain.h" |
49 #include "text/GrTextUtils.h" | 50 #include "text/GrTextUtils.h" |
50 | 51 |
51 #if SK_SUPPORT_GPU | 52 #if SK_SUPPORT_GPU |
52 | 53 |
53 #define ASSERT_SINGLE_OWNER \ | 54 #define ASSERT_SINGLE_OWNER \ |
54 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->debugSing
leOwner());) | 55 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->debugSing
leOwner());) |
55 | 56 |
56 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; | 57 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 *draw.fMatrix, nullptr, | 556 *draw.fMatrix, nullptr, |
556 draw.fClip->getBounds(), true); | 557 draw.fClip->getBounds(), true); |
557 return; | 558 return; |
558 } | 559 } |
559 | 560 |
560 SkASSERT(!strokeInfo.isDashed()); | 561 SkASSERT(!strokeInfo.isDashed()); |
561 | 562 |
562 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); | 563 fDrawContext->drawRRect(fClip, grPaint, *draw.fMatrix, rect, strokeInfo); |
563 } | 564 } |
564 | 565 |
| 566 bool SkGpuDevice::drawFilledDRRect(const SkMatrix& viewMatrix, const SkRRect& or
igOuter, |
| 567 const SkRRect& origInner, const SkPaint& pain
t) { |
| 568 SkASSERT(!origInner.isEmpty()); |
| 569 SkASSERT(!origOuter.isEmpty()); |
| 570 |
| 571 bool applyAA = paint.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled(
); |
| 572 |
| 573 GrPrimitiveEdgeType innerEdgeType = applyAA ? kInverseFillAA_GrProcessorEdge
Type : |
| 574 kInverseFillBW_GrProcessorEdge
Type; |
| 575 GrPrimitiveEdgeType outerEdgeType = applyAA ? kFillAA_GrProcessorEdgeType : |
| 576 kFillBW_GrProcessorEdgeType; |
| 577 |
| 578 SkTCopyOnFirstWrite<SkRRect> inner(origInner), outer(origOuter); |
| 579 SkMatrix inverseVM; |
| 580 if (!viewMatrix.isIdentity()) { |
| 581 if (!origInner.transform(viewMatrix, inner.writable())) { |
| 582 return false; |
| 583 } |
| 584 if (!origOuter.transform(viewMatrix, outer.writable())) { |
| 585 return false; |
| 586 } |
| 587 if (!viewMatrix.invert(&inverseVM)) { |
| 588 return false; |
| 589 } |
| 590 } else { |
| 591 inverseVM.reset(); |
| 592 } |
| 593 |
| 594 GrPaint grPaint; |
| 595 |
| 596 if (!SkPaintToGrPaint(this->context(), paint, viewMatrix, &grPaint)) { |
| 597 return false; |
| 598 } |
| 599 |
| 600 grPaint.setAntiAlias(false); |
| 601 |
| 602 // TODO these need to be a geometry processors |
| 603 SkAutoTUnref<GrFragmentProcessor> innerEffect(GrRRectEffect::Create(innerEdg
eType, *inner)); |
| 604 if (!innerEffect) { |
| 605 return false; |
| 606 } |
| 607 |
| 608 SkAutoTUnref<GrFragmentProcessor> outerEffect(GrRRectEffect::Create(outerEdg
eType, *outer)); |
| 609 if (!outerEffect) { |
| 610 return false; |
| 611 } |
| 612 |
| 613 grPaint.addCoverageFragmentProcessor(innerEffect); |
| 614 grPaint.addCoverageFragmentProcessor(outerEffect); |
| 615 |
| 616 SkRect bounds = outer->getBounds(); |
| 617 if (applyAA) { |
| 618 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
| 619 } |
| 620 |
| 621 fDrawContext->fillRectWithLocalMatrix(fClip, grPaint, SkMatrix::I(), bounds,
inverseVM); |
| 622 return true; |
| 623 } |
| 624 |
| 625 |
565 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 626 void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
566 const SkRRect& inner, const SkPaint& paint) { | 627 const SkRRect& inner, const SkPaint& paint) { |
567 ASSERT_SINGLE_OWNER | 628 ASSERT_SINGLE_OWNER |
568 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); | 629 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext); |
569 CHECK_FOR_ANNOTATION(paint); | 630 CHECK_FOR_ANNOTATION(paint); |
570 CHECK_SHOULD_DRAW(draw); | 631 CHECK_SHOULD_DRAW(draw); |
571 | 632 |
| 633 if (outer.isEmpty()) { |
| 634 return; |
| 635 } |
| 636 |
| 637 if (inner.isEmpty()) { |
| 638 return this->drawRRect(draw, outer, paint); |
| 639 } |
| 640 |
572 SkStrokeRec stroke(paint); | 641 SkStrokeRec stroke(paint); |
573 | 642 |
574 if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()
) { | 643 if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()
) { |
575 GrPaint grPaint; | 644 if (this->drawFilledDRRect(*draw.fMatrix, outer, inner, paint)) { |
576 if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix, &grPaint))
{ | |
577 return; | 645 return; |
578 } | 646 } |
579 | |
580 fDrawContext->drawDRRect(fClip, grPaint, *draw.fMatrix, outer, inner); | |
581 return; | |
582 } | 647 } |
583 | 648 |
584 SkPath path; | 649 SkPath path; |
585 path.setIsVolatile(true); | 650 path.setIsVolatile(true); |
586 path.addRRect(outer); | 651 path.addRRect(outer); |
587 path.addRRect(inner); | 652 path.addRRect(inner); |
588 path.setFillType(SkPath::kEvenOdd_FillType); | 653 path.setFillType(SkPath::kEvenOdd_FillType); |
589 | 654 |
590 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, | 655 GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext, |
591 fClip, path, paint, | 656 fClip, path, paint, |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 } | 1948 } |
1884 | 1949 |
1885 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1950 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1886 ASSERT_SINGLE_OWNER | 1951 ASSERT_SINGLE_OWNER |
1887 // We always return a transient cache, so it is freed after each | 1952 // We always return a transient cache, so it is freed after each |
1888 // filter traversal. | 1953 // filter traversal. |
1889 return SkGpuDevice::NewImageFilterCache(); | 1954 return SkGpuDevice::NewImageFilterCache(); |
1890 } | 1955 } |
1891 | 1956 |
1892 #endif | 1957 #endif |
OLD | NEW |