OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 #define __STDC_LIMIT_MACROS | 7 #define __STDC_LIMIT_MACROS |
8 | 8 |
9 #include "SkDraw.h" | 9 #include "SkDraw.h" |
10 #include "SkBlitter.h" | 10 #include "SkBlitter.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "SkMatrixUtils.h" | 35 #include "SkMatrixUtils.h" |
36 | 36 |
37 //#define TRACE_BITMAP_DRAWS | 37 //#define TRACE_BITMAP_DRAWS |
38 | 38 |
39 | 39 |
40 /** Helper for allocating small blitters on the stack. | 40 /** Helper for allocating small blitters on the stack. |
41 */ | 41 */ |
42 class SkAutoBlitterChoose : SkNoncopyable { | 42 class SkAutoBlitterChoose : SkNoncopyable { |
43 public: | 43 public: |
44 SkAutoBlitterChoose() { | 44 SkAutoBlitterChoose() { |
45 fBlitter = NULL; | 45 fBlitter = nullptr; |
46 } | 46 } |
47 SkAutoBlitterChoose(const SkPixmap& dst, const SkMatrix& matrix, | 47 SkAutoBlitterChoose(const SkPixmap& dst, const SkMatrix& matrix, |
48 const SkPaint& paint, bool drawCoverage = false) { | 48 const SkPaint& paint, bool drawCoverage = false) { |
49 fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAllocator, drawCovera
ge); | 49 fBlitter = SkBlitter::Choose(dst, matrix, paint, &fAllocator, drawCovera
ge); |
50 } | 50 } |
51 | 51 |
52 SkBlitter* operator->() { return fBlitter; } | 52 SkBlitter* operator->() { return fBlitter; } |
53 SkBlitter* get() const { return fBlitter; } | 53 SkBlitter* get() const { return fBlitter; } |
54 | 54 |
55 void choose(const SkPixmap& dst, const SkMatrix& matrix, | 55 void choose(const SkPixmap& dst, const SkMatrix& matrix, |
(...skipping 10 matching lines...) Expand all Loading... |
66 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) | 66 #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) |
67 | 67 |
68 /** | 68 /** |
69 * Since we are providing the storage for the shader (to avoid the perf cost | 69 * Since we are providing the storage for the shader (to avoid the perf cost |
70 * of calling new) we insist that in our destructor we can account for all | 70 * of calling new) we insist that in our destructor we can account for all |
71 * owners of the shader. | 71 * owners of the shader. |
72 */ | 72 */ |
73 class SkAutoBitmapShaderInstall : SkNoncopyable { | 73 class SkAutoBitmapShaderInstall : SkNoncopyable { |
74 public: | 74 public: |
75 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, | 75 SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, |
76 const SkMatrix* localMatrix = NULL) | 76 const SkMatrix* localMatrix = nullptr) |
77 : fPaint(paint) /* makes a copy of the paint */ { | 77 : fPaint(paint) /* makes a copy of the paint */ { |
78 fPaint.setShader(SkCreateBitmapShader(src, SkShader::kClamp_TileMode, | 78 fPaint.setShader(SkCreateBitmapShader(src, SkShader::kClamp_TileMode, |
79 SkShader::kClamp_TileMode, | 79 SkShader::kClamp_TileMode, |
80 localMatrix, &fAllocator)); | 80 localMatrix, &fAllocator)); |
81 // we deliberately left the shader with an owner-count of 2 | 81 // we deliberately left the shader with an owner-count of 2 |
82 SkASSERT(2 == fPaint.getShader()->getRefCnt()); | 82 SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
83 } | 83 } |
84 | 84 |
85 ~SkAutoBitmapShaderInstall() { | 85 ~SkAutoBitmapShaderInstall() { |
86 // since fAllocator will destroy shader, we insist that owners == 2 | 86 // since fAllocator will destroy shader, we insist that owners == 2 |
87 SkASSERT(2 == fPaint.getShader()->getRefCnt()); | 87 SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
88 | 88 |
89 fPaint.setShader(NULL); // unref the shader by 1 | 89 fPaint.setShader(nullptr); // unref the shader by 1 |
90 | 90 |
91 } | 91 } |
92 | 92 |
93 // return the new paint that has the shader applied | 93 // return the new paint that has the shader applied |
94 const SkPaint& paintWithShader() const { return fPaint; } | 94 const SkPaint& paintWithShader() const { return fPaint; } |
95 | 95 |
96 private: | 96 private: |
97 // copy of caller's paint (which we then modify) | 97 // copy of caller's paint (which we then modify) |
98 SkPaint fPaint; | 98 SkPaint fPaint; |
99 // Stores the shader. | 99 // Stores the shader. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { | 149 static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { |
150 memset(pixels, data, bytes); | 150 memset(pixels, data, bytes); |
151 } | 151 } |
152 | 152 |
153 static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
aint, | 153 static BitmapXferProc ChooseBitmapXferProc(const SkPixmap& dst, const SkPaint& p
aint, |
154 uint32_t* data) { | 154 uint32_t* data) { |
155 // todo: we can apply colorfilter up front if no shader, so we wouldn't | 155 // todo: we can apply colorfilter up front if no shader, so we wouldn't |
156 // need to abort this fastpath | 156 // need to abort this fastpath |
157 if (paint.getShader() || paint.getColorFilter()) { | 157 if (paint.getShader() || paint.getColorFilter()) { |
158 return NULL; | 158 return nullptr; |
159 } | 159 } |
160 | 160 |
161 SkXfermode::Mode mode; | 161 SkXfermode::Mode mode; |
162 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) { | 162 if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) { |
163 return NULL; | 163 return nullptr; |
164 } | 164 } |
165 | 165 |
166 SkColor color = paint.getColor(); | 166 SkColor color = paint.getColor(); |
167 | 167 |
168 // collaps modes based on color... | 168 // collaps modes based on color... |
169 if (SkXfermode::kSrcOver_Mode == mode) { | 169 if (SkXfermode::kSrcOver_Mode == mode) { |
170 unsigned alpha = SkColorGetA(color); | 170 unsigned alpha = SkColorGetA(color); |
171 if (0 == alpha) { | 171 if (0 == alpha) { |
172 mode = SkXfermode::kDst_Mode; | 172 mode = SkXfermode::kDst_Mode; |
173 } else if (0xFF == alpha) { | 173 } else if (0xFF == alpha) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // SkDebugf("--- DA8_Src_BitmapXferProc\n"); | 207 // SkDebugf("--- DA8_Src_BitmapXferProc\n"); |
208 return DA8_Src_BitmapXferProc; | 208 return DA8_Src_BitmapXferProc; |
209 default: | 209 default: |
210 break; | 210 break; |
211 } | 211 } |
212 break; | 212 break; |
213 } | 213 } |
214 default: | 214 default: |
215 break; | 215 break; |
216 } | 216 } |
217 return NULL; | 217 return nullptr; |
218 } | 218 } |
219 | 219 |
220 static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapX
ferProc proc, | 220 static void CallBitmapXferProc(const SkPixmap& dst, const SkIRect& rect, BitmapX
ferProc proc, |
221 uint32_t procData) { | 221 uint32_t procData) { |
222 int shiftPerPixel; | 222 int shiftPerPixel; |
223 switch (dst.colorType()) { | 223 switch (dst.colorType()) { |
224 case kN32_SkColorType: | 224 case kN32_SkColorType: |
225 shiftPerPixel = 2; | 225 shiftPerPixel = 2; |
226 break; | 226 break; |
227 case kRGB_565_SkColorType: | 227 case kRGB_565_SkColorType: |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 return false; | 444 return false; |
445 } | 445 } |
446 | 446 |
447 if (paint.getPathEffect()) { | 447 if (paint.getPathEffect()) { |
448 return false; | 448 return false; |
449 } | 449 } |
450 SkScalar width = paint.getStrokeWidth(); | 450 SkScalar width = paint.getStrokeWidth(); |
451 if (0 == width) { | 451 if (0 == width) { |
452 fMode = mode; | 452 fMode = mode; |
453 fPaint = &paint; | 453 fPaint = &paint; |
454 fClip = NULL; | 454 fClip = nullptr; |
455 fRC = rc; | 455 fRC = rc; |
456 fRadius = SK_FixedHalf; | 456 fRadius = SK_FixedHalf; |
457 return true; | 457 return true; |
458 } | 458 } |
459 if (paint.getStrokeCap() != SkPaint::kRound_Cap && | 459 if (paint.getStrokeCap() != SkPaint::kRound_Cap && |
460 matrix->isScaleTranslate() && SkCanvas::kPoints_PointMode == mode) { | 460 matrix->isScaleTranslate() && SkCanvas::kPoints_PointMode == mode) { |
461 SkScalar sx = matrix->get(SkMatrix::kMScaleX); | 461 SkScalar sx = matrix->get(SkMatrix::kMScaleX); |
462 SkScalar sy = matrix->get(SkMatrix::kMScaleY); | 462 SkScalar sy = matrix->get(SkMatrix::kMScaleY); |
463 if (SkScalarNearlyZero(sx - sy)) { | 463 if (SkScalarNearlyZero(sx - sy)) { |
464 if (sx < 0) { | 464 if (sx < 0) { |
465 sx = -sx; | 465 sx = -sx; |
466 } | 466 } |
467 | 467 |
468 fMode = mode; | 468 fMode = mode; |
469 fPaint = &paint; | 469 fPaint = &paint; |
470 fClip = NULL; | 470 fClip = nullptr; |
471 fRC = rc; | 471 fRC = rc; |
472 fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; | 472 fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; |
473 return true; | 473 return true; |
474 } | 474 } |
475 } | 475 } |
476 return false; | 476 return false; |
477 } | 477 } |
478 | 478 |
479 PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) { | 479 PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) { |
480 Proc proc = NULL; | 480 Proc proc = nullptr; |
481 | 481 |
482 SkBlitter* blitter = *blitterPtr; | 482 SkBlitter* blitter = *blitterPtr; |
483 if (fRC->isBW()) { | 483 if (fRC->isBW()) { |
484 fClip = &fRC->bwRgn(); | 484 fClip = &fRC->bwRgn(); |
485 } else { | 485 } else { |
486 fWrapper.init(*fRC, blitter); | 486 fWrapper.init(*fRC, blitter); |
487 fClip = &fWrapper.getRgn(); | 487 fClip = &fWrapper.getRgn(); |
488 blitter = fWrapper.getBlitter(); | 488 blitter = fWrapper.getBlitter(); |
489 *blitterPtr = blitter; | 489 *blitterPtr = blitter; |
490 } | 490 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 bool forceUseDevice) const { | 539 bool forceUseDevice) const { |
540 // if we're in lines mode, force count to be even | 540 // if we're in lines mode, force count to be even |
541 if (SkCanvas::kLines_PointMode == mode) { | 541 if (SkCanvas::kLines_PointMode == mode) { |
542 count &= ~(size_t)1; | 542 count &= ~(size_t)1; |
543 } | 543 } |
544 | 544 |
545 if ((long)count <= 0) { | 545 if ((long)count <= 0) { |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 SkASSERT(pts != NULL); | 549 SkASSERT(pts != nullptr); |
550 SkDEBUGCODE(this->validate();) | 550 SkDEBUGCODE(this->validate();) |
551 | 551 |
552 // nothing to draw | 552 // nothing to draw |
553 if (fRC->isEmpty()) { | 553 if (fRC->isEmpty()) { |
554 return; | 554 return; |
555 } | 555 } |
556 | 556 |
557 PtProcRec rec; | 557 PtProcRec rec; |
558 if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { | 558 if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { |
559 SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); | 559 SkAutoBlitterChoose blitter(fDst, *fMatrix, paint); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 path.moveTo(pts[0]); | 635 path.moveTo(pts[0]); |
636 path.lineTo(pts[1]); | 636 path.lineTo(pts[1]); |
637 | 637 |
638 SkRect cullRect = SkRect::Make(fRC->getBounds()); | 638 SkRect cullRect = SkRect::Make(fRC->getBounds()); |
639 | 639 |
640 if (paint.getPathEffect()->asPoints(&pointData, path, rec, | 640 if (paint.getPathEffect()->asPoints(&pointData, path, rec, |
641 *fMatrix, &cullRect)) { | 641 *fMatrix, &cullRect)) { |
642 // 'asPoints' managed to find some fast path | 642 // 'asPoints' managed to find some fast path |
643 | 643 |
644 SkPaint newP(paint); | 644 SkPaint newP(paint); |
645 newP.setPathEffect(NULL); | 645 newP.setPathEffect(nullptr); |
646 newP.setStyle(SkPaint::kFill_Style); | 646 newP.setStyle(SkPaint::kFill_Style); |
647 | 647 |
648 if (!pointData.fFirst.isEmpty()) { | 648 if (!pointData.fFirst.isEmpty()) { |
649 if (fDevice) { | 649 if (fDevice) { |
650 fDevice->drawPath(*this, pointData.fFirst, newP)
; | 650 fDevice->drawPath(*this, pointData.fFirst, newP)
; |
651 } else { | 651 } else { |
652 this->drawPath(pointData.fFirst, newP); | 652 this->drawPath(pointData.fFirst, newP); |
653 } | 653 } |
654 } | 654 } |
655 | 655 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 count -= 1; | 713 count -= 1; |
714 SkPath path; | 714 SkPath path; |
715 SkPaint p(paint); | 715 SkPaint p(paint); |
716 p.setStyle(SkPaint::kStroke_Style); | 716 p.setStyle(SkPaint::kStroke_Style); |
717 size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; | 717 size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; |
718 path.setIsVolatile(true); | 718 path.setIsVolatile(true); |
719 for (size_t i = 0; i < count; i += inc) { | 719 for (size_t i = 0; i < count; i += inc) { |
720 path.moveTo(pts[i]); | 720 path.moveTo(pts[i]); |
721 path.lineTo(pts[i+1]); | 721 path.lineTo(pts[i+1]); |
722 if (fDevice) { | 722 if (fDevice) { |
723 fDevice->drawPath(*this, path, p, NULL, true); | 723 fDevice->drawPath(*this, path, p, nullptr, true); |
724 } else { | 724 } else { |
725 this->drawPath(path, p, NULL, true); | 725 this->drawPath(path, p, nullptr, true); |
726 } | 726 } |
727 path.rewind(); | 727 path.rewind(); |
728 } | 728 } |
729 break; | 729 break; |
730 } | 730 } |
731 } | 731 } |
732 } | 732 } |
733 } | 733 } |
734 | 734 |
735 static inline SkPoint compute_stroke_size(const SkPaint& paint, const SkMatrix&
matrix) { | 735 static inline SkPoint compute_stroke_size(const SkPaint& paint, const SkMatrix&
matrix) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); | 813 RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); |
814 | 814 |
815 if (kPath_RectType == rtype) { | 815 if (kPath_RectType == rtype) { |
816 SkDraw draw(*this); | 816 SkDraw draw(*this); |
817 if (paintMatrix) { | 817 if (paintMatrix) { |
818 draw.fMatrix = matrix; | 818 draw.fMatrix = matrix; |
819 } | 819 } |
820 SkPath tmp; | 820 SkPath tmp; |
821 tmp.addRect(prePaintRect); | 821 tmp.addRect(prePaintRect); |
822 tmp.setFillType(SkPath::kWinding_FillType); | 822 tmp.setFillType(SkPath::kWinding_FillType); |
823 draw.drawPath(tmp, paint, NULL, true); | 823 draw.drawPath(tmp, paint, nullptr, true); |
824 return; | 824 return; |
825 } | 825 } |
826 | 826 |
827 SkRect devRect; | 827 SkRect devRect; |
828 const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect; | 828 const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect; |
829 // skip the paintMatrix when transforming the rect by the CTM | 829 // skip the paintMatrix when transforming the rect by the CTM |
830 fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2); | 830 fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2); |
831 devRect.sort(); | 831 devRect.sort(); |
832 | 832 |
833 // look for the quick exit, before we build a blitter | 833 // look for the quick exit, before we build a blitter |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 | 894 |
895 void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { | 895 void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { |
896 if (srcM.fBounds.isEmpty()) { | 896 if (srcM.fBounds.isEmpty()) { |
897 return; | 897 return; |
898 } | 898 } |
899 | 899 |
900 const SkMask* mask = &srcM; | 900 const SkMask* mask = &srcM; |
901 | 901 |
902 SkMask dstM; | 902 SkMask dstM; |
903 if (paint.getMaskFilter() && | 903 if (paint.getMaskFilter() && |
904 paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { | 904 paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, nullptr)) { |
905 mask = &dstM; | 905 mask = &dstM; |
906 } else { | 906 } else { |
907 dstM.fImage = NULL; | 907 dstM.fImage = nullptr; |
908 } | 908 } |
909 SkAutoMaskFreeImage ami(dstM.fImage); | 909 SkAutoMaskFreeImage ami(dstM.fImage); |
910 | 910 |
911 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); | 911 SkAutoBlitterChoose blitterChooser(fDst, *fMatrix, paint); |
912 SkBlitter* blitter = blitterChooser.get(); | 912 SkBlitter* blitter = blitterChooser.get(); |
913 | 913 |
914 SkAAClipBlitterWrapper wrapper; | 914 SkAAClipBlitterWrapper wrapper; |
915 const SkRegion* clipRgn; | 915 const SkRegion* clipRgn; |
916 | 916 |
917 if (fRC->isBW()) { | 917 if (fRC->isBW()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 SkPaint::kFill_Style)) { | 991 SkPaint::kFill_Style)) { |
992 return; // filterRRect() called the blitter, so we're done | 992 return; // filterRRect() called the blitter, so we're done |
993 } | 993 } |
994 } | 994 } |
995 } | 995 } |
996 | 996 |
997 DRAW_PATH: | 997 DRAW_PATH: |
998 // Now fall back to the default case of using a path. | 998 // Now fall back to the default case of using a path. |
999 SkPath path; | 999 SkPath path; |
1000 path.addRRect(rrect); | 1000 path.addRRect(rrect); |
1001 this->drawPath(path, paint, NULL, true); | 1001 this->drawPath(path, paint, nullptr, true); |
1002 } | 1002 } |
1003 | 1003 |
1004 static SkScalar compute_res_scale_for_stroking(const SkMatrix& matrix) { | 1004 static SkScalar compute_res_scale_for_stroking(const SkMatrix& matrix) { |
1005 if (!matrix.hasPerspective()) { | 1005 if (!matrix.hasPerspective()) { |
1006 SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatri
x::kMSkewY]); | 1006 SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatri
x::kMSkewY]); |
1007 SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatri
x::kMScaleY]); | 1007 SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatri
x::kMScaleY]); |
1008 if (SkScalarsAreFinite(sx, sy)) { | 1008 if (SkScalarsAreFinite(sx, sy)) { |
1009 return SkTMax(sx, sy); | 1009 return SkTMax(sx, sy); |
1010 } | 1010 } |
1011 } | 1011 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1069 #endif | 1069 #endif |
1070 SkPaint* writablePaint = paint.writable(); | 1070 SkPaint* writablePaint = paint.writable(); |
1071 writablePaint->setStrokeWidth(0); | 1071 writablePaint->setStrokeWidth(0); |
1072 writablePaint->setAlpha(newAlpha); | 1072 writablePaint->setAlpha(newAlpha); |
1073 } | 1073 } |
1074 } | 1074 } |
1075 } | 1075 } |
1076 | 1076 |
1077 if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { | 1077 if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { |
1078 SkRect cullRect; | 1078 SkRect cullRect; |
1079 const SkRect* cullRectPtr = NULL; | 1079 const SkRect* cullRectPtr = nullptr; |
1080 if (this->computeConservativeLocalClipBounds(&cullRect)) { | 1080 if (this->computeConservativeLocalClipBounds(&cullRect)) { |
1081 cullRectPtr = &cullRect; | 1081 cullRectPtr = &cullRect; |
1082 } | 1082 } |
1083 doFill = paint->getFillPath(*pathPtr, &tmpPath, cullRectPtr, | 1083 doFill = paint->getFillPath(*pathPtr, &tmpPath, cullRectPtr, |
1084 compute_res_scale_for_stroking(*fMatrix)); | 1084 compute_res_scale_for_stroking(*fMatrix)); |
1085 pathPtr = &tmpPath; | 1085 pathPtr = &tmpPath; |
1086 } | 1086 } |
1087 | 1087 |
1088 if (paint->getRasterizer()) { | 1088 if (paint->getRasterizer()) { |
1089 SkMask mask; | 1089 SkMask mask; |
1090 if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, | 1090 if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, |
1091 &fRC->getBounds(), paint->getMaskFilter(), &mask, | 1091 &fRC->getBounds(), paint->getMaskFilter(), &mask, |
1092 SkMask::kComputeBoundsAndRenderImage_CreateMode)) { | 1092 SkMask::kComputeBoundsAndRenderImage_CreateMode)) { |
1093 this->drawDevMask(mask, *paint); | 1093 this->drawDevMask(mask, *paint); |
1094 SkMask::FreeImage(mask.fImage); | 1094 SkMask::FreeImage(mask.fImage); |
1095 } | 1095 } |
1096 return; | 1096 return; |
1097 } | 1097 } |
1098 | 1098 |
1099 // avoid possibly allocating a new path in transform if we can | 1099 // avoid possibly allocating a new path in transform if we can |
1100 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; | 1100 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; |
1101 | 1101 |
1102 // transform the path into device space | 1102 // transform the path into device space |
1103 pathPtr->transform(*matrix, devPathPtr); | 1103 pathPtr->transform(*matrix, devPathPtr); |
1104 | 1104 |
1105 SkBlitter* blitter = NULL; | 1105 SkBlitter* blitter = nullptr; |
1106 SkAutoBlitterChoose blitterStorage; | 1106 SkAutoBlitterChoose blitterStorage; |
1107 if (NULL == customBlitter) { | 1107 if (nullptr == customBlitter) { |
1108 blitterStorage.choose(fDst, *fMatrix, *paint, drawCoverage); | 1108 blitterStorage.choose(fDst, *fMatrix, *paint, drawCoverage); |
1109 blitter = blitterStorage.get(); | 1109 blitter = blitterStorage.get(); |
1110 } else { | 1110 } else { |
1111 blitter = customBlitter; | 1111 blitter = customBlitter; |
1112 } | 1112 } |
1113 | 1113 |
1114 if (paint->getMaskFilter()) { | 1114 if (paint->getMaskFilter()) { |
1115 SkPaint::Style style = doFill ? SkPaint::kFill_Style : | 1115 SkPaint::Style style = doFill ? SkPaint::kFill_Style : |
1116 SkPaint::kStroke_Style; | 1116 SkPaint::kStroke_Style; |
1117 if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blit
ter, style)) { | 1117 if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blit
ter, style)) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 | 1326 |
1327 SkPaint paint(origPaint); | 1327 SkPaint paint(origPaint); |
1328 paint.setStyle(SkPaint::kFill_Style); | 1328 paint.setStyle(SkPaint::kFill_Style); |
1329 | 1329 |
1330 SkAutoPixmapUnlock unlocker; | 1330 SkAutoPixmapUnlock unlocker; |
1331 if (!bitmap.requestLock(&unlocker)) { | 1331 if (!bitmap.requestLock(&unlocker)) { |
1332 return; | 1332 return; |
1333 } | 1333 } |
1334 const SkPixmap& pmap = unlocker.pixmap(); | 1334 const SkPixmap& pmap = unlocker.pixmap(); |
1335 | 1335 |
1336 if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) { | 1336 if (nullptr == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)
) { |
1337 SkTBlitterAllocator allocator; | 1337 SkTBlitterAllocator allocator; |
1338 // blitter will be owned by the allocator. | 1338 // blitter will be owned by the allocator. |
1339 SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, paint, pmap, x, y, &a
llocator); | 1339 SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, paint, pmap, x, y, &a
llocator); |
1340 if (blitter) { | 1340 if (blitter) { |
1341 SkScan::FillIRect(bounds, *fRC, blitter); | 1341 SkScan::FillIRect(bounds, *fRC, blitter); |
1342 return; | 1342 return; |
1343 } | 1343 } |
1344 } | 1344 } |
1345 | 1345 |
1346 SkMatrix matrix; | 1346 SkMatrix matrix; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 (fx >> 16) < INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/) || | 1446 (fx >> 16) < INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/) || |
1447 (fy >> 16) > INT_MAX - (INT16_MAX + UINT16_MAX) || | 1447 (fy >> 16) > INT_MAX - (INT16_MAX + UINT16_MAX) || |
1448 (fy >> 16) < INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)) | 1448 (fy >> 16) < INT_MIN - (INT16_MIN + 0 /*UINT16_MIN*/)) |
1449 { | 1449 { |
1450 return; | 1450 return; |
1451 } | 1451 } |
1452 | 1452 |
1453 int left = Sk48Dot16FloorToInt(fx); | 1453 int left = Sk48Dot16FloorToInt(fx); |
1454 int top = Sk48Dot16FloorToInt(fy); | 1454 int top = Sk48Dot16FloorToInt(fy); |
1455 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); | 1455 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
1456 SkASSERT((NULL == state.fClip && state.fAAClip) || | 1456 SkASSERT((nullptr == state.fClip && state.fAAClip) || |
1457 (state.fClip && NULL == state.fAAClip && state.fClip->isRect())); | 1457 (state.fClip && nullptr == state.fAAClip && state.fClip->isRect()))
; |
1458 | 1458 |
1459 left += glyph.fLeft; | 1459 left += glyph.fLeft; |
1460 top += glyph.fTop; | 1460 top += glyph.fTop; |
1461 | 1461 |
1462 int right = left + glyph.fWidth; | 1462 int right = left + glyph.fWidth; |
1463 int bottom = top + glyph.fHeight; | 1463 int bottom = top + glyph.fHeight; |
1464 | 1464 |
1465 SkMask mask; | 1465 SkMask mask; |
1466 SkIRect storage; | 1466 SkIRect storage; |
1467 SkIRect* bounds = &mask.fBounds; | 1467 SkIRect* bounds = &mask.fBounds; |
1468 | 1468 |
1469 mask.fBounds.set(left, top, right, bottom); | 1469 mask.fBounds.set(left, top, right, bottom); |
1470 | 1470 |
1471 // this extra test is worth it, assuming that most of the time it succeeds | 1471 // this extra test is worth it, assuming that most of the time it succeeds |
1472 // since we can avoid writing to storage | 1472 // since we can avoid writing to storage |
1473 if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { | 1473 if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { |
1474 if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) | 1474 if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) |
1475 return; | 1475 return; |
1476 bounds = &storage; | 1476 bounds = &storage; |
1477 } | 1477 } |
1478 | 1478 |
1479 uint8_t* aa = (uint8_t*)glyph.fImage; | 1479 uint8_t* aa = (uint8_t*)glyph.fImage; |
1480 if (NULL == aa) { | 1480 if (nullptr == aa) { |
1481 aa = (uint8_t*)state.fCache->findImage(glyph); | 1481 aa = (uint8_t*)state.fCache->findImage(glyph); |
1482 if (NULL == aa) { | 1482 if (nullptr == aa) { |
1483 return; // can't rasterize glyph | 1483 return; // can't rasterize glyph |
1484 } | 1484 } |
1485 } | 1485 } |
1486 | 1486 |
1487 mask.fRowBytes = glyph.rowBytes(); | 1487 mask.fRowBytes = glyph.rowBytes(); |
1488 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 1488 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
1489 mask.fImage = aa; | 1489 mask.fImage = aa; |
1490 state.blitMask(mask, *bounds); | 1490 state.blitMask(mask, *bounds); |
1491 } | 1491 } |
1492 | 1492 |
1493 static void D1G_RgnClip(const SkDraw1Glyph& state, Sk48Dot16 fx, Sk48Dot16 fy, c
onst SkGlyph& glyph) { | 1493 static void D1G_RgnClip(const SkDraw1Glyph& state, Sk48Dot16 fx, Sk48Dot16 fy, c
onst SkGlyph& glyph) { |
1494 int left = Sk48Dot16FloorToInt(fx); | 1494 int left = Sk48Dot16FloorToInt(fx); |
1495 int top = Sk48Dot16FloorToInt(fy); | 1495 int top = Sk48Dot16FloorToInt(fy); |
1496 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); | 1496 SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
1497 SkASSERT(!state.fClip->isRect()); | 1497 SkASSERT(!state.fClip->isRect()); |
1498 | 1498 |
1499 SkMask mask; | 1499 SkMask mask; |
1500 | 1500 |
1501 left += glyph.fLeft; | 1501 left += glyph.fLeft; |
1502 top += glyph.fTop; | 1502 top += glyph.fTop; |
1503 | 1503 |
1504 mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); | 1504 mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); |
1505 SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); | 1505 SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); |
1506 | 1506 |
1507 if (!clipper.done()) { | 1507 if (!clipper.done()) { |
1508 const SkIRect& cr = clipper.rect(); | 1508 const SkIRect& cr = clipper.rect(); |
1509 const uint8_t* aa = (const uint8_t*)glyph.fImage; | 1509 const uint8_t* aa = (const uint8_t*)glyph.fImage; |
1510 if (NULL == aa) { | 1510 if (nullptr == aa) { |
1511 aa = (uint8_t*)state.fCache->findImage(glyph); | 1511 aa = (uint8_t*)state.fCache->findImage(glyph); |
1512 if (NULL == aa) { | 1512 if (nullptr == aa) { |
1513 return; | 1513 return; |
1514 } | 1514 } |
1515 } | 1515 } |
1516 | 1516 |
1517 mask.fRowBytes = glyph.rowBytes(); | 1517 mask.fRowBytes = glyph.rowBytes(); |
1518 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); | 1518 mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
1519 mask.fImage = (uint8_t*)aa; | 1519 mask.fImage = (uint8_t*)aa; |
1520 do { | 1520 do { |
1521 state.blitMask(mask, cr); | 1521 state.blitMask(mask, cr); |
1522 clipper.next(); | 1522 clipper.next(); |
(...skipping 23 matching lines...) Expand all Loading... |
1546 } | 1546 } |
1547 | 1547 |
1548 if (hasCustomD1GProc(*draw)) { | 1548 if (hasCustomD1GProc(*draw)) { |
1549 // todo: fix this assumption about clips w/ custom | 1549 // todo: fix this assumption about clips w/ custom |
1550 fClip = draw->fClip; | 1550 fClip = draw->fClip; |
1551 fClipBounds = fClip->getBounds(); | 1551 fClipBounds = fClip->getBounds(); |
1552 return draw->fProcs->fD1GProc; | 1552 return draw->fProcs->fD1GProc; |
1553 } | 1553 } |
1554 | 1554 |
1555 if (draw->fRC->isBW()) { | 1555 if (draw->fRC->isBW()) { |
1556 fAAClip = NULL; | 1556 fAAClip = nullptr; |
1557 fClip = &draw->fRC->bwRgn(); | 1557 fClip = &draw->fRC->bwRgn(); |
1558 fClipBounds = fClip->getBounds(); | 1558 fClipBounds = fClip->getBounds(); |
1559 if (fClip->isRect()) { | 1559 if (fClip->isRect()) { |
1560 return D1G_RectClip; | 1560 return D1G_RectClip; |
1561 } else { | 1561 } else { |
1562 return D1G_RgnClip; | 1562 return D1G_RgnClip; |
1563 } | 1563 } |
1564 } else { // aaclip | 1564 } else { // aaclip |
1565 fAAClip = &draw->fRC->aaRgn(); | 1565 fAAClip = &draw->fRC->aaRgn(); |
1566 fClip = NULL; | 1566 fClip = nullptr; |
1567 fClipBounds = fAAClip->getBounds(); | 1567 fClipBounds = fAAClip->getBounds(); |
1568 return D1G_RectClip; | 1568 return D1G_RectClip; |
1569 } | 1569 } |
1570 } | 1570 } |
1571 | 1571 |
1572 void SkDraw1Glyph::blitMaskAsSprite(const SkMask& mask) const { | 1572 void SkDraw1Glyph::blitMaskAsSprite(const SkMask& mask) const { |
1573 SkASSERT(SkMask::kARGB32_Format == mask.fFormat); | 1573 SkASSERT(SkMask::kARGB32_Format == mask.fFormat); |
1574 | 1574 |
1575 SkBitmap bm; | 1575 SkBitmap bm; |
1576 bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.width(), mask.fBoun
ds.height()), | 1576 bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.width(), mask.fBoun
ds.height()), |
1577 (SkPMColor*)mask.fImage, mask.fRowBytes); | 1577 (SkPMColor*)mask.fImage, mask.fRowBytes); |
1578 | 1578 |
1579 fDraw->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), *fPaint); | 1579 fDraw->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), *fPaint); |
1580 } | 1580 } |
1581 | 1581 |
1582 /////////////////////////////////////////////////////////////////////////////// | 1582 /////////////////////////////////////////////////////////////////////////////// |
1583 | 1583 |
1584 void SkDraw::drawText(const char text[], size_t byteLength, | 1584 void SkDraw::drawText(const char text[], size_t byteLength, |
1585 SkScalar x, SkScalar y, const SkPaint& paint) const { | 1585 SkScalar x, SkScalar y, const SkPaint& paint) const { |
1586 SkASSERT(byteLength == 0 || text != NULL); | 1586 SkASSERT(byteLength == 0 || text != nullptr); |
1587 | 1587 |
1588 SkDEBUGCODE(this->validate();) | 1588 SkDEBUGCODE(this->validate();) |
1589 | 1589 |
1590 // nothing to draw | 1590 // nothing to draw |
1591 if (text == NULL || byteLength == 0 || fRC->isEmpty()) { | 1591 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { |
1592 return; | 1592 return; |
1593 } | 1593 } |
1594 | 1594 |
1595 // SkScalarRec doesn't currently have a way of representing hairline stroke
and | 1595 // SkScalarRec doesn't currently have a way of representing hairline stroke
and |
1596 // will fill if its frame-width is 0. | 1596 // will fill if its frame-width is 0. |
1597 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { | 1597 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
1598 this->drawText_asPaths(text, byteLength, x, y, paint); | 1598 this->drawText_asPaths(text, byteLength, x, y, paint); |
1599 return; | 1599 return; |
1600 } | 1600 } |
1601 | 1601 |
(...skipping 24 matching lines...) Expand all Loading... |
1626 stopY = SkScalarHalf(stopY); | 1626 stopY = SkScalarHalf(stopY); |
1627 } | 1627 } |
1628 x -= stopX; | 1628 x -= stopX; |
1629 y -= stopY; | 1629 y -= stopY; |
1630 } | 1630 } |
1631 | 1631 |
1632 const char* stop = text + byteLength; | 1632 const char* stop = text + byteLength; |
1633 | 1633 |
1634 SkAAClipBlitter aaBlitter; | 1634 SkAAClipBlitter aaBlitter; |
1635 SkAutoBlitterChoose blitterChooser; | 1635 SkAutoBlitterChoose blitterChooser; |
1636 SkBlitter* blitter = NULL; | 1636 SkBlitter* blitter = nullptr; |
1637 if (needsRasterTextBlit(*this)) { | 1637 if (needsRasterTextBlit(*this)) { |
1638 blitterChooser.choose(fDst, *fMatrix, paint); | 1638 blitterChooser.choose(fDst, *fMatrix, paint); |
1639 blitter = blitterChooser.get(); | 1639 blitter = blitterChooser.get(); |
1640 if (fRC->isAA()) { | 1640 if (fRC->isAA()) { |
1641 aaBlitter.init(blitter, &fRC->aaRgn()); | 1641 aaBlitter.init(blitter, &fRC->aaRgn()); |
1642 blitter = &aaBlitter; | 1642 blitter = &aaBlitter; |
1643 } | 1643 } |
1644 } | 1644 } |
1645 | 1645 |
1646 SkAutoKern autokern; | 1646 SkAutoKern autokern; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 const SkPoint& offset, const SkPaint& origPaint
) const { | 1684 const SkPoint& offset, const SkPaint& origPaint
) const { |
1685 // setup our std paint, in hopes of getting hits in the cache | 1685 // setup our std paint, in hopes of getting hits in the cache |
1686 SkPaint paint(origPaint); | 1686 SkPaint paint(origPaint); |
1687 SkScalar matrixScale = paint.setupForAsPaths(); | 1687 SkScalar matrixScale = paint.setupForAsPaths(); |
1688 | 1688 |
1689 SkMatrix matrix; | 1689 SkMatrix matrix; |
1690 matrix.setScale(matrixScale, matrixScale); | 1690 matrix.setScale(matrixScale, matrixScale); |
1691 | 1691 |
1692 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. | 1692 // Temporarily jam in kFill, so we only ever ask for the raw outline from th
e cache. |
1693 paint.setStyle(SkPaint::kFill_Style); | 1693 paint.setStyle(SkPaint::kFill_Style); |
1694 paint.setPathEffect(NULL); | 1694 paint.setPathEffect(nullptr); |
1695 | 1695 |
1696 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); | 1696 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
1697 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), NULL); | 1697 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), nullptr); |
1698 SkGlyphCache* cache = autoCache.getCache(); | 1698 SkGlyphCache* cache = autoCache.getCache(); |
1699 | 1699 |
1700 const char* stop = text + byteLength; | 1700 const char* stop = text + byteLength; |
1701 SkTextAlignProc alignProc(paint.getTextAlign()); | 1701 SkTextAlignProc alignProc(paint.getTextAlign()); |
1702 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); | 1702 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
1703 | 1703 |
1704 // Now restore the original settings, so we "draw" with whatever style/strok
ing. | 1704 // Now restore the original settings, so we "draw" with whatever style/strok
ing. |
1705 paint.setStyle(origPaint.getStyle()); | 1705 paint.setStyle(origPaint.getStyle()); |
1706 paint.setPathEffect(origPaint.getPathEffect()); | 1706 paint.setPathEffect(origPaint.getPathEffect()); |
1707 | 1707 |
(...skipping 16 matching lines...) Expand all Loading... |
1724 } | 1724 } |
1725 } | 1725 } |
1726 } | 1726 } |
1727 pos += scalarsPerPosition; | 1727 pos += scalarsPerPosition; |
1728 } | 1728 } |
1729 } | 1729 } |
1730 | 1730 |
1731 void SkDraw::drawPosText(const char text[], size_t byteLength, | 1731 void SkDraw::drawPosText(const char text[], size_t byteLength, |
1732 const SkScalar pos[], int scalarsPerPosition, | 1732 const SkScalar pos[], int scalarsPerPosition, |
1733 const SkPoint& offset, const SkPaint& paint) const { | 1733 const SkPoint& offset, const SkPaint& paint) const { |
1734 SkASSERT(byteLength == 0 || text != NULL); | 1734 SkASSERT(byteLength == 0 || text != nullptr); |
1735 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 1735 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
1736 | 1736 |
1737 SkDEBUGCODE(this->validate();) | 1737 SkDEBUGCODE(this->validate();) |
1738 | 1738 |
1739 // nothing to draw | 1739 // nothing to draw |
1740 if (text == NULL || byteLength == 0 || fRC->isEmpty()) { | 1740 if (text == nullptr || byteLength == 0 || fRC->isEmpty()) { |
1741 return; | 1741 return; |
1742 } | 1742 } |
1743 | 1743 |
1744 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { | 1744 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
1745 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off
set, paint); | 1745 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off
set, paint); |
1746 return; | 1746 return; |
1747 } | 1747 } |
1748 | 1748 |
1749 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); | 1749 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
1750 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), fMatrix); | 1750 SkAutoGlyphCache autoCache(paint, &fDevice->surfaceProps(), fMatrix); |
1751 SkGlyphCache* cache = autoCache.getCache(); | 1751 SkGlyphCache* cache = autoCache.getCache(); |
1752 | 1752 |
1753 SkAAClipBlitterWrapper wrapper; | 1753 SkAAClipBlitterWrapper wrapper; |
1754 SkAutoBlitterChoose blitterChooser; | 1754 SkAutoBlitterChoose blitterChooser; |
1755 SkBlitter* blitter = NULL; | 1755 SkBlitter* blitter = nullptr; |
1756 if (needsRasterTextBlit(*this)) { | 1756 if (needsRasterTextBlit(*this)) { |
1757 blitterChooser.choose(fDst, *fMatrix, paint); | 1757 blitterChooser.choose(fDst, *fMatrix, paint); |
1758 blitter = blitterChooser.get(); | 1758 blitter = blitterChooser.get(); |
1759 if (fRC->isAA()) { | 1759 if (fRC->isAA()) { |
1760 wrapper.init(*fRC, blitter); | 1760 wrapper.init(*fRC, blitter); |
1761 blitter = wrapper.getBlitter(); | 1761 blitter = wrapper.getBlitter(); |
1762 } | 1762 } |
1763 } | 1763 } |
1764 | 1764 |
1765 const char* stop = text + byteLength; | 1765 const char* stop = text + byteLength; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 private: | 1908 private: |
1909 SkMatrix fDstToUnit; | 1909 SkMatrix fDstToUnit; |
1910 SkPMColor fColors[3]; | 1910 SkPMColor fColors[3]; |
1911 | 1911 |
1912 typedef SkShader::Context INHERITED; | 1912 typedef SkShader::Context INHERITED; |
1913 }; | 1913 }; |
1914 | 1914 |
1915 SK_TO_STRING_OVERRIDE() | 1915 SK_TO_STRING_OVERRIDE() |
1916 | 1916 |
1917 // For serialization. This will never be called. | 1917 // For serialization. This will never be called. |
1918 Factory getFactory() const override { sk_throw(); return NULL; } | 1918 Factory getFactory() const override { sk_throw(); return nullptr; } |
1919 | 1919 |
1920 protected: | 1920 protected: |
1921 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid
e { | 1921 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid
e { |
1922 return new (storage) TriColorShaderContext(*this, rec); | 1922 return new (storage) TriColorShaderContext(*this, rec); |
1923 } | 1923 } |
1924 | 1924 |
1925 private: | 1925 private: |
1926 typedef SkShader INHERITED; | 1926 typedef SkShader INHERITED; |
1927 }; | 1927 }; |
1928 | 1928 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 - just texture (has shader/texture[], no colors[]) | 2046 - just texture (has shader/texture[], no colors[]) |
2047 - colors * texture (has shader/texture[], has colors[]) | 2047 - colors * texture (has shader/texture[], has colors[]) |
2048 | 2048 |
2049 Thus for texture drawing, we need both texture[] and a shader. | 2049 Thus for texture drawing, we need both texture[] and a shader. |
2050 */ | 2050 */ |
2051 | 2051 |
2052 SkTriColorShader triShader; // must be above declaration of p | 2052 SkTriColorShader triShader; // must be above declaration of p |
2053 SkPaint p(paint); | 2053 SkPaint p(paint); |
2054 | 2054 |
2055 SkShader* shader = p.getShader(); | 2055 SkShader* shader = p.getShader(); |
2056 if (NULL == shader) { | 2056 if (nullptr == shader) { |
2057 // if we have no shader, we ignore the texture coordinates | 2057 // if we have no shader, we ignore the texture coordinates |
2058 textures = NULL; | 2058 textures = nullptr; |
2059 } else if (NULL == textures) { | 2059 } else if (nullptr == textures) { |
2060 // if we don't have texture coordinates, ignore the shader | 2060 // if we don't have texture coordinates, ignore the shader |
2061 p.setShader(NULL); | 2061 p.setShader(nullptr); |
2062 shader = NULL; | 2062 shader = nullptr; |
2063 } | 2063 } |
2064 | 2064 |
2065 // setup the custom shader (if needed) | 2065 // setup the custom shader (if needed) |
2066 SkAutoTUnref<SkComposeShader> composeShader; | 2066 SkAutoTUnref<SkComposeShader> composeShader; |
2067 if (colors) { | 2067 if (colors) { |
2068 if (NULL == textures) { | 2068 if (nullptr == textures) { |
2069 // just colors (no texture) | 2069 // just colors (no texture) |
2070 shader = p.setShader(&triShader); | 2070 shader = p.setShader(&triShader); |
2071 } else { | 2071 } else { |
2072 // colors * texture | 2072 // colors * texture |
2073 SkASSERT(shader); | 2073 SkASSERT(shader); |
2074 bool releaseMode = false; | 2074 bool releaseMode = false; |
2075 if (NULL == xmode) { | 2075 if (nullptr == xmode) { |
2076 xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); | 2076 xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); |
2077 releaseMode = true; | 2077 releaseMode = true; |
2078 } | 2078 } |
2079 composeShader.reset(new SkComposeShader(&triShader, shader, xmode)); | 2079 composeShader.reset(new SkComposeShader(&triShader, shader, xmode)); |
2080 p.setShader(composeShader); | 2080 p.setShader(composeShader); |
2081 if (releaseMode) { | 2081 if (releaseMode) { |
2082 xmode->unref(); | 2082 xmode->unref(); |
2083 } | 2083 } |
2084 } | 2084 } |
2085 } | 2085 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 } | 2148 } |
2149 } | 2149 } |
2150 } | 2150 } |
2151 | 2151 |
2152 /////////////////////////////////////////////////////////////////////////////// | 2152 /////////////////////////////////////////////////////////////////////////////// |
2153 /////////////////////////////////////////////////////////////////////////////// | 2153 /////////////////////////////////////////////////////////////////////////////// |
2154 | 2154 |
2155 #ifdef SK_DEBUG | 2155 #ifdef SK_DEBUG |
2156 | 2156 |
2157 void SkDraw::validate() const { | 2157 void SkDraw::validate() const { |
2158 SkASSERT(fMatrix != NULL); | 2158 SkASSERT(fMatrix != nullptr); |
2159 SkASSERT(fClip != NULL); | 2159 SkASSERT(fClip != nullptr); |
2160 SkASSERT(fRC != NULL); | 2160 SkASSERT(fRC != nullptr); |
2161 | 2161 |
2162 const SkIRect& cr = fRC->getBounds(); | 2162 const SkIRect& cr = fRC->getBounds(); |
2163 SkIRect br; | 2163 SkIRect br; |
2164 | 2164 |
2165 br.set(0, 0, fDst.width(), fDst.height()); | 2165 br.set(0, 0, fDst.width(), fDst.height()); |
2166 SkASSERT(cr.isEmpty() || br.contains(cr)); | 2166 SkASSERT(cr.isEmpty() || br.contains(cr)); |
2167 } | 2167 } |
2168 | 2168 |
2169 #endif | 2169 #endif |
2170 | 2170 |
(...skipping 15 matching lines...) Expand all Loading... |
2186 *bounds = devPath.getBounds().makeOutset(SK_ScalarHalf, SK_ScalarHalf).round
Out(); | 2186 *bounds = devPath.getBounds().makeOutset(SK_ScalarHalf, SK_ScalarHalf).round
Out(); |
2187 | 2187 |
2188 SkIPoint margin = SkIPoint::Make(0, 0); | 2188 SkIPoint margin = SkIPoint::Make(0, 0); |
2189 if (filter) { | 2189 if (filter) { |
2190 SkASSERT(filterMatrix); | 2190 SkASSERT(filterMatrix); |
2191 | 2191 |
2192 SkMask srcM, dstM; | 2192 SkMask srcM, dstM; |
2193 | 2193 |
2194 srcM.fBounds = *bounds; | 2194 srcM.fBounds = *bounds; |
2195 srcM.fFormat = SkMask::kA8_Format; | 2195 srcM.fFormat = SkMask::kA8_Format; |
2196 srcM.fImage = NULL; | 2196 srcM.fImage = nullptr; |
2197 if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { | 2197 if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { |
2198 return false; | 2198 return false; |
2199 } | 2199 } |
2200 } | 2200 } |
2201 | 2201 |
2202 // (possibly) trim the bounds to reflect the clip | 2202 // (possibly) trim the bounds to reflect the clip |
2203 // (plus whatever slop the filter needs) | 2203 // (plus whatever slop the filter needs) |
2204 if (clipBounds) { | 2204 if (clipBounds) { |
2205 // Ugh. Guard against gigantic margins from wacky filters. Without this | 2205 // Ugh. Guard against gigantic margins from wacky filters. Without this |
2206 // check we can request arbitrary amounts of slop beyond our visible | 2206 // check we can request arbitrary amounts of slop beyond our visible |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2260 mask->fImage = SkMask::AllocImage(size); | 2260 mask->fImage = SkMask::AllocImage(size); |
2261 memset(mask->fImage, 0, mask->computeImageSize()); | 2261 memset(mask->fImage, 0, mask->computeImageSize()); |
2262 } | 2262 } |
2263 | 2263 |
2264 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2264 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2265 draw_into_mask(*mask, devPath, style); | 2265 draw_into_mask(*mask, devPath, style); |
2266 } | 2266 } |
2267 | 2267 |
2268 return true; | 2268 return true; |
2269 } | 2269 } |
OLD | NEW |