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/GrTextureDomainEffect.h" | 10 #include "effects/GrTextureDomainEffect.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 #define DO_DEFERRED_CLEAR() \ | 47 #define DO_DEFERRED_CLEAR() \ |
48 do { \ | 48 do { \ |
49 if (fNeedClear) { \ | 49 if (fNeedClear) { \ |
50 this->clear(SK_ColorTRANSPARENT); \ | 50 this->clear(SK_ColorTRANSPARENT); \ |
51 } \ | 51 } \ |
52 } while (false) \ | 52 } while (false) \ |
53 | 53 |
54 /////////////////////////////////////////////////////////////////////////////// | 54 /////////////////////////////////////////////////////////////////////////////// |
55 | 55 |
56 #define CHECK_FOR_NODRAW_ANNOTATION(paint) \ | 56 #define CHECK_FOR_ANNOTATION(paint) \ |
57 do { if (paint.isNoDrawAnnotation()) { return; } } while (0) | 57 do { if (paint.getAnnotation()) { return; } } while (0) |
58 | 58 |
59 /////////////////////////////////////////////////////////////////////////////// | 59 /////////////////////////////////////////////////////////////////////////////// |
60 | 60 |
61 | 61 |
62 class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable { | 62 class SkGpuDevice::SkAutoCachedTexture : public ::SkNoncopyable { |
63 public: | 63 public: |
64 SkAutoCachedTexture() | 64 SkAutoCachedTexture() |
65 : fDevice(NULL) | 65 : fDevice(NULL) |
66 , fTexture(NULL) { | 66 , fTexture(NULL) { |
67 } | 67 } |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 | 565 |
566 // must be in SkCanvas::PointMode order | 566 // must be in SkCanvas::PointMode order |
567 static const GrPrimitiveType gPointMode2PrimtiveType[] = { | 567 static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
568 kPoints_GrPrimitiveType, | 568 kPoints_GrPrimitiveType, |
569 kLines_GrPrimitiveType, | 569 kLines_GrPrimitiveType, |
570 kLineStrip_GrPrimitiveType | 570 kLineStrip_GrPrimitiveType |
571 }; | 571 }; |
572 | 572 |
573 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | 573 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
574 size_t count, const SkPoint pts[], const SkPaint& p
aint) { | 574 size_t count, const SkPoint pts[], const SkPaint& p
aint) { |
575 CHECK_FOR_NODRAW_ANNOTATION(paint); | 575 CHECK_FOR_ANNOTATION(paint); |
576 CHECK_SHOULD_DRAW(draw, false); | 576 CHECK_SHOULD_DRAW(draw, false); |
577 | 577 |
578 SkScalar width = paint.getStrokeWidth(); | 578 SkScalar width = paint.getStrokeWidth(); |
579 if (width < 0) { | 579 if (width < 0) { |
580 return; | 580 return; |
581 } | 581 } |
582 | 582 |
583 // we only handle hairlines and paints without path effects or mask filters, | 583 // we only handle hairlines and paints without path effects or mask filters, |
584 // else we let the SkDraw call our drawPath() | 584 // else we let the SkDraw call our drawPath() |
585 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { | 585 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { |
(...skipping 13 matching lines...) Expand all Loading... |
599 NULL, | 599 NULL, |
600 NULL, | 600 NULL, |
601 NULL, | 601 NULL, |
602 0); | 602 0); |
603 } | 603 } |
604 | 604 |
605 /////////////////////////////////////////////////////////////////////////////// | 605 /////////////////////////////////////////////////////////////////////////////// |
606 | 606 |
607 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, | 607 void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, |
608 const SkPaint& paint) { | 608 const SkPaint& paint) { |
609 CHECK_FOR_NODRAW_ANNOTATION(paint); | 609 CHECK_FOR_ANNOTATION(paint); |
610 CHECK_SHOULD_DRAW(draw, false); | 610 CHECK_SHOULD_DRAW(draw, false); |
611 | 611 |
612 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; | 612 bool doStroke = paint.getStyle() != SkPaint::kFill_Style; |
613 SkScalar width = paint.getStrokeWidth(); | 613 SkScalar width = paint.getStrokeWidth(); |
614 | 614 |
615 /* | 615 /* |
616 We have special code for hairline strokes, miter-strokes, and fills. | 616 We have special code for hairline strokes, miter-strokes, and fills. |
617 Anything else we just call our path code. | 617 Anything else we just call our path code. |
618 */ | 618 */ |
619 bool usePath = doStroke && width > 0 && | 619 bool usePath = doStroke && width > 0 && |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 655 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
656 return; | 656 return; |
657 } | 657 } |
658 fContext->drawRect(grPaint, rect, doStroke ? width : -1); | 658 fContext->drawRect(grPaint, rect, doStroke ? width : -1); |
659 } | 659 } |
660 | 660 |
661 /////////////////////////////////////////////////////////////////////////////// | 661 /////////////////////////////////////////////////////////////////////////////// |
662 | 662 |
663 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, | 663 void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect, |
664 const SkPaint& paint) { | 664 const SkPaint& paint) { |
665 CHECK_FOR_NODRAW_ANNOTATION(paint); | 665 CHECK_FOR_ANNOTATION(paint); |
666 CHECK_SHOULD_DRAW(draw, false); | 666 CHECK_SHOULD_DRAW(draw, false); |
667 | 667 |
668 bool usePath = !rect.isSimple(); | 668 bool usePath = !rect.isSimple(); |
669 // another two reasons we might need to call drawPath... | 669 // another two reasons we might need to call drawPath... |
670 if (paint.getMaskFilter() || paint.getPathEffect()) { | 670 if (paint.getMaskFilter() || paint.getPathEffect()) { |
671 usePath = true; | 671 usePath = true; |
672 } | 672 } |
673 // until we can rotate rrects... | 673 // until we can rotate rrects... |
674 if (!usePath && !fContext->getMatrix().rectStaysRect()) { | 674 if (!usePath && !fContext->getMatrix().rectStaysRect()) { |
675 usePath = true; | 675 usePath = true; |
(...skipping 12 matching lines...) Expand all Loading... |
688 } | 688 } |
689 | 689 |
690 SkStrokeRec stroke(paint); | 690 SkStrokeRec stroke(paint); |
691 fContext->drawRRect(grPaint, rect, stroke); | 691 fContext->drawRRect(grPaint, rect, stroke); |
692 } | 692 } |
693 | 693 |
694 /////////////////////////////////////////////////////////////////////////////// | 694 /////////////////////////////////////////////////////////////////////////////// |
695 | 695 |
696 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, | 696 void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, |
697 const SkPaint& paint) { | 697 const SkPaint& paint) { |
698 CHECK_FOR_NODRAW_ANNOTATION(paint); | 698 CHECK_FOR_ANNOTATION(paint); |
699 CHECK_SHOULD_DRAW(draw, false); | 699 CHECK_SHOULD_DRAW(draw, false); |
700 | 700 |
701 bool usePath = false; | 701 bool usePath = false; |
702 // some basic reasons we might need to call drawPath... | 702 // some basic reasons we might need to call drawPath... |
703 if (paint.getMaskFilter() || paint.getPathEffect()) { | 703 if (paint.getMaskFilter() || paint.getPathEffect()) { |
704 usePath = true; | 704 usePath = true; |
705 } | 705 } |
706 | 706 |
707 if (usePath) { | 707 if (usePath) { |
708 SkPath path; | 708 SkPath path; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 | 780 |
781 GrAutoScratchTexture ast(context, desc); | 781 GrAutoScratchTexture ast(context, desc); |
782 GrTexture* texture = ast.texture(); | 782 GrTexture* texture = ast.texture(); |
783 | 783 |
784 if (NULL == texture) { | 784 if (NULL == texture) { |
785 return false; | 785 return false; |
786 } | 786 } |
787 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, | 787 texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, |
788 dstM.fImage, dstM.fRowBytes); | 788 dstM.fImage, dstM.fRowBytes); |
789 | 789 |
790 SkRect maskRect = SkRect::MakeFromIRect(dstM.fBounds); | 790 SkRect maskRect = SkRect::Make(dstM.fBounds); |
791 | 791 |
792 return draw_mask(context, maskRect, grp, texture); | 792 return draw_mask(context, maskRect, grp, texture); |
793 } | 793 } |
794 | 794 |
795 // Create a mask of 'devPath' and place the result in 'mask'. Return true on | 795 // Create a mask of 'devPath' and place the result in 'mask'. Return true on |
796 // success; false otherwise. | 796 // success; false otherwise. |
797 bool create_mask_GPU(GrContext* context, | 797 bool create_mask_GPU(GrContext* context, |
798 const SkRect& maskRect, | 798 const SkRect& maskRect, |
799 const SkPath& devPath, | 799 const SkPath& devPath, |
800 const SkStrokeRec& stroke, | 800 const SkStrokeRec& stroke, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 result.setConfig(config, texture->width(), texture->height()); | 853 result.setConfig(config, texture->width(), texture->height()); |
854 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); | 854 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (texture)))->unref(); |
855 return result; | 855 return result; |
856 } | 856 } |
857 | 857 |
858 }; | 858 }; |
859 | 859 |
860 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, | 860 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, |
861 const SkPaint& paint, const SkMatrix* prePathMatrix, | 861 const SkPaint& paint, const SkMatrix* prePathMatrix, |
862 bool pathIsMutable) { | 862 bool pathIsMutable) { |
863 CHECK_FOR_NODRAW_ANNOTATION(paint); | 863 CHECK_FOR_ANNOTATION(paint); |
864 CHECK_SHOULD_DRAW(draw, false); | 864 CHECK_SHOULD_DRAW(draw, false); |
865 | 865 |
866 GrPaint grPaint; | 866 GrPaint grPaint; |
867 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { | 867 if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) { |
868 return; | 868 return; |
869 } | 869 } |
870 | 870 |
871 // can we cheat, and treat a thin stroke as a hairline w/ coverage | 871 // can we cheat, and treat a thin stroke as a hairline w/ coverage |
872 // if we can, we draw lots faster (raster device does this same test) | 872 // if we can, we draw lots faster (raster device does this same test) |
873 SkScalar hairlineCoverage; | 873 SkScalar hairlineCoverage; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 const SkBitmap& bitmap, | 1010 const SkBitmap& bitmap, |
1011 const SkRect* srcRectPtr, | 1011 const SkRect* srcRectPtr, |
1012 SkIRect* clippedSrcIRect) { | 1012 SkIRect* clippedSrcIRect) { |
1013 const GrClipData* clip = context->getClip(); | 1013 const GrClipData* clip = context->getClip(); |
1014 clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NUL
L); | 1014 clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NUL
L); |
1015 SkMatrix inv; | 1015 SkMatrix inv; |
1016 if (!context->getMatrix().invert(&inv)) { | 1016 if (!context->getMatrix().invert(&inv)) { |
1017 clippedSrcIRect->setEmpty(); | 1017 clippedSrcIRect->setEmpty(); |
1018 return; | 1018 return; |
1019 } | 1019 } |
1020 SkRect clippedSrcRect = SkRect::MakeFromIRect(*clippedSrcIRect); | 1020 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); |
1021 inv.mapRect(&clippedSrcRect); | 1021 inv.mapRect(&clippedSrcRect); |
1022 if (NULL != srcRectPtr) { | 1022 if (NULL != srcRectPtr) { |
1023 if (!clippedSrcRect.intersect(*srcRectPtr)) { | 1023 if (!clippedSrcRect.intersect(*srcRectPtr)) { |
1024 clippedSrcIRect->setEmpty(); | 1024 clippedSrcIRect->setEmpty(); |
1025 return; | 1025 return; |
1026 } | 1026 } |
1027 } | 1027 } |
1028 clippedSrcRect.roundOut(clippedSrcIRect); | 1028 clippedSrcRect.roundOut(clippedSrcIRect); |
1029 SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); | 1029 SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
1030 if (!clippedSrcIRect->intersect(bmpBounds)) { | 1030 if (!clippedSrcIRect->intersect(bmpBounds)) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 | 1229 |
1230 // Break 'bitmap' into several tiles to draw it since it has already | 1230 // Break 'bitmap' into several tiles to draw it since it has already |
1231 // been determined to be too large to fit in VRAM | 1231 // been determined to be too large to fit in VRAM |
1232 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, | 1232 void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
1233 const SkRect& srcRect, | 1233 const SkRect& srcRect, |
1234 const SkIRect& clippedSrcIRect, | 1234 const SkIRect& clippedSrcIRect, |
1235 const GrTextureParams& params, | 1235 const GrTextureParams& params, |
1236 const SkPaint& paint, | 1236 const SkPaint& paint, |
1237 SkCanvas::DrawBitmapRectFlags flags, | 1237 SkCanvas::DrawBitmapRectFlags flags, |
1238 int tileSize) { | 1238 int tileSize) { |
1239 SkRect clippedSrcRect = SkRect::MakeFromIRect(clippedSrcIRect); | 1239 SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
1240 | 1240 |
1241 int nx = bitmap.width() / tileSize; | 1241 int nx = bitmap.width() / tileSize; |
1242 int ny = bitmap.height() / tileSize; | 1242 int ny = bitmap.height() / tileSize; |
1243 for (int x = 0; x <= nx; x++) { | 1243 for (int x = 0; x <= nx; x++) { |
1244 for (int y = 0; y <= ny; y++) { | 1244 for (int y = 0; y <= ny; y++) { |
1245 SkRect tileR; | 1245 SkRect tileR; |
1246 tileR.set(SkIntToScalar(x * tileSize), | 1246 tileR.set(SkIntToScalar(x * tileSize), |
1247 SkIntToScalar(y * tileSize), | 1247 SkIntToScalar(y * tileSize), |
1248 SkIntToScalar((x + 1) * tileSize), | 1248 SkIntToScalar((x + 1) * tileSize), |
1249 SkIntToScalar((y + 1) * tileSize)); | 1249 SkIntToScalar((y + 1) * tileSize)); |
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 GrTexture* texture, | 1851 GrTexture* texture, |
1852 bool needClear) | 1852 bool needClear) |
1853 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { | 1853 : SkBitmapDevice(make_bitmap(context, texture->asRenderTarget())) { |
1854 | 1854 |
1855 SkASSERT(texture && texture->asRenderTarget()); | 1855 SkASSERT(texture && texture->asRenderTarget()); |
1856 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture | 1856 // This constructor is called from onCreateCompatibleDevice. It has locked t
he RT in the texture |
1857 // cache. We pass true for the third argument so that it will get unlocked. | 1857 // cache. We pass true for the third argument so that it will get unlocked. |
1858 this->initFromRenderTarget(context, texture->asRenderTarget(), true); | 1858 this->initFromRenderTarget(context, texture->asRenderTarget(), true); |
1859 fNeedClear = needClear; | 1859 fNeedClear = needClear; |
1860 } | 1860 } |
OLD | NEW |