| 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 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 SkDEBUGFAIL("unknown paint cap type"); | 1165 SkDEBUGFAIL("unknown paint cap type"); |
| 1166 } | 1166 } |
| 1167 #ifdef SK_SUPPORT_LEGACY_HAIR_IGNORES_CAPS | 1167 #ifdef SK_SUPPORT_LEGACY_HAIR_IGNORES_CAPS |
| 1168 proc = SkScan::HairPath; | 1168 proc = SkScan::HairPath; |
| 1169 #endif | 1169 #endif |
| 1170 } | 1170 } |
| 1171 } | 1171 } |
| 1172 proc(*devPathPtr, *fRC, blitter); | 1172 proc(*devPathPtr, *fRC, blitter); |
| 1173 } | 1173 } |
| 1174 | 1174 |
| 1175 /** For the purposes of drawing bitmaps, if a matrix is "almost" translate | |
| 1176 go ahead and treat it as if it were, so that subsequent code can go fast. | |
| 1177 */ | |
| 1178 static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { | |
| 1179 unsigned bits = 0; // TODO: find a way to allow the caller to tell us to | |
| 1180 // respect filtering. | |
| 1181 return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits); | |
| 1182 } | |
| 1183 | |
| 1184 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, | 1175 void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, |
| 1185 const SkPaint& paint) const { | 1176 const SkPaint& paint) const { |
| 1186 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); | 1177 SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); |
| 1187 | 1178 |
| 1188 if (just_translate(*fMatrix, bitmap)) { | 1179 if (SkTreatAsSprite(*fMatrix, bitmap.dimensions(), paint)) { |
| 1189 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); | 1180 int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); |
| 1190 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); | 1181 int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); |
| 1191 | 1182 |
| 1192 SkAutoPixmapUnlock result; | 1183 SkAutoPixmapUnlock result; |
| 1193 if (!bitmap.requestLock(&result)) { | 1184 if (!bitmap.requestLock(&result)) { |
| 1194 return; | 1185 return; |
| 1195 } | 1186 } |
| 1196 const SkPixmap& pmap = result.pixmap(); | 1187 const SkPixmap& pmap = result.pixmap(); |
| 1197 SkMask mask; | 1188 SkMask mask; |
| 1198 mask.fBounds.set(ix, iy, ix + pmap.width(), iy + pmap.height()); | 1189 mask.fBounds.set(ix, iy, ix + pmap.width(), iy + pmap.height()); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1293 SkPaint paint(origPaint); | 1284 SkPaint paint(origPaint); |
| 1294 paint.setStyle(SkPaint::kFill_Style); | 1285 paint.setStyle(SkPaint::kFill_Style); |
| 1295 | 1286 |
| 1296 SkMatrix matrix; | 1287 SkMatrix matrix; |
| 1297 matrix.setConcat(*fMatrix, prematrix); | 1288 matrix.setConcat(*fMatrix, prematrix); |
| 1298 | 1289 |
| 1299 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { | 1290 if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { |
| 1300 return; | 1291 return; |
| 1301 } | 1292 } |
| 1302 | 1293 |
| 1303 if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bit
map)) { | 1294 if (bitmap.colorType() != kAlpha_8_SkColorType |
| 1295 && SkTreatAsSprite(matrix, bitmap.dimensions(), paint)) { |
| 1304 // | 1296 // |
| 1305 // It is safe to call lock pixels now, since we know the matrix is | 1297 // It is safe to call lock pixels now, since we know the matrix is |
| 1306 // (more or less) identity. | 1298 // (more or less) identity. |
| 1307 // | 1299 // |
| 1308 SkAutoPixmapUnlock unlocker; | 1300 SkAutoPixmapUnlock unlocker; |
| 1309 if (!bitmap.requestLock(&unlocker)) { | 1301 if (!bitmap.requestLock(&unlocker)) { |
| 1310 return; | 1302 return; |
| 1311 } | 1303 } |
| 1312 const SkPixmap& pmap = unlocker.pixmap(); | 1304 const SkPixmap& pmap = unlocker.pixmap(); |
| 1313 int ix = SkScalarRoundToInt(matrix.getTranslateX()); | 1305 int ix = SkScalarRoundToInt(matrix.getTranslateX()); |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2076 mask->fImage = SkMask::AllocImage(size); | 2068 mask->fImage = SkMask::AllocImage(size); |
| 2077 memset(mask->fImage, 0, mask->computeImageSize()); | 2069 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2078 } | 2070 } |
| 2079 | 2071 |
| 2080 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2072 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2081 draw_into_mask(*mask, devPath, style); | 2073 draw_into_mask(*mask, devPath, style); |
| 2082 } | 2074 } |
| 2083 | 2075 |
| 2084 return true; | 2076 return true; |
| 2085 } | 2077 } |
| OLD | NEW |