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 998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 if (!matrix.hasPerspective()) { | 1009 if (!matrix.hasPerspective()) { |
1010 SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatri
x::kMSkewY]); | 1010 SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatri
x::kMSkewY]); |
1011 SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatri
x::kMScaleY]); | 1011 SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatri
x::kMScaleY]); |
1012 if (SkScalarsAreFinite(sx, sy)) { | 1012 if (SkScalarsAreFinite(sx, sy)) { |
1013 return SkTMax(sx, sy); | 1013 return SkTMax(sx, sy); |
1014 } | 1014 } |
1015 } | 1015 } |
1016 return 1; | 1016 return 1; |
1017 } | 1017 } |
1018 | 1018 |
| 1019 void SkDraw::drawDevPath(const SkPath& devPath, const SkPaint& paint, bool drawC
overage, |
| 1020 SkBlitter* customBlitter, bool doFill) const { |
| 1021 SkBlitter* blitter = nullptr; |
| 1022 SkAutoBlitterChoose blitterStorage; |
| 1023 if (nullptr == customBlitter) { |
| 1024 blitterStorage.choose(fDst, *fMatrix, paint, drawCoverage); |
| 1025 blitter = blitterStorage.get(); |
| 1026 } else { |
| 1027 blitter = customBlitter; |
| 1028 } |
| 1029 |
| 1030 if (paint.getMaskFilter()) { |
| 1031 SkStrokeRec::InitStyle style = doFill ? SkStrokeRec::kFill_InitStyle |
| 1032 : SkStrokeRec::kHairline_InitStyle; |
| 1033 if (paint.getMaskFilter()->filterPath(devPath, *fMatrix, *fRC, blitter,
style)) { |
| 1034 return; // filterPath() called the blitter, so we're done |
| 1035 } |
| 1036 } |
| 1037 |
| 1038 void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); |
| 1039 if (doFill) { |
| 1040 if (paint.isAntiAlias()) { |
| 1041 proc = SkScan::AntiFillPath; |
| 1042 } else { |
| 1043 proc = SkScan::FillPath; |
| 1044 } |
| 1045 } else { // hairline |
| 1046 if (paint.isAntiAlias()) { |
| 1047 switch (paint.getStrokeCap()) { |
| 1048 case SkPaint::kButt_Cap: |
| 1049 proc = SkScan::AntiHairPath; |
| 1050 break; |
| 1051 case SkPaint::kSquare_Cap: |
| 1052 proc = SkScan::AntiHairSquarePath; |
| 1053 break; |
| 1054 case SkPaint::kRound_Cap: |
| 1055 proc = SkScan::AntiHairRoundPath; |
| 1056 break; |
| 1057 default: |
| 1058 proc SK_INIT_TO_AVOID_WARNING; |
| 1059 SkDEBUGFAIL("unknown paint cap type"); |
| 1060 } |
| 1061 } else { |
| 1062 switch (paint.getStrokeCap()) { |
| 1063 case SkPaint::kButt_Cap: |
| 1064 proc = SkScan::HairPath; |
| 1065 break; |
| 1066 case SkPaint::kSquare_Cap: |
| 1067 proc = SkScan::HairSquarePath; |
| 1068 break; |
| 1069 case SkPaint::kRound_Cap: |
| 1070 proc = SkScan::HairRoundPath; |
| 1071 break; |
| 1072 default: |
| 1073 proc SK_INIT_TO_AVOID_WARNING; |
| 1074 SkDEBUGFAIL("unknown paint cap type"); |
| 1075 } |
| 1076 } |
| 1077 } |
| 1078 proc(devPath, *fRC, blitter); |
| 1079 } |
| 1080 |
1019 void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, | 1081 void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, |
1020 const SkMatrix* prePathMatrix, bool pathIsMutable, | 1082 const SkMatrix* prePathMatrix, bool pathIsMutable, |
1021 bool drawCoverage, SkBlitter* customBlitter) const { | 1083 bool drawCoverage, SkBlitter* customBlitter) const { |
1022 SkDEBUGCODE(this->validate();) | 1084 SkDEBUGCODE(this->validate();) |
1023 | 1085 |
1024 // nothing to draw | 1086 // nothing to draw |
1025 if (fRC->isEmpty()) { | 1087 if (fRC->isEmpty()) { |
1026 return; | 1088 return; |
1027 } | 1089 } |
1028 | 1090 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 } | 1161 } |
1100 return; | 1162 return; |
1101 } | 1163 } |
1102 | 1164 |
1103 // avoid possibly allocating a new path in transform if we can | 1165 // avoid possibly allocating a new path in transform if we can |
1104 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; | 1166 SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; |
1105 | 1167 |
1106 // transform the path into device space | 1168 // transform the path into device space |
1107 pathPtr->transform(*matrix, devPathPtr); | 1169 pathPtr->transform(*matrix, devPathPtr); |
1108 | 1170 |
1109 SkBlitter* blitter = nullptr; | 1171 this->drawDevPath(*devPathPtr, *paint, drawCoverage, customBlitter, doFill); |
1110 SkAutoBlitterChoose blitterStorage; | |
1111 if (nullptr == customBlitter) { | |
1112 blitterStorage.choose(fDst, *fMatrix, *paint, drawCoverage); | |
1113 blitter = blitterStorage.get(); | |
1114 } else { | |
1115 blitter = customBlitter; | |
1116 } | |
1117 | |
1118 if (paint->getMaskFilter()) { | |
1119 SkStrokeRec::InitStyle style = doFill ? SkStrokeRec::kFill_InitStyle | |
1120 : SkStrokeRec::kHairline_InitStyle
; | |
1121 if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blit
ter, style)) { | |
1122 return; // filterPath() called the blitter, so we're done | |
1123 } | |
1124 } | |
1125 | |
1126 void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); | |
1127 if (doFill) { | |
1128 if (paint->isAntiAlias()) { | |
1129 proc = SkScan::AntiFillPath; | |
1130 } else { | |
1131 proc = SkScan::FillPath; | |
1132 } | |
1133 } else { // hairline | |
1134 if (paint->isAntiAlias()) { | |
1135 switch (paint->getStrokeCap()) { | |
1136 case SkPaint::kButt_Cap: | |
1137 proc = SkScan::AntiHairPath; | |
1138 break; | |
1139 case SkPaint::kSquare_Cap: | |
1140 proc = SkScan::AntiHairSquarePath; | |
1141 break; | |
1142 case SkPaint::kRound_Cap: | |
1143 proc = SkScan::AntiHairRoundPath; | |
1144 break; | |
1145 default: | |
1146 proc SK_INIT_TO_AVOID_WARNING; | |
1147 SkDEBUGFAIL("unknown paint cap type"); | |
1148 } | |
1149 } else { | |
1150 switch (paint->getStrokeCap()) { | |
1151 case SkPaint::kButt_Cap: | |
1152 proc = SkScan::HairPath; | |
1153 break; | |
1154 case SkPaint::kSquare_Cap: | |
1155 proc = SkScan::HairSquarePath; | |
1156 break; | |
1157 case SkPaint::kRound_Cap: | |
1158 proc = SkScan::HairRoundPath; | |
1159 break; | |
1160 default: | |
1161 proc SK_INIT_TO_AVOID_WARNING; | |
1162 SkDEBUGFAIL("unknown paint cap type"); | |
1163 } | |
1164 } | |
1165 } | |
1166 proc(*devPathPtr, *fRC, blitter); | |
1167 } | 1172 } |
1168 | 1173 |
1169 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, | 1174 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, const SkPaint& paint) cons
t { |
1170 const SkPaint& paint) const { | |
1171 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); | 1175 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); |
1172 | 1176 |
1173 if (SkTreatAsSprite(*fMatrix, bitmap.dimensions(), paint)) { | 1177 if (SkTreatAsSprite(*fMatrix, bitmap.dimensions(), paint)) { |
1174 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); | 1178 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); |
1175 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); | 1179 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); |
1176 | 1180 |
1177 SkAutoPixmapUnlock result; | 1181 SkAutoPixmapUnlock result; |
1178 if (!bitmap.requestLock(&result)) { | 1182 if (!bitmap.requestLock(&result)) { |
1179 return; | 1183 return; |
1180 } | 1184 } |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 mask->fImage = SkMask::AllocImage(size); | 2079 mask->fImage = SkMask::AllocImage(size); |
2076 memset(mask->fImage, 0, mask->computeImageSize()); | 2080 memset(mask->fImage, 0, mask->computeImageSize()); |
2077 } | 2081 } |
2078 | 2082 |
2079 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2083 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2080 draw_into_mask(*mask, devPath, style); | 2084 draw_into_mask(*mask, devPath, style); |
2081 } | 2085 } |
2082 | 2086 |
2083 return true; | 2087 return true; |
2084 } | 2088 } |
OLD | NEW |