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 "GrBitmapTextContext.h" | 10 #include "GrBitmapTextContext.h" |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 kDevice_GrCoordSet))
->unref(); | 632 kDevice_GrCoordSet))
->unref(); |
633 | 633 |
634 SkMatrix inverse; | 634 SkMatrix inverse; |
635 if (!viewMatrix.invert(&inverse)) { | 635 if (!viewMatrix.invert(&inverse)) { |
636 return false; | 636 return false; |
637 } | 637 } |
638 context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), maskRec
t, inverse); | 638 context->drawNonAARectWithLocalMatrix(rt, clip, *grp, SkMatrix::I(), maskRec
t, inverse); |
639 return true; | 639 return true; |
640 } | 640 } |
641 | 641 |
| 642 static bool clip_bounds_quick_reject(const SkIRect& clipBounds, const SkIRect& r
ect) { |
| 643 return clipBounds.isEmpty() || rect.isEmpty() || !SkIRect::Intersects(clipBo
unds, rect); |
| 644 } |
| 645 |
642 bool draw_with_mask_filter(GrContext* context, | 646 bool draw_with_mask_filter(GrContext* context, |
643 GrRenderTarget* rt, | 647 GrRenderTarget* rt, |
644 const GrClip& clipData, | 648 const GrClip& clipData, |
645 const SkMatrix& viewMatrix, | 649 const SkMatrix& viewMatrix, |
646 const SkPath& devPath, | 650 const SkPath& devPath, |
647 SkMaskFilter* filter, | 651 SkMaskFilter* filter, |
648 const SkRegion& clip, | 652 const SkIRect& clipBounds, |
649 GrPaint* grp, | 653 GrPaint* grp, |
650 SkPaint::Style style) { | 654 SkPaint::Style style) { |
651 SkMask srcM, dstM; | 655 SkMask srcM, dstM; |
652 | 656 |
653 if (!SkDraw::DrawToMask(devPath, &clip.getBounds(), filter, &viewMatrix, &sr
cM, | 657 if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, |
654 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { | 658 SkMask::kComputeBoundsAndRenderImage_CreateMode, sty
le)) { |
655 return false; | 659 return false; |
656 } | 660 } |
657 SkAutoMaskFreeImage autoSrc(srcM.fImage); | 661 SkAutoMaskFreeImage autoSrc(srcM.fImage); |
658 | 662 |
659 if (!filter->filterMask(&dstM, srcM, viewMatrix, NULL)) { | 663 if (!filter->filterMask(&dstM, srcM, viewMatrix, NULL)) { |
660 return false; | 664 return false; |
661 } | 665 } |
662 // this will free-up dstM when we're done (allocated in filterMask()) | 666 // this will free-up dstM when we're done (allocated in filterMask()) |
663 SkAutoMaskFreeImage autoDst(dstM.fImage); | 667 SkAutoMaskFreeImage autoDst(dstM.fImage); |
664 | 668 |
665 if (clip.quickReject(dstM.fBounds)) { | 669 if (clip_bounds_quick_reject(clipBounds, dstM.fBounds)) { |
666 return false; | 670 return false; |
667 } | 671 } |
668 | 672 |
669 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using | 673 // we now have a device-aligned 8bit mask in dstM, ready to be drawn using |
670 // the current clip (and identity matrix) and GrPaint settings | 674 // the current clip (and identity matrix) and GrPaint settings |
671 GrSurfaceDesc desc; | 675 GrSurfaceDesc desc; |
672 desc.fWidth = dstM.fBounds.width(); | 676 desc.fWidth = dstM.fBounds.width(); |
673 desc.fHeight = dstM.fBounds.height(); | 677 desc.fHeight = dstM.fBounds.height(); |
674 desc.fConfig = kAlpha_8_GrPixelConfig; | 678 desc.fConfig = kAlpha_8_GrPixelConfig; |
675 | 679 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 744 |
741 }; | 745 }; |
742 | 746 |
743 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 747 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
744 const SkPaint& paint, const SkMatrix* prePathMatrix, | 748 const SkPaint& paint, const SkMatrix* prePathMatrix, |
745 bool pathIsMutable) { | 749 bool pathIsMutable) { |
746 CHECK_FOR_ANNOTATION(paint); | 750 CHECK_FOR_ANNOTATION(paint); |
747 CHECK_SHOULD_DRAW(draw); | 751 CHECK_SHOULD_DRAW(draw); |
748 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); | 752 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPath", fContext); |
749 | 753 |
| 754 return this->internalDrawPath(origSrcPath, paint, *draw.fMatrix, prePathMatr
ix, |
| 755 draw.fClip->getBounds(), pathIsMutable); |
| 756 } |
| 757 |
| 758 void SkGpuDevice::internalDrawPath(const SkPath& origSrcPath, const SkPaint& pai
nt, |
| 759 const SkMatrix& origViewMatrix, const SkMatri
x* prePathMatrix, |
| 760 const SkIRect& clipBounds, bool pathIsMutable
) { |
750 SkASSERT(!pathIsMutable || origSrcPath.isVolatile()); | 761 SkASSERT(!pathIsMutable || origSrcPath.isVolatile()); |
751 | 762 |
752 GrStrokeInfo strokeInfo(paint); | 763 GrStrokeInfo strokeInfo(paint); |
753 | 764 |
754 // If we have a prematrix, apply it to the path, optimizing for the case | 765 // If we have a prematrix, apply it to the path, optimizing for the case |
755 // where the original path can in fact be modified in place (even though | 766 // where the original path can in fact be modified in place (even though |
756 // its parameter type is const). | 767 // its parameter type is const). |
757 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); | 768 SkPath* pathPtr = const_cast<SkPath*>(&origSrcPath); |
758 SkTLazy<SkPath> tmpPath; | 769 SkTLazy<SkPath> tmpPath; |
759 SkTLazy<SkPath> effectPath; | 770 SkTLazy<SkPath> effectPath; |
760 SkPathEffect* pathEffect = paint.getPathEffect(); | 771 SkPathEffect* pathEffect = paint.getPathEffect(); |
761 | 772 |
762 SkMatrix viewMatrix = *draw.fMatrix; | 773 SkMatrix viewMatrix = origViewMatrix; |
763 | 774 |
764 if (prePathMatrix) { | 775 if (prePathMatrix) { |
765 // stroking and path effects are supposed to be applied *after* the preP
athMatrix. | 776 // stroking and path effects are supposed to be applied *after* the preP
athMatrix. |
766 // The pre-path-matrix also should not affect shadeing. | 777 // The pre-path-matrix also should not affect shadeing. |
767 if (NULL == pathEffect && NULL == paint.getShader() && | 778 if (NULL == pathEffect && NULL == paint.getShader() && |
768 (strokeInfo.getStrokeRec().isFillStyle() || | 779 (strokeInfo.getStrokeRec().isFillStyle() || |
769 strokeInfo.getStrokeRec().isHairlineStyle())) { | 780 strokeInfo.getStrokeRec().isHairlineStyle())) { |
770 viewMatrix.preConcat(*prePathMatrix); | 781 viewMatrix.preConcat(*prePathMatrix); |
771 } else { | 782 } else { |
772 SkPath* result = pathPtr; | 783 SkPath* result = pathPtr; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); | 823 SkPath* devPathPtr = pathIsMutable ? pathPtr : tmpPath.init(); |
813 if (!pathIsMutable) { | 824 if (!pathIsMutable) { |
814 devPathPtr->setIsVolatile(true); | 825 devPathPtr->setIsVolatile(true); |
815 } | 826 } |
816 | 827 |
817 // transform the path into device space | 828 // transform the path into device space |
818 pathPtr->transform(viewMatrix, devPathPtr); | 829 pathPtr->transform(viewMatrix, devPathPtr); |
819 | 830 |
820 SkRect maskRect; | 831 SkRect maskRect; |
821 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), | 832 if (paint.getMaskFilter()->canFilterMaskGPU(devPathPtr->getBounds(), |
822 draw.fClip->getBounds(), | 833 clipBounds, |
823 viewMatrix, | 834 viewMatrix, |
824 &maskRect)) { | 835 &maskRect)) { |
825 SkIRect finalIRect; | 836 SkIRect finalIRect; |
826 maskRect.roundOut(&finalIRect); | 837 maskRect.roundOut(&finalIRect); |
827 if (draw.fClip->quickReject(finalIRect)) { | 838 if (clip_bounds_quick_reject(clipBounds, finalIRect)) { |
828 // clipped out | 839 // clipped out |
829 return; | 840 return; |
830 } | 841 } |
831 | 842 |
832 if (paint.getMaskFilter()->directFilterMaskGPU(fContext, | 843 if (paint.getMaskFilter()->directFilterMaskGPU(fContext, |
833 fRenderTarget, | 844 fRenderTarget, |
834 &grPaint, | 845 &grPaint, |
835 fClip, | 846 fClip, |
836 viewMatrix, | 847 viewMatrix, |
837 stroke, | 848 stroke, |
(...skipping 29 matching lines...) Expand all Loading... |
867 } | 878 } |
868 } | 879 } |
869 } | 880 } |
870 } | 881 } |
871 | 882 |
872 // draw the mask on the CPU - this is a fallthrough path in case the | 883 // draw the mask on the CPU - this is a fallthrough path in case the |
873 // GPU path fails | 884 // GPU path fails |
874 SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style
: | 885 SkPaint::Style style = stroke.isHairlineStyle() ? SkPaint::kStroke_Style
: |
875 SkPaint::kFill_Style; | 886 SkPaint::kFill_Style; |
876 draw_with_mask_filter(fContext, fRenderTarget, fClip, viewMatrix, *devPa
thPtr, | 887 draw_with_mask_filter(fContext, fRenderTarget, fClip, viewMatrix, *devPa
thPtr, |
877 paint.getMaskFilter(), *draw.fClip, &grPaint, styl
e); | 888 paint.getMaskFilter(), clipBounds, &grPaint, style
); |
878 return; | 889 return; |
879 } | 890 } |
880 | 891 |
881 fContext->drawPath(fRenderTarget, fClip, grPaint, viewMatrix, *pathPtr, stro
keInfo); | 892 fContext->drawPath(fRenderTarget, fClip, grPaint, viewMatrix, *pathPtr, stro
keInfo); |
882 } | 893 } |
883 | 894 |
884 static const int kBmpSmallTileSize = 1 << 10; | 895 static const int kBmpSmallTileSize = 1 << 10; |
885 | 896 |
886 static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { | 897 static inline int get_tile_count(const SkIRect& srcRect, int tileSize) { |
887 int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; | 898 int tilesX = (srcRect.fRight / tileSize) - (srcRect.fLeft / tileSize) + 1; |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 #endif | 1976 #endif |
1966 } | 1977 } |
1967 | 1978 |
1968 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1979 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1969 // We always return a transient cache, so it is freed after each | 1980 // We always return a transient cache, so it is freed after each |
1970 // filter traversal. | 1981 // filter traversal. |
1971 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1982 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1972 } | 1983 } |
1973 | 1984 |
1974 #endif | 1985 #endif |
OLD | NEW |