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 "SkAutoKern.h" | 9 #include "SkAutoKern.h" |
10 #include "SkChecksum.h" | 10 #include "SkChecksum.h" |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 matrix.setConcat(ctm, textM); | 423 matrix.setConcat(ctm, textM); |
424 return tooBig(matrix, MaxCacheSize2()); | 424 return tooBig(matrix, MaxCacheSize2()); |
425 } | 425 } |
426 | 426 |
427 | 427 |
428 /////////////////////////////////////////////////////////////////////////////// | 428 /////////////////////////////////////////////////////////////////////////////// |
429 | 429 |
430 #include "SkGlyphCache.h" | 430 #include "SkGlyphCache.h" |
431 #include "SkUtils.h" | 431 #include "SkUtils.h" |
432 | 432 |
433 static void DetachDescProc(SkTypeface* typeface, const SkDescriptor* desc, | 433 static void DetachDescProc(SkTypeface* typeface, const SkScalerContextEffects& e
ffects, |
434 void* context) { | 434 const SkDescriptor* desc, void* context) { |
435 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, desc); | 435 *((SkGlyphCache**)context) = SkGlyphCache::DetachCache(typeface, effects, de
sc); |
436 } | 436 } |
437 | 437 |
438 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, | 438 int SkPaint::textToGlyphs(const void* textData, size_t byteLength, uint16_t glyp
hs[]) const { |
439 uint16_t glyphs[]) const { | |
440 if (byteLength == 0) { | 439 if (byteLength == 0) { |
441 return 0; | 440 return 0; |
442 } | 441 } |
443 | 442 |
444 SkASSERT(textData != nullptr); | 443 SkASSERT(textData != nullptr); |
445 | 444 |
446 if (nullptr == glyphs) { | 445 if (nullptr == glyphs) { |
447 switch (this->getTextEncoding()) { | 446 switch (this->getTextEncoding()) { |
448 case kUTF8_TextEncoding: | 447 case kUTF8_TextEncoding: |
449 return SkUTF8_CountUnichars((const char*)textData, byteLength); | 448 return SkUTF8_CountUnichars((const char*)textData, byteLength); |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 return text - stop + length; | 930 return text - stop + length; |
932 } | 931 } |
933 | 932 |
934 /////////////////////////////////////////////////////////////////////////////// | 933 /////////////////////////////////////////////////////////////////////////////// |
935 | 934 |
936 static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) { | 935 static bool FontMetricsCacheProc(const SkGlyphCache* cache, void* context) { |
937 *(SkPaint::FontMetrics*)context = cache->getFontMetrics(); | 936 *(SkPaint::FontMetrics*)context = cache->getFontMetrics(); |
938 return false; // don't detach the cache | 937 return false; // don't detach the cache |
939 } | 938 } |
940 | 939 |
941 static void FontMetricsDescProc(SkTypeface* typeface, const SkDescriptor* desc, | 940 static void FontMetricsDescProc(SkTypeface* typeface, const SkScalerContextEffec
ts& effects, |
942 void* context) { | 941 const SkDescriptor* desc, void* context) { |
943 SkGlyphCache::VisitCache(typeface, desc, FontMetricsCacheProc, context); | 942 SkGlyphCache::VisitCache(typeface, effects, desc, FontMetricsCacheProc, cont
ext); |
944 } | 943 } |
945 | 944 |
946 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { | 945 SkScalar SkPaint::getFontMetrics(FontMetrics* metrics, SkScalar zoom) const { |
947 SkCanonicalizePaint canon(*this); | 946 SkCanonicalizePaint canon(*this); |
948 const SkPaint& paint = canon.getPaint(); | 947 const SkPaint& paint = canon.getPaint(); |
949 SkScalar scale = canon.getScale(); | 948 SkScalar scale = canon.getScale(); |
950 | 949 |
951 SkMatrix zoomMatrix, *zoomPtr = nullptr; | 950 SkMatrix zoomMatrix, *zoomPtr = nullptr; |
952 if (zoom) { | 951 if (zoom) { |
953 zoomMatrix.setScale(zoom, zoom); | 952 zoomMatrix.setScale(zoom, zoom); |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 SkASSERT(descSize == desc1->getLength()); | 1640 SkASSERT(descSize == desc1->getLength()); |
1642 SkASSERT(descSize == desc2->getLength()); | 1641 SkASSERT(descSize == desc2->getLength()); |
1643 desc1->computeChecksum(); | 1642 desc1->computeChecksum(); |
1644 desc2->computeChecksum(); | 1643 desc2->computeChecksum(); |
1645 SkASSERT(!memcmp(desc, desc1, descSize)); | 1644 SkASSERT(!memcmp(desc, desc1, descSize)); |
1646 SkASSERT(!memcmp(desc, desc2, descSize)); | 1645 SkASSERT(!memcmp(desc, desc2, descSize)); |
1647 } | 1646 } |
1648 #endif | 1647 #endif |
1649 | 1648 |
1650 /* see the note on ignoreGamma on descriptorProc */ | 1649 /* see the note on ignoreGamma on descriptorProc */ |
1651 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, | 1650 void SkPaint::getScalerContextDescriptor(SkScalerContextEffects* effects, |
| 1651 SkAutoDescriptor* ad, |
1652 const SkSurfaceProps& surfaceProps, | 1652 const SkSurfaceProps& surfaceProps, |
1653 uint32_t scalerContextFlags, | 1653 uint32_t scalerContextFlags, |
1654 const SkMatrix* deviceMatrix) const { | 1654 const SkMatrix* deviceMatrix) const { |
1655 SkScalerContext::Rec rec; | 1655 SkScalerContext::Rec rec; |
1656 | 1656 |
1657 SkPathEffect* pe = this->getPathEffect(); | 1657 SkPathEffect* pe = this->getPathEffect(); |
1658 SkMaskFilter* mf = this->getMaskFilter(); | 1658 SkMaskFilter* mf = this->getMaskFilter(); |
1659 SkRasterizer* ra = this->getRasterizer(); | 1659 SkRasterizer* ra = this->getRasterizer(); |
1660 | 1660 |
1661 SkWriteBuffer peBuffer, mfBuffer, raBuffer; | 1661 SkWriteBuffer peBuffer, mfBuffer, raBuffer; |
1662 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps, | 1662 size_t descSize = fill_out_rec(*this, &rec, &surfaceProps, |
1663 SkToBool(scalerContextFlags & kFakeGamma_Scal
erContextFlag), | 1663 SkToBool(scalerContextFlags & kFakeGamma_Scal
erContextFlag), |
1664 SkToBool(scalerContextFlags & kBoostContrast_
ScalerContextFlag), | 1664 SkToBool(scalerContextFlags & kBoostContrast_
ScalerContextFlag), |
1665 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r
a, &raBuffer); | 1665 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r
a, &raBuffer); |
1666 | 1666 |
1667 ad->reset(descSize); | 1667 ad->reset(descSize); |
1668 SkDescriptor* desc = ad->getDesc(); | 1668 SkDescriptor* desc = ad->getDesc(); |
1669 | 1669 |
1670 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer,
descSize); | 1670 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer,
descSize); |
1671 | 1671 |
1672 SkASSERT(descSize == desc->getLength()); | 1672 SkASSERT(descSize == desc->getLength()); |
1673 | 1673 |
1674 #ifdef TEST_DESC | 1674 #ifdef TEST_DESC |
1675 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); | 1675 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); |
1676 #endif | 1676 #endif |
| 1677 |
| 1678 effects->fPathEffect = pe; |
| 1679 effects->fMaskFilter = mf; |
| 1680 effects->fRasterizer = ra; |
1677 } | 1681 } |
1678 | 1682 |
1679 /* | 1683 /* |
1680 * ignoreGamma tells us that the caller just wants metrics that are unaffected | 1684 * ignoreGamma tells us that the caller just wants metrics that are unaffected |
1681 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, | 1685 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, |
1682 * contrast = 0, luminanceColor = transparent black. | 1686 * contrast = 0, luminanceColor = transparent black. |
1683 */ | 1687 */ |
1684 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, | 1688 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, |
1685 uint32_t scalerContextFlags, | 1689 uint32_t scalerContextFlags, |
1686 const SkMatrix* deviceMatrix, | 1690 const SkMatrix* deviceMatrix, |
1687 void (*proc)(SkTypeface*, const SkDescriptor*, void
*), | 1691 void (*proc)(SkTypeface*, const SkScalerContextEffe
cts&, |
| 1692 const SkDescriptor*, void*), |
1688 void* context) const { | 1693 void* context) const { |
1689 SkScalerContext::Rec rec; | 1694 SkScalerContext::Rec rec; |
1690 | 1695 |
1691 SkPathEffect* pe = this->getPathEffect(); | 1696 SkPathEffect* pe = this->getPathEffect(); |
1692 SkMaskFilter* mf = this->getMaskFilter(); | 1697 SkMaskFilter* mf = this->getMaskFilter(); |
1693 SkRasterizer* ra = this->getRasterizer(); | 1698 SkRasterizer* ra = this->getRasterizer(); |
1694 | 1699 |
1695 SkWriteBuffer peBuffer, mfBuffer, raBuffer; | 1700 SkWriteBuffer peBuffer, mfBuffer, raBuffer; |
1696 size_t descSize = fill_out_rec(*this, &rec, surfaceProps, | 1701 size_t descSize = fill_out_rec(*this, &rec, surfaceProps, |
1697 SkToBool(scalerContextFlags & kFakeGamma_Scal
erContextFlag), | 1702 SkToBool(scalerContextFlags & kFakeGamma_Scal
erContextFlag), |
1698 SkToBool(scalerContextFlags & kBoostContrast_
ScalerContextFlag), | 1703 SkToBool(scalerContextFlags & kBoostContrast_
ScalerContextFlag), |
1699 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r
a, &raBuffer); | 1704 deviceMatrix, pe, &peBuffer, mf, &mfBuffer, r
a, &raBuffer); |
1700 | 1705 |
1701 SkAutoDescriptor ad(descSize); | 1706 SkAutoDescriptor ad(descSize); |
1702 SkDescriptor* desc = ad.getDesc(); | 1707 SkDescriptor* desc = ad.getDesc(); |
1703 | 1708 |
1704 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer,
descSize); | 1709 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer,
descSize); |
1705 | 1710 |
1706 SkASSERT(descSize == desc->getLength()); | 1711 SkASSERT(descSize == desc->getLength()); |
1707 | 1712 |
1708 #ifdef TEST_DESC | 1713 #ifdef TEST_DESC |
1709 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); | 1714 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); |
1710 #endif | 1715 #endif |
1711 | 1716 |
1712 proc(fTypeface.get(), desc, context); | 1717 proc(fTypeface.get(), { pe, mf, ra }, desc, context); |
1713 } | 1718 } |
1714 | 1719 |
1715 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, | 1720 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, |
1716 uint32_t scalerContextFlags, | 1721 uint32_t scalerContextFlags, |
1717 const SkMatrix* deviceMatrix) const { | 1722 const SkMatrix* deviceMatrix) const { |
1718 SkGlyphCache* cache; | 1723 SkGlyphCache* cache; |
1719 this->descriptorProc(surfaceProps, scalerContextFlags, deviceMatrix, DetachD
escProc, &cache); | 1724 this->descriptorProc(surfaceProps, scalerContextFlags, deviceMatrix, DetachD
escProc, &cache); |
1720 return cache; | 1725 return cache; |
1721 } | 1726 } |
1722 | 1727 |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2366 } | 2371 } |
2367 | 2372 |
2368 uint32_t SkPaint::getHash() const { | 2373 uint32_t SkPaint::getHash() const { |
2369 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, | 2374 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB
itfields, |
2370 // so fBitfields should be 10 pointers and 6 32-bit values from the start. | 2375 // so fBitfields should be 10 pointers and 6 32-bit values from the start. |
2371 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo
f(uint32_t), | 2376 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo
f(uint32_t), |
2372 "SkPaint_notPackedTightly"); | 2377 "SkPaint_notPackedTightly"); |
2373 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), | 2378 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), |
2374 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); | 2379 offsetof(SkPaint, fBitfields) + sizeof(fBitfields
)); |
2375 } | 2380 } |
OLD | NEW |