| 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 "SkPaint.h" | 8 #include "SkPaint.h" |
| 9 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
| 10 #include "SkAutoKern.h" | 10 #include "SkAutoKern.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "SkTLazy.h" | 33 #include "SkTLazy.h" |
| 34 #include "SkTypeface.h" | 34 #include "SkTypeface.h" |
| 35 #include "SkSurfacePriv.h" | 35 #include "SkSurfacePriv.h" |
| 36 #include "SkXfermode.h" | 36 #include "SkXfermode.h" |
| 37 | 37 |
| 38 // define this to get a printf for out-of-range parameter in setters | 38 // define this to get a printf for out-of-range parameter in setters |
| 39 // e.g. setTextSize(-1) | 39 // e.g. setTextSize(-1) |
| 40 //#define SK_REPORT_API_RANGE_CHECK | 40 //#define SK_REPORT_API_RANGE_CHECK |
| 41 | 41 |
| 42 SkPaint::SkPaint() { | 42 SkPaint::SkPaint() { |
| 43 fTypeface = NULL; | 43 fTypeface = nullptr; |
| 44 fPathEffect = NULL; | 44 fPathEffect = nullptr; |
| 45 fShader = NULL; | 45 fShader = nullptr; |
| 46 fXfermode = NULL; | 46 fXfermode = nullptr; |
| 47 fMaskFilter = NULL; | 47 fMaskFilter = nullptr; |
| 48 fColorFilter = NULL; | 48 fColorFilter = nullptr; |
| 49 fRasterizer = NULL; | 49 fRasterizer = nullptr; |
| 50 fLooper = NULL; | 50 fLooper = nullptr; |
| 51 fImageFilter = NULL; | 51 fImageFilter = nullptr; |
| 52 fAnnotation = NULL; | 52 fAnnotation = nullptr; |
| 53 | 53 |
| 54 fTextSize = SkPaintDefaults_TextSize; | 54 fTextSize = SkPaintDefaults_TextSize; |
| 55 fTextScaleX = SK_Scalar1; | 55 fTextScaleX = SK_Scalar1; |
| 56 fTextSkewX = 0; | 56 fTextSkewX = 0; |
| 57 fColor = SK_ColorBLACK; | 57 fColor = SK_ColorBLACK; |
| 58 fWidth = 0; | 58 fWidth = 0; |
| 59 fMiterLimit = SkPaintDefaults_MiterLimit; | 59 fMiterLimit = SkPaintDefaults_MiterLimit; |
| 60 | 60 |
| 61 // Zero all bitfields, then set some non-zero defaults. | 61 // Zero all bitfields, then set some non-zero defaults. |
| 62 fBitfieldsUInt = 0; | 62 fBitfieldsUInt = 0; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 void* context) { | 391 void* context) { |
| 392 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); | 392 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); |
| 393 } | 393 } |
| 394 | 394 |
| 395 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, | 395 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, |
| 396 uint16_t glyphs[]) const { | 396 uint16_t glyphs[]) const { |
| 397 if (byteLength == 0) { | 397 if (byteLength == 0) { |
| 398 return 0; | 398 return 0; |
| 399 } | 399 } |
| 400 | 400 |
| 401 SkASSERT(textData != NULL); | 401 SkASSERT(textData != nullptr); |
| 402 | 402 |
| 403 if (NULL == glyphs) { | 403 if (nullptr == glyphs) { |
| 404 switch (this->getTextEncoding()) { | 404 switch (this->getTextEncoding()) { |
| 405 case kUTF8_TextEncoding: | 405 case kUTF8_TextEncoding: |
| 406 return SkUTF8_CountUnichars((const char*)textData, byteLength); | 406 return SkUTF8_CountUnichars((const char*)textData, byteLength); |
| 407 case kUTF16_TextEncoding: | 407 case kUTF16_TextEncoding: |
| 408 return SkUTF16_CountUnichars((const uint16_t*)textData, SkToInt(byte
Length >> 1)); | 408 return SkUTF16_CountUnichars((const uint16_t*)textData, SkToInt(byte
Length >> 1)); |
| 409 case kUTF32_TextEncoding: | 409 case kUTF32_TextEncoding: |
| 410 return SkToInt(byteLength >> 2); | 410 return SkToInt(byteLength >> 2); |
| 411 case kGlyphID_TextEncoding: | 411 case kGlyphID_TextEncoding: |
| 412 return SkToInt(byteLength >> 1); | 412 return SkToInt(byteLength >> 1); |
| 413 default: | 413 default: |
| 414 SkDEBUGFAIL("unknown text encoding"); | 414 SkDEBUGFAIL("unknown text encoding"); |
| 415 } | 415 } |
| 416 return 0; | 416 return 0; |
| 417 } | 417 } |
| 418 | 418 |
| 419 // if we get here, we have a valid glyphs[] array, so time to fill it in | 419 // if we get here, we have a valid glyphs[] array, so time to fill it in |
| 420 | 420 |
| 421 // handle this encoding before the setup for the glyphcache | 421 // handle this encoding before the setup for the glyphcache |
| 422 if (this->getTextEncoding() == kGlyphID_TextEncoding) { | 422 if (this->getTextEncoding() == kGlyphID_TextEncoding) { |
| 423 // we want to ignore the low bit of byteLength | 423 // we want to ignore the low bit of byteLength |
| 424 memcpy(glyphs, textData, byteLength >> 1 << 1); | 424 memcpy(glyphs, textData, byteLength >> 1 << 1); |
| 425 return SkToInt(byteLength >> 1); | 425 return SkToInt(byteLength >> 1); |
| 426 } | 426 } |
| 427 | 427 |
| 428 SkAutoGlyphCache autoCache(*this, NULL, NULL); | 428 SkAutoGlyphCache autoCache(*this, nullptr, nullptr); |
| 429 SkGlyphCache* cache = autoCache.getCache(); | 429 SkGlyphCache* cache = autoCache.getCache(); |
| 430 | 430 |
| 431 const char* text = (const char*)textData; | 431 const char* text = (const char*)textData; |
| 432 const char* stop = text + byteLength; | 432 const char* stop = text + byteLength; |
| 433 uint16_t* gptr = glyphs; | 433 uint16_t* gptr = glyphs; |
| 434 | 434 |
| 435 switch (this->getTextEncoding()) { | 435 switch (this->getTextEncoding()) { |
| 436 case SkPaint::kUTF8_TextEncoding: | 436 case SkPaint::kUTF8_TextEncoding: |
| 437 while (text < stop) { | 437 while (text < stop) { |
| 438 *gptr++ = cache->unicharToGlyph(SkUTF8_NextUnichar(&text)); | 438 *gptr++ = cache->unicharToGlyph(SkUTF8_NextUnichar(&text)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 458 SkDEBUGFAIL("unknown text encoding"); | 458 SkDEBUGFAIL("unknown text encoding"); |
| 459 } | 459 } |
| 460 return SkToInt(gptr - glyphs); | 460 return SkToInt(gptr - glyphs); |
| 461 } | 461 } |
| 462 | 462 |
| 463 bool SkPaint::containsText(const void* textData, size_t byteLength) const { | 463 bool SkPaint::containsText(const void* textData, size_t byteLength) const { |
| 464 if (0 == byteLength) { | 464 if (0 == byteLength) { |
| 465 return true; | 465 return true; |
| 466 } | 466 } |
| 467 | 467 |
| 468 SkASSERT(textData != NULL); | 468 SkASSERT(textData != nullptr); |
| 469 | 469 |
| 470 // handle this encoding before the setup for the glyphcache | 470 // handle this encoding before the setup for the glyphcache |
| 471 if (this->getTextEncoding() == kGlyphID_TextEncoding) { | 471 if (this->getTextEncoding() == kGlyphID_TextEncoding) { |
| 472 const uint16_t* glyphID = static_cast<const uint16_t*>(textData); | 472 const uint16_t* glyphID = static_cast<const uint16_t*>(textData); |
| 473 size_t count = byteLength >> 1; | 473 size_t count = byteLength >> 1; |
| 474 for (size_t i = 0; i < count; i++) { | 474 for (size_t i = 0; i < count; i++) { |
| 475 if (0 == glyphID[i]) { | 475 if (0 == glyphID[i]) { |
| 476 return false; | 476 return false; |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 return true; | 479 return true; |
| 480 } | 480 } |
| 481 | 481 |
| 482 SkAutoGlyphCache autoCache(*this, NULL, NULL); | 482 SkAutoGlyphCache autoCache(*this, nullptr, nullptr); |
| 483 SkGlyphCache* cache = autoCache.getCache(); | 483 SkGlyphCache* cache = autoCache.getCache(); |
| 484 | 484 |
| 485 switch (this->getTextEncoding()) { | 485 switch (this->getTextEncoding()) { |
| 486 case SkPaint::kUTF8_TextEncoding: { | 486 case SkPaint::kUTF8_TextEncoding: { |
| 487 const char* text = static_cast<const char*>(textData); | 487 const char* text = static_cast<const char*>(textData); |
| 488 const char* stop = text + byteLength; | 488 const char* stop = text + byteLength; |
| 489 while (text < stop) { | 489 while (text < stop) { |
| 490 if (0 == cache->unicharToGlyph(SkUTF8_NextUnichar(&text))) { | 490 if (0 == cache->unicharToGlyph(SkUTF8_NextUnichar(&text))) { |
| 491 return false; | 491 return false; |
| 492 } | 492 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 518 return false; | 518 return false; |
| 519 } | 519 } |
| 520 return true; | 520 return true; |
| 521 } | 521 } |
| 522 | 522 |
| 523 void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex
tData[]) const { | 523 void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex
tData[]) const { |
| 524 if (count <= 0) { | 524 if (count <= 0) { |
| 525 return; | 525 return; |
| 526 } | 526 } |
| 527 | 527 |
| 528 SkASSERT(glyphs != NULL); | 528 SkASSERT(glyphs != nullptr); |
| 529 SkASSERT(textData != NULL); | 529 SkASSERT(textData != nullptr); |
| 530 | 530 |
| 531 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); | 531 SkSurfaceProps props(0, kUnknown_SkPixelGeometry); |
| 532 SkAutoGlyphCache autoCache(*this, &props, NULL); | 532 SkAutoGlyphCache autoCache(*this, &props, nullptr); |
| 533 SkGlyphCache* cache = autoCache.getCache(); | 533 SkGlyphCache* cache = autoCache.getCache(); |
| 534 | 534 |
| 535 for (int index = 0; index < count; index++) { | 535 for (int index = 0; index < count; index++) { |
| 536 textData[index] = cache->glyphToUnichar(glyphs[index]); | 536 textData[index] = cache->glyphToUnichar(glyphs[index]); |
| 537 } | 537 } |
| 538 } | 538 } |
| 539 | 539 |
| 540 /////////////////////////////////////////////////////////////////////////////// | 540 /////////////////////////////////////////////////////////////////////////////// |
| 541 | 541 |
| 542 static const SkGlyph& sk_getMetrics_utf8_next(SkGlyphCache* cache, | 542 static const SkGlyph& sk_getMetrics_utf8_next(SkGlyphCache* cache, |
| 543 const char** text) { | 543 const char** text) { |
| 544 SkASSERT(cache != NULL); | 544 SkASSERT(cache != nullptr); |
| 545 SkASSERT(text != NULL); | 545 SkASSERT(text != nullptr); |
| 546 | 546 |
| 547 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text)); | 547 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text)); |
| 548 } | 548 } |
| 549 | 549 |
| 550 static const SkGlyph& sk_getMetrics_utf16_next(SkGlyphCache* cache, | 550 static const SkGlyph& sk_getMetrics_utf16_next(SkGlyphCache* cache, |
| 551 const char** text) { | 551 const char** text) { |
| 552 SkASSERT(cache != NULL); | 552 SkASSERT(cache != nullptr); |
| 553 SkASSERT(text != NULL); | 553 SkASSERT(text != nullptr); |
| 554 | 554 |
| 555 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text))
; | 555 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text))
; |
| 556 } | 556 } |
| 557 | 557 |
| 558 static const SkGlyph& sk_getMetrics_utf32_next(SkGlyphCache* cache, | 558 static const SkGlyph& sk_getMetrics_utf32_next(SkGlyphCache* cache, |
| 559 const char** text) { | 559 const char** text) { |
| 560 SkASSERT(cache != NULL); | 560 SkASSERT(cache != nullptr); |
| 561 SkASSERT(text != NULL); | 561 SkASSERT(text != nullptr); |
| 562 | 562 |
| 563 const int32_t* ptr = *(const int32_t**)text; | 563 const int32_t* ptr = *(const int32_t**)text; |
| 564 SkUnichar uni = *ptr++; | 564 SkUnichar uni = *ptr++; |
| 565 *text = (const char*)ptr; | 565 *text = (const char*)ptr; |
| 566 return cache->getUnicharMetrics(uni); | 566 return cache->getUnicharMetrics(uni); |
| 567 } | 567 } |
| 568 | 568 |
| 569 static const SkGlyph& sk_getMetrics_glyph_next(SkGlyphCache* cache, | 569 static const SkGlyph& sk_getMetrics_glyph_next(SkGlyphCache* cache, |
| 570 const char** text) { | 570 const char** text) { |
| 571 SkASSERT(cache != NULL); | 571 SkASSERT(cache != nullptr); |
| 572 SkASSERT(text != NULL); | 572 SkASSERT(text != nullptr); |
| 573 | 573 |
| 574 const uint16_t* ptr = *(const uint16_t**)text; | 574 const uint16_t* ptr = *(const uint16_t**)text; |
| 575 unsigned glyphID = *ptr; | 575 unsigned glyphID = *ptr; |
| 576 ptr += 1; | 576 ptr += 1; |
| 577 *text = (const char*)ptr; | 577 *text = (const char*)ptr; |
| 578 return cache->getGlyphIDMetrics(glyphID); | 578 return cache->getGlyphIDMetrics(glyphID); |
| 579 } | 579 } |
| 580 | 580 |
| 581 static const SkGlyph& sk_getAdvance_utf8_next(SkGlyphCache* cache, | 581 static const SkGlyph& sk_getAdvance_utf8_next(SkGlyphCache* cache, |
| 582 const char** text) { | 582 const char** text) { |
| 583 SkASSERT(cache != NULL); | 583 SkASSERT(cache != nullptr); |
| 584 SkASSERT(text != NULL); | 584 SkASSERT(text != nullptr); |
| 585 | 585 |
| 586 return cache->getUnicharAdvance(SkUTF8_NextUnichar(text)); | 586 return cache->getUnicharAdvance(SkUTF8_NextUnichar(text)); |
| 587 } | 587 } |
| 588 | 588 |
| 589 static const SkGlyph& sk_getAdvance_utf16_next(SkGlyphCache* cache, | 589 static const SkGlyph& sk_getAdvance_utf16_next(SkGlyphCache* cache, |
| 590 const char** text) { | 590 const char** text) { |
| 591 SkASSERT(cache != NULL); | 591 SkASSERT(cache != nullptr); |
| 592 SkASSERT(text != NULL); | 592 SkASSERT(text != nullptr); |
| 593 | 593 |
| 594 return cache->getUnicharAdvance(SkUTF16_NextUnichar((const uint16_t**)text))
; | 594 return cache->getUnicharAdvance(SkUTF16_NextUnichar((const uint16_t**)text))
; |
| 595 } | 595 } |
| 596 | 596 |
| 597 static const SkGlyph& sk_getAdvance_utf32_next(SkGlyphCache* cache, | 597 static const SkGlyph& sk_getAdvance_utf32_next(SkGlyphCache* cache, |
| 598 const char** text) { | 598 const char** text) { |
| 599 SkASSERT(cache != NULL); | 599 SkASSERT(cache != nullptr); |
| 600 SkASSERT(text != NULL); | 600 SkASSERT(text != nullptr); |
| 601 | 601 |
| 602 const int32_t* ptr = *(const int32_t**)text; | 602 const int32_t* ptr = *(const int32_t**)text; |
| 603 SkUnichar uni = *ptr++; | 603 SkUnichar uni = *ptr++; |
| 604 *text = (const char*)ptr; | 604 *text = (const char*)ptr; |
| 605 return cache->getUnicharAdvance(uni); | 605 return cache->getUnicharAdvance(uni); |
| 606 } | 606 } |
| 607 | 607 |
| 608 static const SkGlyph& sk_getAdvance_glyph_next(SkGlyphCache* cache, | 608 static const SkGlyph& sk_getAdvance_glyph_next(SkGlyphCache* cache, |
| 609 const char** text) { | 609 const char** text) { |
| 610 SkASSERT(cache != NULL); | 610 SkASSERT(cache != nullptr); |
| 611 SkASSERT(text != NULL); | 611 SkASSERT(text != nullptr); |
| 612 | 612 |
| 613 const uint16_t* ptr = *(const uint16_t**)text; | 613 const uint16_t* ptr = *(const uint16_t**)text; |
| 614 unsigned glyphID = *ptr; | 614 unsigned glyphID = *ptr; |
| 615 ptr += 1; | 615 ptr += 1; |
| 616 *text = (const char*)ptr; | 616 *text = (const char*)ptr; |
| 617 return cache->getGlyphIDAdvance(glyphID); | 617 return cache->getGlyphIDAdvance(glyphID); |
| 618 } | 618 } |
| 619 | 619 |
| 620 SkMeasureCacheProc SkPaint::getMeasureCacheProc(bool needFullMetrics) const { | 620 SkMeasureCacheProc SkPaint::getMeasureCacheProc(bool needFullMetrics) const { |
| 621 static const SkMeasureCacheProc gMeasureCacheProcs[] = { | 621 static const SkMeasureCacheProc gMeasureCacheProcs[] = { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 637 } | 637 } |
| 638 | 638 |
| 639 SkASSERT(index < SK_ARRAY_COUNT(gMeasureCacheProcs)); | 639 SkASSERT(index < SK_ARRAY_COUNT(gMeasureCacheProcs)); |
| 640 return gMeasureCacheProcs[index]; | 640 return gMeasureCacheProcs[index]; |
| 641 } | 641 } |
| 642 | 642 |
| 643 /////////////////////////////////////////////////////////////////////////////// | 643 /////////////////////////////////////////////////////////////////////////////// |
| 644 | 644 |
| 645 static const SkGlyph& sk_getMetrics_utf8_00(SkGlyphCache* cache, | 645 static const SkGlyph& sk_getMetrics_utf8_00(SkGlyphCache* cache, |
| 646 const char** text, SkFixed, SkFixed) { | 646 const char** text, SkFixed, SkFixed) { |
| 647 SkASSERT(cache != NULL); | 647 SkASSERT(cache != nullptr); |
| 648 SkASSERT(text != NULL); | 648 SkASSERT(text != nullptr); |
| 649 | 649 |
| 650 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text)); | 650 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text)); |
| 651 } | 651 } |
| 652 | 652 |
| 653 static const SkGlyph& sk_getMetrics_utf8_xy(SkGlyphCache* cache, | 653 static const SkGlyph& sk_getMetrics_utf8_xy(SkGlyphCache* cache, |
| 654 const char** text, SkFixed x, SkFixed y) { | 654 const char** text, SkFixed x, SkFixed y) { |
| 655 SkASSERT(cache != NULL); | 655 SkASSERT(cache != nullptr); |
| 656 SkASSERT(text != NULL); | 656 SkASSERT(text != nullptr); |
| 657 | 657 |
| 658 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text), x, y); | 658 return cache->getUnicharMetrics(SkUTF8_NextUnichar(text), x, y); |
| 659 } | 659 } |
| 660 | 660 |
| 661 static const SkGlyph& sk_getMetrics_utf16_00(SkGlyphCache* cache, | 661 static const SkGlyph& sk_getMetrics_utf16_00(SkGlyphCache* cache, |
| 662 const char** text, SkFixed, SkFixed) { | 662 const char** text, SkFixed, SkFixed) { |
| 663 SkASSERT(cache != NULL); | 663 SkASSERT(cache != nullptr); |
| 664 SkASSERT(text != NULL); | 664 SkASSERT(text != nullptr); |
| 665 | 665 |
| 666 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text))
; | 666 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text))
; |
| 667 } | 667 } |
| 668 | 668 |
| 669 static const SkGlyph& sk_getMetrics_utf16_xy(SkGlyphCache* cache, | 669 static const SkGlyph& sk_getMetrics_utf16_xy(SkGlyphCache* cache, |
| 670 const char** text, SkFixed x, SkFixed y) { | 670 const char** text, SkFixed x, SkFixed y) { |
| 671 SkASSERT(cache != NULL); | 671 SkASSERT(cache != nullptr); |
| 672 SkASSERT(text != NULL); | 672 SkASSERT(text != nullptr); |
| 673 | 673 |
| 674 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text), | 674 return cache->getUnicharMetrics(SkUTF16_NextUnichar((const uint16_t**)text), |
| 675 x, y); | 675 x, y); |
| 676 } | 676 } |
| 677 | 677 |
| 678 static const SkGlyph& sk_getMetrics_utf32_00(SkGlyphCache* cache, | 678 static const SkGlyph& sk_getMetrics_utf32_00(SkGlyphCache* cache, |
| 679 const char** text, SkFixed, SkFixed) { | 679 const char** text, SkFixed, SkFixed) { |
| 680 SkASSERT(cache != NULL); | 680 SkASSERT(cache != nullptr); |
| 681 SkASSERT(text != NULL); | 681 SkASSERT(text != nullptr); |
| 682 | 682 |
| 683 const int32_t* ptr = *(const int32_t**)text; | 683 const int32_t* ptr = *(const int32_t**)text; |
| 684 SkUnichar uni = *ptr++; | 684 SkUnichar uni = *ptr++; |
| 685 *text = (const char*)ptr; | 685 *text = (const char*)ptr; |
| 686 return cache->getUnicharMetrics(uni); | 686 return cache->getUnicharMetrics(uni); |
| 687 } | 687 } |
| 688 | 688 |
| 689 static const SkGlyph& sk_getMetrics_utf32_xy(SkGlyphCache* cache, | 689 static const SkGlyph& sk_getMetrics_utf32_xy(SkGlyphCache* cache, |
| 690 const char** text, SkFixed x, SkFixed y) { | 690 const char** text, SkFixed x, SkFixed y) { |
| 691 SkASSERT(cache != NULL); | 691 SkASSERT(cache != nullptr); |
| 692 SkASSERT(text != NULL); | 692 SkASSERT(text != nullptr); |
| 693 | 693 |
| 694 const int32_t* ptr = *(const int32_t**)text; | 694 const int32_t* ptr = *(const int32_t**)text; |
| 695 SkUnichar uni = *ptr++; | 695 SkUnichar uni = *ptr++; |
| 696 *text = (const char*)ptr; | 696 *text = (const char*)ptr; |
| 697 return cache->getUnicharMetrics(uni, x, y); | 697 return cache->getUnicharMetrics(uni, x, y); |
| 698 } | 698 } |
| 699 | 699 |
| 700 static const SkGlyph& sk_getMetrics_glyph_00(SkGlyphCache* cache, | 700 static const SkGlyph& sk_getMetrics_glyph_00(SkGlyphCache* cache, |
| 701 const char** text, SkFixed, SkFixed) { | 701 const char** text, SkFixed, SkFixed) { |
| 702 SkASSERT(cache != NULL); | 702 SkASSERT(cache != nullptr); |
| 703 SkASSERT(text != NULL); | 703 SkASSERT(text != nullptr); |
| 704 | 704 |
| 705 const uint16_t* ptr = *(const uint16_t**)text; | 705 const uint16_t* ptr = *(const uint16_t**)text; |
| 706 unsigned glyphID = *ptr; | 706 unsigned glyphID = *ptr; |
| 707 ptr += 1; | 707 ptr += 1; |
| 708 *text = (const char*)ptr; | 708 *text = (const char*)ptr; |
| 709 return cache->getGlyphIDMetrics(glyphID); | 709 return cache->getGlyphIDMetrics(glyphID); |
| 710 } | 710 } |
| 711 | 711 |
| 712 static const SkGlyph& sk_getMetrics_glyph_xy(SkGlyphCache* cache, | 712 static const SkGlyph& sk_getMetrics_glyph_xy(SkGlyphCache* cache, |
| 713 const char** text, SkFixed x, SkFixed y) { | 713 const char** text, SkFixed x, SkFixed y) { |
| 714 SkASSERT(cache != NULL); | 714 SkASSERT(cache != nullptr); |
| 715 SkASSERT(text != NULL); | 715 SkASSERT(text != nullptr); |
| 716 | 716 |
| 717 const uint16_t* ptr = *(const uint16_t**)text; | 717 const uint16_t* ptr = *(const uint16_t**)text; |
| 718 unsigned glyphID = *ptr; | 718 unsigned glyphID = *ptr; |
| 719 ptr += 1; | 719 ptr += 1; |
| 720 *text = (const char*)ptr; | 720 *text = (const char*)ptr; |
| 721 return cache->getGlyphIDMetrics(glyphID, x, y); | 721 return cache->getGlyphIDMetrics(glyphID, x, y); |
| 722 } | 722 } |
| 723 | 723 |
| 724 SkDrawCacheProc SkPaint::getDrawCacheProc() const { | 724 SkDrawCacheProc SkPaint::getDrawCacheProc() const { |
| 725 static const SkDrawCacheProc gDrawCacheProcs[] = { | 725 static const SkDrawCacheProc gDrawCacheProcs[] = { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 int* count, SkRect* bounds) const { | 828 int* count, SkRect* bounds) const { |
| 829 SkASSERT(count); | 829 SkASSERT(count); |
| 830 if (byteLength == 0) { | 830 if (byteLength == 0) { |
| 831 *count = 0; | 831 *count = 0; |
| 832 if (bounds) { | 832 if (bounds) { |
| 833 bounds->setEmpty(); | 833 bounds->setEmpty(); |
| 834 } | 834 } |
| 835 return 0; | 835 return 0; |
| 836 } | 836 } |
| 837 | 837 |
| 838 SkMeasureCacheProc glyphCacheProc = this->getMeasureCacheProc(NULL != bounds
); | 838 SkMeasureCacheProc glyphCacheProc = this->getMeasureCacheProc(nullptr != bou
nds); |
| 839 | 839 |
| 840 int xyIndex; | 840 int xyIndex; |
| 841 JoinBoundsProc joinBoundsProc; | 841 JoinBoundsProc joinBoundsProc; |
| 842 if (this->isVerticalText()) { | 842 if (this->isVerticalText()) { |
| 843 xyIndex = 1; | 843 xyIndex = 1; |
| 844 joinBoundsProc = join_bounds_y; | 844 joinBoundsProc = join_bounds_y; |
| 845 } else { | 845 } else { |
| 846 xyIndex = 0; | 846 xyIndex = 0; |
| 847 joinBoundsProc = join_bounds_x; | 847 joinBoundsProc = join_bounds_x; |
| 848 } | 848 } |
| 849 | 849 |
| 850 int n = 1; | 850 int n = 1; |
| 851 const char* stop = (const char*)text + byteLength; | 851 const char* stop = (const char*)text + byteLength; |
| 852 const SkGlyph* g = &glyphCacheProc(cache, &text); | 852 const SkGlyph* g = &glyphCacheProc(cache, &text); |
| 853 // our accumulated fixed-point advances might overflow 16.16, so we use | 853 // our accumulated fixed-point advances might overflow 16.16, so we use |
| 854 // a 48.16 (64bit) accumulator, and then convert that to scalar at the | 854 // a 48.16 (64bit) accumulator, and then convert that to scalar at the |
| 855 // very end. | 855 // very end. |
| 856 Sk48Dot16 x = advance(*g, xyIndex); | 856 Sk48Dot16 x = advance(*g, xyIndex); |
| 857 | 857 |
| 858 SkAutoKern autokern; | 858 SkAutoKern autokern; |
| 859 | 859 |
| 860 if (NULL == bounds) { | 860 if (nullptr == bounds) { |
| 861 if (this->isDevKernText()) { | 861 if (this->isDevKernText()) { |
| 862 int rsb; | 862 int rsb; |
| 863 for (; text < stop; n++) { | 863 for (; text < stop; n++) { |
| 864 rsb = g->fRsbDelta; | 864 rsb = g->fRsbDelta; |
| 865 g = &glyphCacheProc(cache, &text); | 865 g = &glyphCacheProc(cache, &text); |
| 866 x += SkAutoKern_AdjustF(rsb, g->fLsbDelta) + advance(*g, xyIndex
); | 866 x += SkAutoKern_AdjustF(rsb, g->fLsbDelta) + advance(*g, xyIndex
); |
| 867 } | 867 } |
| 868 } else { | 868 } else { |
| 869 for (; text < stop; n++) { | 869 for (; text < stop; n++) { |
| 870 x += advance(glyphCacheProc(cache, &text), xyIndex); | 870 x += advance(glyphCacheProc(cache, &text), xyIndex); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 890 } | 890 } |
| 891 } | 891 } |
| 892 SkASSERT(text == stop); | 892 SkASSERT(text == stop); |
| 893 | 893 |
| 894 *count = n; | 894 *count = n; |
| 895 return Sk48Dot16ToScalar(x); | 895 return Sk48Dot16ToScalar(x); |
| 896 } | 896 } |
| 897 | 897 |
| 898 SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
s) const { | 898 SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
s) const { |
| 899 const char* text = (const char*)textData; | 899 const char* text = (const char*)textData; |
| 900 SkASSERT(text != NULL || length == 0); | 900 SkASSERT(text != nullptr || length == 0); |
| 901 | 901 |
| 902 SkCanonicalizePaint canon(*this); | 902 SkCanonicalizePaint canon(*this); |
| 903 const SkPaint& paint = canon.getPaint(); | 903 const SkPaint& paint = canon.getPaint(); |
| 904 SkScalar scale = canon.getScale(); | 904 SkScalar scale = canon.getScale(); |
| 905 | 905 |
| 906 SkAutoGlyphCache autoCache(paint, NULL, NULL); | 906 SkAutoGlyphCache autoCache(paint, nullptr, nullptr); |
| 907 SkGlyphCache* cache = autoCache.getCache(); | 907 SkGlyphCache* cache = autoCache.getCache(); |
| 908 | 908 |
| 909 SkScalar width = 0; | 909 SkScalar width = 0; |
| 910 | 910 |
| 911 if (length > 0) { | 911 if (length > 0) { |
| 912 int tempCount; | 912 int tempCount; |
| 913 | 913 |
| 914 width = paint.measure_text(cache, text, length, &tempCount, bounds); | 914 width = paint.measure_text(cache, text, length, &tempCount, bounds); |
| 915 if (scale) { | 915 if (scale) { |
| 916 width = SkScalarMul(width, scale); | 916 width = SkScalarMul(width, scale); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 937 return 0; | 937 return 0; |
| 938 } | 938 } |
| 939 | 939 |
| 940 if (0 == fTextSize) { | 940 if (0 == fTextSize) { |
| 941 if (measuredWidth) { | 941 if (measuredWidth) { |
| 942 *measuredWidth = 0; | 942 *measuredWidth = 0; |
| 943 } | 943 } |
| 944 return length; | 944 return length; |
| 945 } | 945 } |
| 946 | 946 |
| 947 SkASSERT(textD != NULL); | 947 SkASSERT(textD != nullptr); |
| 948 const char* text = (const char*)textD; | 948 const char* text = (const char*)textD; |
| 949 const char* stop = text + length; | 949 const char* stop = text + length; |
| 950 | 950 |
| 951 SkCanonicalizePaint canon(*this); | 951 SkCanonicalizePaint canon(*this); |
| 952 const SkPaint& paint = canon.getPaint(); | 952 const SkPaint& paint = canon.getPaint(); |
| 953 SkScalar scale = canon.getScale(); | 953 SkScalar scale = canon.getScale(); |
| 954 | 954 |
| 955 // adjust max in case we changed the textSize in paint | 955 // adjust max in case we changed the textSize in paint |
| 956 if (scale) { | 956 if (scale) { |
| 957 maxWidth /= scale; | 957 maxWidth /= scale; |
| 958 } | 958 } |
| 959 | 959 |
| 960 SkAutoGlyphCache autoCache(paint, NULL, NULL); | 960 SkAutoGlyphCache autoCache(paint, nullptr, nullptr); |
| 961 SkGlyphCache* cache = autoCache.getCache(); | 961 SkGlyphCache* cache = autoCache.getCache(); |
| 962 | 962 |
| 963 SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc(false); | 963 SkMeasureCacheProc glyphCacheProc = paint.getMeasureCacheProc(false); |
| 964 const int xyIndex = paint.isVerticalText() ? 1 : 0; | 964 const int xyIndex = paint.isVerticalText() ? 1 : 0; |
| 965 // use 64bits for our accumulator, to avoid overflowing 16.16 | 965 // use 64bits for our accumulator, to avoid overflowing 16.16 |
| 966 Sk48Dot16 max = SkScalarToFixed(maxWidth); | 966 Sk48Dot16 max = SkScalarToFixed(maxWidth); |
| 967 Sk48Dot16 width = 0; | 967 Sk48Dot16 width = 0; |
| 968 | 968 |
| 969 SkAutoKern autokern; | 969 SkAutoKern autokern; |
| 970 | 970 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc, | 1015 static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc, |
| 1016 void* context) { | 1016 void* context) { |
| 1017 SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context); | 1017 SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { | 1020 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { |
| 1021 SkCanonicalizePaint canon(*this); | 1021 SkCanonicalizePaint canon(*this); |
| 1022 const SkPaint& paint = canon.getPaint(); | 1022 const SkPaint& paint = canon.getPaint(); |
| 1023 SkScalar scale = canon.getScale(); | 1023 SkScalar scale = canon.getScale(); |
| 1024 | 1024 |
| 1025 SkMatrix zoomMatrix, *zoomPtr = NULL; | 1025 SkMatrix zoomMatrix, *zoomPtr = nullptr; |
| 1026 if (zoom) { | 1026 if (zoom) { |
| 1027 zoomMatrix.setScale(zoom, zoom); | 1027 zoomMatrix.setScale(zoom, zoom); |
| 1028 zoomPtr = &zoomMatrix; | 1028 zoomPtr = &zoomMatrix; |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 FontMetrics storage; | 1031 FontMetrics storage; |
| 1032 if (NULL == metrics) { | 1032 if (nullptr == metrics) { |
| 1033 metrics = &storage; | 1033 metrics = &storage; |
| 1034 } | 1034 } |
| 1035 | 1035 |
| 1036 paint.descriptorProc(NULL, zoomPtr, FontMetricsDescProc, metrics, true); | 1036 paint.descriptorProc(nullptr, zoomPtr, FontMetricsDescProc, metrics, true); |
| 1037 | 1037 |
| 1038 if (scale) { | 1038 if (scale) { |
| 1039 metrics->fTop = SkScalarMul(metrics->fTop, scale); | 1039 metrics->fTop = SkScalarMul(metrics->fTop, scale); |
| 1040 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); | 1040 metrics->fAscent = SkScalarMul(metrics->fAscent, scale); |
| 1041 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); | 1041 metrics->fDescent = SkScalarMul(metrics->fDescent, scale); |
| 1042 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); | 1042 metrics->fBottom = SkScalarMul(metrics->fBottom, scale); |
| 1043 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); | 1043 metrics->fLeading = SkScalarMul(metrics->fLeading, scale); |
| 1044 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); | 1044 metrics->fAvgCharWidth = SkScalarMul(metrics->fAvgCharWidth, scale); |
| 1045 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); | 1045 metrics->fXMin = SkScalarMul(metrics->fXMin, scale); |
| 1046 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); | 1046 metrics->fXMax = SkScalarMul(metrics->fXMax, scale); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1061 } | 1061 } |
| 1062 | 1062 |
| 1063 int SkPaint::getTextWidths(const void* textData, size_t byteLength, | 1063 int SkPaint::getTextWidths(const void* textData, size_t byteLength, |
| 1064 SkScalar widths[], SkRect bounds[]) const { | 1064 SkScalar widths[], SkRect bounds[]) const { |
| 1065 if (0 == byteLength) { | 1065 if (0 == byteLength) { |
| 1066 return 0; | 1066 return 0; |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 SkASSERT(textData); | 1069 SkASSERT(textData); |
| 1070 | 1070 |
| 1071 if (NULL == widths && NULL == bounds) { | 1071 if (nullptr == widths && nullptr == bounds) { |
| 1072 return this->countText(textData, byteLength); | 1072 return this->countText(textData, byteLength); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 SkCanonicalizePaint canon(*this); | 1075 SkCanonicalizePaint canon(*this); |
| 1076 const SkPaint& paint = canon.getPaint(); | 1076 const SkPaint& paint = canon.getPaint(); |
| 1077 SkScalar scale = canon.getScale(); | 1077 SkScalar scale = canon.getScale(); |
| 1078 | 1078 |
| 1079 SkAutoGlyphCache autoCache(paint, NULL, NULL); | 1079 SkAutoGlyphCache autoCache(paint, nullptr, nullptr); |
| 1080 SkGlyphCache* cache = autoCache.getCache(); | 1080 SkGlyphCache* cache = autoCache.getCache(); |
| 1081 SkMeasureCacheProc glyphCacheProc; | 1081 SkMeasureCacheProc glyphCacheProc; |
| 1082 glyphCacheProc = paint.getMeasureCacheProc(NULL != bounds); | 1082 glyphCacheProc = paint.getMeasureCacheProc(nullptr != bounds); |
| 1083 | 1083 |
| 1084 const char* text = (const char*)textData; | 1084 const char* text = (const char*)textData; |
| 1085 const char* stop = text + byteLength; | 1085 const char* stop = text + byteLength; |
| 1086 int count = 0; | 1086 int count = 0; |
| 1087 const int xyIndex = paint.isVerticalText() ? 1 : 0; | 1087 const int xyIndex = paint.isVerticalText() ? 1 : 0; |
| 1088 | 1088 |
| 1089 if (this->isDevKernText()) { | 1089 if (this->isDevKernText()) { |
| 1090 // we adjust the widths returned here through auto-kerning | 1090 // we adjust the widths returned here through auto-kerning |
| 1091 SkAutoKern autokern; | 1091 SkAutoKern autokern; |
| 1092 SkFixed prevWidth = 0; | 1092 SkFixed prevWidth = 0; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 SkASSERT(text == stop); | 1161 SkASSERT(text == stop); |
| 1162 return count; | 1162 return count; |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 /////////////////////////////////////////////////////////////////////////////// | 1165 /////////////////////////////////////////////////////////////////////////////// |
| 1166 | 1166 |
| 1167 #include "SkDraw.h" | 1167 #include "SkDraw.h" |
| 1168 | 1168 |
| 1169 void SkPaint::getTextPath(const void* textData, size_t length, | 1169 void SkPaint::getTextPath(const void* textData, size_t length, |
| 1170 SkScalar x, SkScalar y, SkPath* path) const { | 1170 SkScalar x, SkScalar y, SkPath* path) const { |
| 1171 SkASSERT(length == 0 || textData != NULL); | 1171 SkASSERT(length == 0 || textData != nullptr); |
| 1172 | 1172 |
| 1173 const char* text = (const char*)textData; | 1173 const char* text = (const char*)textData; |
| 1174 if (text == NULL || length == 0 || path == NULL) { | 1174 if (text == nullptr || length == 0 || path == nullptr) { |
| 1175 return; | 1175 return; |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 SkTextToPathIter iter(text, length, *this, false); | 1178 SkTextToPathIter iter(text, length, *this, false); |
| 1179 SkMatrix matrix; | 1179 SkMatrix matrix; |
| 1180 SkScalar prevXPos = 0; | 1180 SkScalar prevXPos = 0; |
| 1181 | 1181 |
| 1182 matrix.setScale(iter.getPathScale(), iter.getPathScale()); | 1182 matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 1183 matrix.postTranslate(x, y); | 1183 matrix.postTranslate(x, y); |
| 1184 path->reset(); | 1184 path->reset(); |
| 1185 | 1185 |
| 1186 SkScalar xpos; | 1186 SkScalar xpos; |
| 1187 const SkPath* iterPath; | 1187 const SkPath* iterPath; |
| 1188 while (iter.next(&iterPath, &xpos)) { | 1188 while (iter.next(&iterPath, &xpos)) { |
| 1189 matrix.postTranslate(xpos - prevXPos, 0); | 1189 matrix.postTranslate(xpos - prevXPos, 0); |
| 1190 if (iterPath) { | 1190 if (iterPath) { |
| 1191 path->addPath(*iterPath, matrix); | 1191 path->addPath(*iterPath, matrix); |
| 1192 } | 1192 } |
| 1193 prevXPos = xpos; | 1193 prevXPos = xpos; |
| 1194 } | 1194 } |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 void SkPaint::getPosTextPath(const void* textData, size_t length, | 1197 void SkPaint::getPosTextPath(const void* textData, size_t length, |
| 1198 const SkPoint pos[], SkPath* path) const { | 1198 const SkPoint pos[], SkPath* path) const { |
| 1199 SkASSERT(length == 0 || textData != NULL); | 1199 SkASSERT(length == 0 || textData != nullptr); |
| 1200 | 1200 |
| 1201 const char* text = (const char*)textData; | 1201 const char* text = (const char*)textData; |
| 1202 if (text == NULL || length == 0 || path == NULL) { | 1202 if (text == nullptr || length == 0 || path == nullptr) { |
| 1203 return; | 1203 return; |
| 1204 } | 1204 } |
| 1205 | 1205 |
| 1206 SkTextToPathIter iter(text, length, *this, false); | 1206 SkTextToPathIter iter(text, length, *this, false); |
| 1207 SkMatrix matrix; | 1207 SkMatrix matrix; |
| 1208 SkPoint prevPos; | 1208 SkPoint prevPos; |
| 1209 prevPos.set(0, 0); | 1209 prevPos.set(0, 0); |
| 1210 | 1210 |
| 1211 matrix.setScale(iter.getPathScale(), iter.getPathScale()); | 1211 matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 1212 path->reset(); | 1212 path->reset(); |
| 1213 | 1213 |
| 1214 unsigned int i = 0; | 1214 unsigned int i = 0; |
| 1215 const SkPath* iterPath; | 1215 const SkPath* iterPath; |
| 1216 while (iter.next(&iterPath, NULL)) { | 1216 while (iter.next(&iterPath, nullptr)) { |
| 1217 matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY); | 1217 matrix.postTranslate(pos[i].fX - prevPos.fX, pos[i].fY - prevPos.fY); |
| 1218 if (iterPath) { | 1218 if (iterPath) { |
| 1219 path->addPath(*iterPath, matrix); | 1219 path->addPath(*iterPath, matrix); |
| 1220 } | 1220 } |
| 1221 prevPos = pos[i]; | 1221 prevPos = pos[i]; |
| 1222 i++; | 1222 i++; |
| 1223 } | 1223 } |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 SkRect SkPaint::getFontBounds() const { | 1226 SkRect SkPaint::getFontBounds() const { |
| 1227 SkMatrix m; | 1227 SkMatrix m; |
| 1228 m.setScale(fTextSize * fTextScaleX, fTextSize); | 1228 m.setScale(fTextSize * fTextScaleX, fTextSize); |
| 1229 m.postSkew(fTextSkewX, 0); | 1229 m.postSkew(fTextSkewX, 0); |
| 1230 | 1230 |
| 1231 SkTypeface* typeface = this->getTypeface(); | 1231 SkTypeface* typeface = this->getTypeface(); |
| 1232 if (NULL == typeface) { | 1232 if (nullptr == typeface) { |
| 1233 typeface = SkTypeface::GetDefaultTypeface(); | 1233 typeface = SkTypeface::GetDefaultTypeface(); |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 SkRect bounds; | 1236 SkRect bounds; |
| 1237 m.mapRect(&bounds, typeface->getBounds()); | 1237 m.mapRect(&bounds, typeface->getBounds()); |
| 1238 return bounds; | 1238 return bounds; |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 static void add_flattenable(SkDescriptor* desc, uint32_t tag, | 1241 static void add_flattenable(SkDescriptor* desc, uint32_t tag, |
| 1242 SkWriteBuffer* buffer) { | 1242 SkWriteBuffer* buffer) { |
| 1243 buffer->writeToMemory(desc->addEntry(tag, buffer->bytesWritten(), NULL)); | 1243 buffer->writeToMemory(desc->addEntry(tag, buffer->bytesWritten(), nullptr)); |
| 1244 } | 1244 } |
| 1245 | 1245 |
| 1246 static SkMask::Format compute_mask_format(const SkPaint& paint) { | 1246 static SkMask::Format compute_mask_format(const SkPaint& paint) { |
| 1247 uint32_t flags = paint.getFlags(); | 1247 uint32_t flags = paint.getFlags(); |
| 1248 | 1248 |
| 1249 // Antialiasing being disabled trumps all other settings. | 1249 // Antialiasing being disabled trumps all other settings. |
| 1250 if (!(flags & SkPaint::kAntiAlias_Flag)) { | 1250 if (!(flags & SkPaint::kAntiAlias_Flag)) { |
| 1251 return SkMask::kBW_Format; | 1251 return SkMask::kBW_Format; |
| 1252 } | 1252 } |
| 1253 | 1253 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1322 */ | 1322 */ |
| 1323 static SkScalar sk_relax(SkScalar x) { | 1323 static SkScalar sk_relax(SkScalar x) { |
| 1324 int n = sk_float_round2int(x * 1024); | 1324 int n = sk_float_round2int(x * 1024); |
| 1325 return n / 1024.0f; | 1325 return n / 1024.0f; |
| 1326 } | 1326 } |
| 1327 | 1327 |
| 1328 void SkScalerContext::MakeRec(const SkPaint& paint, | 1328 void SkScalerContext::MakeRec(const SkPaint& paint, |
| 1329 const SkSurfaceProps* surfaceProps, | 1329 const SkSurfaceProps* surfaceProps, |
| 1330 const SkMatrix* deviceMatrix, | 1330 const SkMatrix* deviceMatrix, |
| 1331 Rec* rec) { | 1331 Rec* rec) { |
| 1332 SkASSERT(deviceMatrix == NULL || !deviceMatrix->hasPerspective()); | 1332 SkASSERT(deviceMatrix == nullptr || !deviceMatrix->hasPerspective()); |
| 1333 | 1333 |
| 1334 SkTypeface* typeface = paint.getTypeface(); | 1334 SkTypeface* typeface = paint.getTypeface(); |
| 1335 if (NULL == typeface) { | 1335 if (nullptr == typeface) { |
| 1336 typeface = SkTypeface::GetDefaultTypeface(); | 1336 typeface = SkTypeface::GetDefaultTypeface(); |
| 1337 } | 1337 } |
| 1338 rec->fFontID = typeface->uniqueID(); | 1338 rec->fFontID = typeface->uniqueID(); |
| 1339 rec->fTextSize = paint.getTextSize(); | 1339 rec->fTextSize = paint.getTextSize(); |
| 1340 rec->fPreScaleX = paint.getTextScaleX(); | 1340 rec->fPreScaleX = paint.getTextScaleX(); |
| 1341 rec->fPreSkewX = paint.getTextSkewX(); | 1341 rec->fPreSkewX = paint.getTextSkewX(); |
| 1342 | 1342 |
| 1343 bool checkPost2x2 = false; | 1343 bool checkPost2x2 = false; |
| 1344 | 1344 |
| 1345 if (deviceMatrix) { | 1345 if (deviceMatrix) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 // be sure to call PostMakeRec(rec) before you actually use it! | 1491 // be sure to call PostMakeRec(rec) before you actually use it! |
| 1492 } | 1492 } |
| 1493 | 1493 |
| 1494 /** | 1494 /** |
| 1495 * In order to call cachedDeviceLuminance, cachedPaintLuminance, or | 1495 * In order to call cachedDeviceLuminance, cachedPaintLuminance, or |
| 1496 * cachedMaskGamma the caller must hold the gMaskGammaCacheMutex and continue | 1496 * cachedMaskGamma the caller must hold the gMaskGammaCacheMutex and continue |
| 1497 * to hold it until the returned pointer is refed or forgotten. | 1497 * to hold it until the returned pointer is refed or forgotten. |
| 1498 */ | 1498 */ |
| 1499 SK_DECLARE_STATIC_MUTEX(gMaskGammaCacheMutex); | 1499 SK_DECLARE_STATIC_MUTEX(gMaskGammaCacheMutex); |
| 1500 | 1500 |
| 1501 static SkMaskGamma* gLinearMaskGamma = NULL; | 1501 static SkMaskGamma* gLinearMaskGamma = nullptr; |
| 1502 static SkMaskGamma* gMaskGamma = NULL; | 1502 static SkMaskGamma* gMaskGamma = nullptr; |
| 1503 static SkScalar gContrast = SK_ScalarMin; | 1503 static SkScalar gContrast = SK_ScalarMin; |
| 1504 static SkScalar gPaintGamma = SK_ScalarMin; | 1504 static SkScalar gPaintGamma = SK_ScalarMin; |
| 1505 static SkScalar gDeviceGamma = SK_ScalarMin; | 1505 static SkScalar gDeviceGamma = SK_ScalarMin; |
| 1506 /** | 1506 /** |
| 1507 * The caller must hold the gMaskGammaCacheMutex and continue to hold it until | 1507 * The caller must hold the gMaskGammaCacheMutex and continue to hold it until |
| 1508 * the returned SkMaskGamma pointer is refed or forgotten. | 1508 * the returned SkMaskGamma pointer is refed or forgotten. |
| 1509 */ | 1509 */ |
| 1510 static const SkMaskGamma& cachedMaskGamma(SkScalar contrast, SkScalar paintGamma
, SkScalar deviceGamma) { | 1510 static const SkMaskGamma& cachedMaskGamma(SkScalar contrast, SkScalar paintGamma
, SkScalar deviceGamma) { |
| 1511 gMaskGammaCacheMutex.assertHeld(); | 1511 gMaskGammaCacheMutex.assertHeld(); |
| 1512 if (0 == contrast && SK_Scalar1 == paintGamma && SK_Scalar1 == deviceGamma)
{ | 1512 if (0 == contrast && SK_Scalar1 == paintGamma && SK_Scalar1 == deviceGamma)
{ |
| 1513 if (NULL == gLinearMaskGamma) { | 1513 if (nullptr == gLinearMaskGamma) { |
| 1514 gLinearMaskGamma = new SkMaskGamma; | 1514 gLinearMaskGamma = new SkMaskGamma; |
| 1515 } | 1515 } |
| 1516 return *gLinearMaskGamma; | 1516 return *gLinearMaskGamma; |
| 1517 } | 1517 } |
| 1518 if (gContrast != contrast || gPaintGamma != paintGamma || gDeviceGamma != de
viceGamma) { | 1518 if (gContrast != contrast || gPaintGamma != paintGamma || gDeviceGamma != de
viceGamma) { |
| 1519 SkSafeUnref(gMaskGamma); | 1519 SkSafeUnref(gMaskGamma); |
| 1520 gMaskGamma = new SkMaskGamma(contrast, paintGamma, deviceGamma); | 1520 gMaskGamma = new SkMaskGamma(contrast, paintGamma, deviceGamma); |
| 1521 gContrast = contrast; | 1521 gContrast = contrast; |
| 1522 gPaintGamma = paintGamma; | 1522 gPaintGamma = paintGamma; |
| 1523 gDeviceGamma = deviceGamma; | 1523 gDeviceGamma = deviceGamma; |
| 1524 } | 1524 } |
| 1525 return *gMaskGamma; | 1525 return *gMaskGamma; |
| 1526 } | 1526 } |
| 1527 | 1527 |
| 1528 /*static*/ void SkPaint::Term() { | 1528 /*static*/ void SkPaint::Term() { |
| 1529 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); | 1529 SkAutoMutexAcquire ama(gMaskGammaCacheMutex); |
| 1530 | 1530 |
| 1531 SkSafeUnref(gLinearMaskGamma); | 1531 SkSafeUnref(gLinearMaskGamma); |
| 1532 gLinearMaskGamma = NULL; | 1532 gLinearMaskGamma = nullptr; |
| 1533 SkSafeUnref(gMaskGamma); | 1533 SkSafeUnref(gMaskGamma); |
| 1534 gMaskGamma = NULL; | 1534 gMaskGamma = nullptr; |
| 1535 SkDEBUGCODE(gContrast = SK_ScalarMin;) | 1535 SkDEBUGCODE(gContrast = SK_ScalarMin;) |
| 1536 SkDEBUGCODE(gPaintGamma = SK_ScalarMin;) | 1536 SkDEBUGCODE(gPaintGamma = SK_ScalarMin;) |
| 1537 SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;) | 1537 SkDEBUGCODE(gDeviceGamma = SK_ScalarMin;) |
| 1538 } | 1538 } |
| 1539 | 1539 |
| 1540 /** | 1540 /** |
| 1541 * We ensure that the rec is self-consistent and efficient (where possible) | 1541 * We ensure that the rec is self-consistent and efficient (where possible) |
| 1542 */ | 1542 */ |
| 1543 void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) { | 1543 void SkScalerContext::PostMakeRec(const SkPaint&, SkScalerContext::Rec* rec) { |
| 1544 /** | 1544 /** |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1968 | 1968 |
| 1969 uint32_t tmp = *pod++; | 1969 uint32_t tmp = *pod++; |
| 1970 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); | 1970 this->setStrokeCap(static_cast<Cap>((tmp >> 24) & 0xFF)); |
| 1971 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); | 1971 this->setStrokeJoin(static_cast<Join>((tmp >> 16) & 0xFF)); |
| 1972 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); | 1972 this->setStyle(static_cast<Style>((tmp >> 8) & 0xFF)); |
| 1973 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); | 1973 this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); |
| 1974 | 1974 |
| 1975 if (flatFlags & kHasTypeface_FlatFlag) { | 1975 if (flatFlags & kHasTypeface_FlatFlag) { |
| 1976 this->setTypeface(buffer.readTypeface()); | 1976 this->setTypeface(buffer.readTypeface()); |
| 1977 } else { | 1977 } else { |
| 1978 this->setTypeface(NULL); | 1978 this->setTypeface(nullptr); |
| 1979 } | 1979 } |
| 1980 | 1980 |
| 1981 if (flatFlags & kHasEffects_FlatFlag) { | 1981 if (flatFlags & kHasEffects_FlatFlag) { |
| 1982 SkSafeUnref(this->setPathEffect(buffer.readPathEffect())); | 1982 SkSafeUnref(this->setPathEffect(buffer.readPathEffect())); |
| 1983 SkSafeUnref(this->setShader(buffer.readShader())); | 1983 SkSafeUnref(this->setShader(buffer.readShader())); |
| 1984 SkSafeUnref(this->setXfermode(buffer.readXfermode())); | 1984 SkSafeUnref(this->setXfermode(buffer.readXfermode())); |
| 1985 SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); | 1985 SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter())); |
| 1986 SkSafeUnref(this->setColorFilter(buffer.readColorFilter())); | 1986 SkSafeUnref(this->setColorFilter(buffer.readColorFilter())); |
| 1987 SkSafeUnref(this->setRasterizer(buffer.readRasterizer())); | 1987 SkSafeUnref(this->setRasterizer(buffer.readRasterizer())); |
| 1988 SkSafeUnref(this->setLooper(buffer.readDrawLooper())); | 1988 SkSafeUnref(this->setLooper(buffer.readDrawLooper())); |
| 1989 SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); | 1989 SkSafeUnref(this->setImageFilter(buffer.readImageFilter())); |
| 1990 | 1990 |
| 1991 if (buffer.readBool()) { | 1991 if (buffer.readBool()) { |
| 1992 this->setAnnotation(SkAnnotation::Create(buffer))->unref(); | 1992 this->setAnnotation(SkAnnotation::Create(buffer))->unref(); |
| 1993 } | 1993 } |
| 1994 } else { | 1994 } else { |
| 1995 this->setPathEffect(NULL); | 1995 this->setPathEffect(nullptr); |
| 1996 this->setShader(NULL); | 1996 this->setShader(nullptr); |
| 1997 this->setXfermode(NULL); | 1997 this->setXfermode(nullptr); |
| 1998 this->setMaskFilter(NULL); | 1998 this->setMaskFilter(nullptr); |
| 1999 this->setColorFilter(NULL); | 1999 this->setColorFilter(nullptr); |
| 2000 this->setRasterizer(NULL); | 2000 this->setRasterizer(nullptr); |
| 2001 this->setLooper(NULL); | 2001 this->setLooper(nullptr); |
| 2002 this->setImageFilter(NULL); | 2002 this->setImageFilter(nullptr); |
| 2003 } | 2003 } |
| 2004 } | 2004 } |
| 2005 | 2005 |
| 2006 /////////////////////////////////////////////////////////////////////////////// | 2006 /////////////////////////////////////////////////////////////////////////////// |
| 2007 | 2007 |
| 2008 SkShader* SkPaint::setShader(SkShader* shader) { | 2008 SkShader* SkPaint::setShader(SkShader* shader) { |
| 2009 SkRefCnt_SafeAssign(fShader, shader); | 2009 SkRefCnt_SafeAssign(fShader, shader); |
| 2010 return shader; | 2010 return shader; |
| 2011 } | 2011 } |
| 2012 | 2012 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2296 paint.getStyle() != SkPaint::kFill_Style; | 2296 paint.getStyle() != SkPaint::kFill_Style; |
| 2297 } | 2297 } |
| 2298 | 2298 |
| 2299 SkTextToPathIter::SkTextToPathIter(const char text[], size_t length, | 2299 SkTextToPathIter::SkTextToPathIter(const char text[], size_t length, |
| 2300 const SkPaint& paint, | 2300 const SkPaint& paint, |
| 2301 bool applyStrokeAndPathEffects) | 2301 bool applyStrokeAndPathEffects) |
| 2302 : fPaint(paint) { | 2302 : fPaint(paint) { |
| 2303 fGlyphCacheProc = paint.getMeasureCacheProc(true); | 2303 fGlyphCacheProc = paint.getMeasureCacheProc(true); |
| 2304 | 2304 |
| 2305 fPaint.setLinearText(true); | 2305 fPaint.setLinearText(true); |
| 2306 fPaint.setMaskFilter(NULL); // don't want this affecting our path-cache lo
okup | 2306 fPaint.setMaskFilter(nullptr); // don't want this affecting our path-cache
lookup |
| 2307 | 2307 |
| 2308 if (fPaint.getPathEffect() == NULL && !has_thick_frame(fPaint)) { | 2308 if (fPaint.getPathEffect() == nullptr && !has_thick_frame(fPaint)) { |
| 2309 applyStrokeAndPathEffects = false; | 2309 applyStrokeAndPathEffects = false; |
| 2310 } | 2310 } |
| 2311 | 2311 |
| 2312 // can't use our canonical size if we need to apply patheffects | 2312 // can't use our canonical size if we need to apply patheffects |
| 2313 if (fPaint.getPathEffect() == NULL) { | 2313 if (fPaint.getPathEffect() == nullptr) { |
| 2314 fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths)); | 2314 fPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths)); |
| 2315 fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths; | 2315 fScale = paint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths; |
| 2316 if (has_thick_frame(fPaint)) { | 2316 if (has_thick_frame(fPaint)) { |
| 2317 fPaint.setStrokeWidth(fPaint.getStrokeWidth() / fScale); | 2317 fPaint.setStrokeWidth(fPaint.getStrokeWidth() / fScale); |
| 2318 } | 2318 } |
| 2319 } else { | 2319 } else { |
| 2320 fScale = SK_Scalar1; | 2320 fScale = SK_Scalar1; |
| 2321 } | 2321 } |
| 2322 | 2322 |
| 2323 if (!applyStrokeAndPathEffects) { | 2323 if (!applyStrokeAndPathEffects) { |
| 2324 fPaint.setStyle(SkPaint::kFill_Style); | 2324 fPaint.setStyle(SkPaint::kFill_Style); |
| 2325 fPaint.setPathEffect(NULL); | 2325 fPaint.setPathEffect(nullptr); |
| 2326 } | 2326 } |
| 2327 | 2327 |
| 2328 fCache = fPaint.detachCache(NULL, NULL, false); | 2328 fCache = fPaint.detachCache(nullptr, nullptr, false); |
| 2329 | 2329 |
| 2330 SkPaint::Style style = SkPaint::kFill_Style; | 2330 SkPaint::Style style = SkPaint::kFill_Style; |
| 2331 SkPathEffect* pe = NULL; | 2331 SkPathEffect* pe = nullptr; |
| 2332 | 2332 |
| 2333 if (!applyStrokeAndPathEffects) { | 2333 if (!applyStrokeAndPathEffects) { |
| 2334 style = paint.getStyle(); // restore | 2334 style = paint.getStyle(); // restore |
| 2335 pe = paint.getPathEffect(); // restore | 2335 pe = paint.getPathEffect(); // restore |
| 2336 } | 2336 } |
| 2337 fPaint.setStyle(style); | 2337 fPaint.setStyle(style); |
| 2338 fPaint.setPathEffect(pe); | 2338 fPaint.setPathEffect(pe); |
| 2339 fPaint.setMaskFilter(paint.getMaskFilter()); // restore | 2339 fPaint.setMaskFilter(paint.getMaskFilter()); // restore |
| 2340 | 2340 |
| 2341 // now compute fXOffset if needed | 2341 // now compute fXOffset if needed |
| 2342 | 2342 |
| 2343 SkScalar xOffset = 0; | 2343 SkScalar xOffset = 0; |
| 2344 if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first | 2344 if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first |
| 2345 int count; | 2345 int count; |
| 2346 SkScalar width = SkScalarMul(fPaint.measure_text(fCache, text, length, | 2346 SkScalar width = SkScalarMul(fPaint.measure_text(fCache, text, length, |
| 2347 &count, NULL), fScale); | 2347 &count, nullptr), fScal
e); |
| 2348 if (paint.getTextAlign() == SkPaint::kCenter_Align) { | 2348 if (paint.getTextAlign() == SkPaint::kCenter_Align) { |
| 2349 width = SkScalarHalf(width); | 2349 width = SkScalarHalf(width); |
| 2350 } | 2350 } |
| 2351 xOffset = -width; | 2351 xOffset = -width; |
| 2352 } | 2352 } |
| 2353 fXPos = xOffset; | 2353 fXPos = xOffset; |
| 2354 fPrevAdvance = 0; | 2354 fPrevAdvance = 0; |
| 2355 | 2355 |
| 2356 fText = text; | 2356 fText = text; |
| 2357 fStop = text + length; | 2357 fStop = text + length; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2369 | 2369 |
| 2370 fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(gly
ph)), fScale); | 2370 fXPos += SkScalarMul(SkFixedToScalar(fPrevAdvance + fAutoKern.adjust(gly
ph)), fScale); |
| 2371 fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking()
; | 2371 fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking()
; |
| 2372 | 2372 |
| 2373 if (glyph.fWidth) { | 2373 if (glyph.fWidth) { |
| 2374 if (path) { | 2374 if (path) { |
| 2375 *path = fCache->findPath(glyph); | 2375 *path = fCache->findPath(glyph); |
| 2376 } | 2376 } |
| 2377 } else { | 2377 } else { |
| 2378 if (path) { | 2378 if (path) { |
| 2379 *path = NULL; | 2379 *path = nullptr; |
| 2380 } | 2380 } |
| 2381 } | 2381 } |
| 2382 if (xpos) { | 2382 if (xpos) { |
| 2383 *xpos = fXPos; | 2383 *xpos = fXPos; |
| 2384 } | 2384 } |
| 2385 return true; | 2385 return true; |
| 2386 } | 2386 } |
| 2387 return false; | 2387 return false; |
| 2388 } | 2388 } |
| 2389 | 2389 |
| 2390 /////////////////////////////////////////////////////////////////////////////// | 2390 /////////////////////////////////////////////////////////////////////////////// |
| 2391 | 2391 |
| 2392 // return true if the filter exists, and may affect alpha | 2392 // return true if the filter exists, and may affect alpha |
| 2393 static bool affects_alpha(const SkColorFilter* cf) { | 2393 static bool affects_alpha(const SkColorFilter* cf) { |
| 2394 return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); | 2394 return cf && !(cf->getFlags() & SkColorFilter::kAlphaUnchanged_Flag); |
| 2395 } | 2395 } |
| 2396 | 2396 |
| 2397 // return true if the filter exists, and may affect alpha | 2397 // return true if the filter exists, and may affect alpha |
| 2398 static bool affects_alpha(const SkImageFilter* imf) { | 2398 static bool affects_alpha(const SkImageFilter* imf) { |
| 2399 // TODO: check if we should allow imagefilters to broadcast that they don't
affect alpha | 2399 // TODO: check if we should allow imagefilters to broadcast that they don't
affect alpha |
| 2400 // ala colorfilters | 2400 // ala colorfilters |
| 2401 return imf != NULL; | 2401 return imf != nullptr; |
| 2402 } | 2402 } |
| 2403 | 2403 |
| 2404 bool SkPaint::nothingToDraw() const { | 2404 bool SkPaint::nothingToDraw() const { |
| 2405 if (fLooper) { | 2405 if (fLooper) { |
| 2406 return false; | 2406 return false; |
| 2407 } | 2407 } |
| 2408 SkXfermode::Mode mode; | 2408 SkXfermode::Mode mode; |
| 2409 if (SkXfermode::AsMode(fXfermode, &mode)) { | 2409 if (SkXfermode::AsMode(fXfermode, &mode)) { |
| 2410 switch (mode) { | 2410 switch (mode) { |
| 2411 case SkXfermode::kSrcOver_Mode: | 2411 case SkXfermode::kSrcOver_Mode: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2427 } | 2427 } |
| 2428 | 2428 |
| 2429 uint32_t SkPaint::getHash() const { | 2429 uint32_t SkPaint::getHash() const { |
| 2430 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, | 2430 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, |
| 2431 // so fBitfields should be 10 pointers and 6 32-bit values from the start. | 2431 // so fBitfields should be 10 pointers and 6 32-bit values from the start. |
| 2432 static_assert(offsetof(SkPaint, fBitfields) == 10 * sizeof(void*) + 6 * size
of(uint32_t), | 2432 static_assert(offsetof(SkPaint, fBitfields) == 10 * sizeof(void*) + 6 * size
of(uint32_t), |
| 2433 "SkPaint_notPackedTightly"); | 2433 "SkPaint_notPackedTightly"); |
| 2434 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), | 2434 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), |
| 2435 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); | 2435 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); |
| 2436 } | 2436 } |
| OLD | NEW |