OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 GEN_ID_INC; | 418 GEN_ID_INC; |
419 | 419 |
420 bool isNoDraw = annotation && annotation->isNoDraw(); | 420 bool isNoDraw = annotation && annotation->isNoDraw(); |
421 fPrivFlags = SkSetClearMask(fPrivFlags, isNoDraw, kNoDrawAnnotation_PrivFlag
); | 421 fPrivFlags = SkSetClearMask(fPrivFlags, isNoDraw, kNoDrawAnnotation_PrivFlag
); |
422 | 422 |
423 return annotation; | 423 return annotation; |
424 } | 424 } |
425 | 425 |
426 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
427 | 427 |
| 428 static SkScalar mag2(SkScalar x, SkScalar y) { |
| 429 return x * x + y * y; |
| 430 } |
| 431 |
| 432 static bool tooBig(const SkMatrix& m, SkScalar ma2max) { |
| 433 return mag2(m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY]) > ma2max |
| 434 || |
| 435 mag2(m[SkMatrix::kMSkewX], m[SkMatrix::kMScaleY]) > ma2max; |
| 436 } |
| 437 |
| 438 bool SkPaint::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM) { |
| 439 SkASSERT(!ctm.hasPerspective()); |
| 440 SkASSERT(!textM.hasPerspective()); |
| 441 |
| 442 SkMatrix matrix; |
| 443 matrix.setConcat(ctm, textM); |
| 444 return tooBig(matrix, MaxCacheSize2()); |
| 445 } |
| 446 |
| 447 bool SkPaint::tooBigToUseCache(const SkMatrix& ctm) const { |
| 448 SkMatrix textM; |
| 449 return TooBigToUseCache(ctm, *this->setTextMatrix(&textM)); |
| 450 } |
| 451 |
| 452 bool SkPaint::tooBigToUseCache() const { |
| 453 SkMatrix textM; |
| 454 return tooBig(*this->setTextMatrix(&textM), MaxCacheSize2()); |
| 455 } |
| 456 |
| 457 /////////////////////////////////////////////////////////////////////////////// |
| 458 |
428 #include "SkGlyphCache.h" | 459 #include "SkGlyphCache.h" |
429 #include "SkUtils.h" | 460 #include "SkUtils.h" |
430 | 461 |
431 static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc, | 462 static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc, |
432 void* context) { | 463 void* context) { |
433 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); | 464 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); |
434 } | 465 } |
435 | 466 |
436 #ifdef SK_BUILD_FOR_ANDROID | 467 #ifdef SK_BUILD_FOR_ANDROID |
437 const SkGlyph& SkPaint::getUnicharMetrics(SkUnichar text, | 468 const SkGlyph& SkPaint::getUnicharMetrics(SkUnichar text, |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 } | 1096 } |
1066 | 1097 |
1067 SkScalar SkPaint::measureText(const void* textData, size_t length, | 1098 SkScalar SkPaint::measureText(const void* textData, size_t length, |
1068 SkRect* bounds, SkScalar zoom) const { | 1099 SkRect* bounds, SkScalar zoom) const { |
1069 const char* text = (const char*)textData; | 1100 const char* text = (const char*)textData; |
1070 SkASSERT(text != NULL || length == 0); | 1101 SkASSERT(text != NULL || length == 0); |
1071 | 1102 |
1072 SkScalar scale = 0; | 1103 SkScalar scale = 0; |
1073 SkAutoRestorePaintTextSizeAndFrame restore(this); | 1104 SkAutoRestorePaintTextSizeAndFrame restore(this); |
1074 | 1105 |
1075 if (this->isLinearText()) { | 1106 if (this->isLinearText() || this->tooBigToUseCache()) { |
1076 scale = fTextSize / kCanonicalTextSizeForPaths; | 1107 scale = fTextSize / kCanonicalTextSizeForPaths; |
1077 // this gets restored by restore | 1108 // this gets restored by restore |
1078 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths))
; | 1109 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths))
; |
1079 } | 1110 } |
1080 | 1111 |
1081 SkMatrix zoomMatrix, *zoomPtr = NULL; | 1112 SkMatrix zoomMatrix, *zoomPtr = NULL; |
1082 if (zoom) { | 1113 if (zoom) { |
1083 zoomMatrix.setScale(zoom, zoom); | 1114 zoomMatrix.setScale(zoom, zoom); |
1084 zoomPtr = &zoomMatrix; | 1115 zoomPtr = &zoomMatrix; |
1085 } | 1116 } |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 | 1311 |
1281 SkASSERT(NULL != textData); | 1312 SkASSERT(NULL != textData); |
1282 | 1313 |
1283 if (NULL == widths && NULL == bounds) { | 1314 if (NULL == widths && NULL == bounds) { |
1284 return this->countText(textData, byteLength); | 1315 return this->countText(textData, byteLength); |
1285 } | 1316 } |
1286 | 1317 |
1287 SkAutoRestorePaintTextSizeAndFrame restore(this); | 1318 SkAutoRestorePaintTextSizeAndFrame restore(this); |
1288 SkScalar scale = 0; | 1319 SkScalar scale = 0; |
1289 | 1320 |
1290 if (this->isLinearText()) { | 1321 if (this->isLinearText() || this->tooBigToUseCache()) { |
1291 scale = fTextSize / kCanonicalTextSizeForPaths; | 1322 scale = fTextSize / kCanonicalTextSizeForPaths; |
1292 // this gets restored by restore | 1323 // this gets restored by restore |
1293 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths))
; | 1324 ((SkPaint*)this)->setTextSize(SkIntToScalar(kCanonicalTextSizeForPaths))
; |
1294 } | 1325 } |
1295 | 1326 |
1296 SkAutoGlyphCache autoCache(*this, NULL, NULL); | 1327 SkAutoGlyphCache autoCache(*this, NULL, NULL); |
1297 SkGlyphCache* cache = autoCache.getCache(); | 1328 SkGlyphCache* cache = autoCache.getCache(); |
1298 SkMeasureCacheProc glyphCacheProc; | 1329 SkMeasureCacheProc glyphCacheProc; |
1299 glyphCacheProc = this->getMeasureCacheProc(kForward_TextBufferDirection, | 1330 glyphCacheProc = this->getMeasureCacheProc(kForward_TextBufferDirection, |
1300 NULL != bounds); | 1331 NULL != bounds); |
(...skipping 1248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2549 case SkXfermode::kPlus_Mode: | 2580 case SkXfermode::kPlus_Mode: |
2550 return 0 == this->getAlpha(); | 2581 return 0 == this->getAlpha(); |
2551 case SkXfermode::kDst_Mode: | 2582 case SkXfermode::kDst_Mode: |
2552 return true; | 2583 return true; |
2553 default: | 2584 default: |
2554 break; | 2585 break; |
2555 } | 2586 } |
2556 } | 2587 } |
2557 return false; | 2588 return false; |
2558 } | 2589 } |
OLD | NEW |