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 | 7 |
8 #include "SkDraw.h" | 8 #include "SkDraw.h" |
9 #include "SkBlitter.h" | 9 #include "SkBlitter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 } else { | 1100 } else { |
1101 proc = SkScan::HairPath; | 1101 proc = SkScan::HairPath; |
1102 } | 1102 } |
1103 } | 1103 } |
1104 proc(*devPathPtr, *fRC, blitter.get()); | 1104 proc(*devPathPtr, *fRC, blitter.get()); |
1105 } | 1105 } |
1106 | 1106 |
1107 /** For the purposes of drawing bitmaps, if a matrix is "almost" translate | 1107 /** For the purposes of drawing bitmaps, if a matrix is "almost" translate |
1108 go ahead and treat it as if it were, so that subsequent code can go fast. | 1108 go ahead and treat it as if it were, so that subsequent code can go fast. |
1109 */ | 1109 */ |
1110 static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { | 1110 static bool just_translate(const SkMatrix& ctm, const SkBitmap& bm, SkPaint::Fil
terLevel filter) { |
1111 unsigned bits = 0; // TODO: find a way to allow the caller to tell us to | 1111 unsigned bits = 0; |
1112 // respect filtering. | 1112 switch (filter) { |
1113 return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits); | 1113 case SkPaint::kNone_FilterLevel: |
| 1114 bits = 0; |
| 1115 break; |
| 1116 case SkPaint::kLow_FilterLevel: |
| 1117 case SkPaint::kMedium_FilterLevel: |
| 1118 bits = 4; |
| 1119 break; |
| 1120 case SkPaint::kHigh_FilterLevel: |
| 1121 bits = 4; |
| 1122 break; |
| 1123 } |
| 1124 return SkTreatAsSprite(ctm, bm.width(), bm.height(), bits); |
1114 } | 1125 } |
1115 | 1126 |
1116 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, | 1127 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, |
1117 const SkPaint& paint) const { | 1128 const SkPaint& paint) const { |
1118 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); | 1129 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); |
1119 | 1130 |
1120 if (just_translate(*fMatrix, bitmap)) { | 1131 if (just_translate(*fMatrix, bitmap, paint.getFilterLevel())) { |
1121 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); | 1132 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); |
1122 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); | 1133 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); |
1123 | 1134 |
1124 SkAutoLockPixels alp(bitmap); | 1135 SkAutoLockPixels alp(bitmap); |
1125 if (!bitmap.readyToDraw()) { | 1136 if (!bitmap.readyToDraw()) { |
1126 return; | 1137 return; |
1127 } | 1138 } |
1128 | 1139 |
1129 SkMask mask; | 1140 SkMask mask; |
1130 mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); | 1141 mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 SkPaint paint(origPaint); | 1240 SkPaint paint(origPaint); |
1230 paint.setStyle(SkPaint::kFill_Style); | 1241 paint.setStyle(SkPaint::kFill_Style); |
1231 | 1242 |
1232 SkMatrix matrix; | 1243 SkMatrix matrix; |
1233 matrix.setConcat(*fMatrix, prematrix); | 1244 matrix.setConcat(*fMatrix, prematrix); |
1234 | 1245 |
1235 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { | 1246 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { |
1236 return; | 1247 return; |
1237 } | 1248 } |
1238 | 1249 |
1239 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bit
map)) { | 1250 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bit
map, |
| 1251 paint.getFi
lterLevel())) { |
1240 // | 1252 // |
1241 // It is safe to call lock pixels now, since we know the matrix is | 1253 // It is safe to call lock pixels now, since we know the matrix is |
1242 // (more or less) identity. | 1254 // (more or less) identity. |
1243 // | 1255 // |
1244 SkAutoLockPixels alp(bitmap); | 1256 SkAutoLockPixels alp(bitmap); |
1245 if (!bitmap.readyToDraw()) { | 1257 if (!bitmap.readyToDraw()) { |
1246 return; | 1258 return; |
1247 } | 1259 } |
1248 int ix = SkScalarRoundToInt(matrix.getTranslateX()); | 1260 int ix = SkScalarRoundToInt(matrix.getTranslateX()); |
1249 int iy = SkScalarRoundToInt(matrix.getTranslateY()); | 1261 int iy = SkScalarRoundToInt(matrix.getTranslateY()); |
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2477 mask->fImage = SkMask::AllocImage(size); | 2489 mask->fImage = SkMask::AllocImage(size); |
2478 memset(mask->fImage, 0, mask->computeImageSize()); | 2490 memset(mask->fImage, 0, mask->computeImageSize()); |
2479 } | 2491 } |
2480 | 2492 |
2481 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2493 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
2482 draw_into_mask(*mask, devPath, style); | 2494 draw_into_mask(*mask, devPath, style); |
2483 } | 2495 } |
2484 | 2496 |
2485 return true; | 2497 return true; |
2486 } | 2498 } |
OLD | NEW |