Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: src/core/SkPaint.cpp

Issue 1863013003: Pass effects directly to fontcache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: removed DUMMY effects Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 SkASSERT(descSize == desc2->getLength()); 1638 SkASSERT(descSize == desc2->getLength());
1640 desc1->computeChecksum(); 1639 desc1->computeChecksum();
1641 desc2->computeChecksum(); 1640 desc2->computeChecksum();
1642 SkASSERT(!memcmp(desc, desc1, descSize)); 1641 SkASSERT(!memcmp(desc, desc1, descSize));
1643 SkASSERT(!memcmp(desc, desc2, descSize)); 1642 SkASSERT(!memcmp(desc, desc2, descSize));
1644 } 1643 }
1645 #endif 1644 #endif
1646 1645
1647 /* see the note on ignoreGamma on descriptorProc */ 1646 /* see the note on ignoreGamma on descriptorProc */
1648 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad, 1647 void SkPaint::getScalerContextDescriptor(SkAutoDescriptor* ad,
1648 SkScalerContextEffects* effects,
1649 const SkSurfaceProps& surfaceProps, 1649 const SkSurfaceProps& surfaceProps,
1650 FakeGamma fakeGamma, 1650 FakeGamma fakeGamma,
1651 const SkMatrix* deviceMatrix) const { 1651 const SkMatrix* deviceMatrix) const {
1652 SkScalerContext::Rec rec; 1652 SkScalerContext::Rec rec;
1653 1653
1654 SkPathEffect* pe = this->getPathEffect(); 1654 SkPathEffect* pe = this->getPathEffect();
1655 SkMaskFilter* mf = this->getMaskFilter(); 1655 SkMaskFilter* mf = this->getMaskFilter();
1656 SkRasterizer* ra = this->getRasterizer(); 1656 SkRasterizer* ra = this->getRasterizer();
1657 1657
1658 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1658 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1659 size_t descSize = fill_out_rec(*this, &rec, 1659 size_t descSize = fill_out_rec(*this, &rec,
1660 &surfaceProps, FakeGamma::On == fakeGamma, de viceMatrix, 1660 &surfaceProps, FakeGamma::On == fakeGamma, de viceMatrix,
1661 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1661 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer);
1662 1662
1663 ad->reset(descSize); 1663 ad->reset(descSize);
1664 SkDescriptor* desc = ad->getDesc(); 1664 SkDescriptor* desc = ad->getDesc();
1665 1665
1666 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1666 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1667 1667
1668 SkASSERT(descSize == desc->getLength()); 1668 SkASSERT(descSize == desc->getLength());
1669 1669
1670 #ifdef TEST_DESC 1670 #ifdef TEST_DESC
1671 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1671 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1672 #endif 1672 #endif
1673
1674 effects->fPathEffect = pe;
1675 effects->fMaskFilter = mf;
1676 effects->fRasterizer = ra;
1673 } 1677 }
1674 1678
1675 /* 1679 /*
1676 * ignoreGamma tells us that the caller just wants metrics that are unaffected 1680 * ignoreGamma tells us that the caller just wants metrics that are unaffected
1677 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1, 1681 * by gamma correction, so we set the rec to ignore preblend: i.e. gamma = 1,
1678 * contrast = 0, luminanceColor = transparent black. 1682 * contrast = 0, luminanceColor = transparent black.
1679 */ 1683 */
1680 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps, 1684 void SkPaint::descriptorProc(const SkSurfaceProps* surfaceProps,
1681 FakeGamma fakeGamma, 1685 FakeGamma fakeGamma,
1682 const SkMatrix* deviceMatrix, 1686 const SkMatrix* deviceMatrix,
1683 void (*proc)(SkTypeface*, const SkDescriptor*, void *), 1687 void (*proc)(SkTypeface*, const SkScalerContextEffe cts&,
1688 const SkDescriptor*, void*),
1684 void* context) const { 1689 void* context) const {
1685 SkScalerContext::Rec rec; 1690 SkScalerContext::Rec rec;
1686 1691
1687 SkPathEffect* pe = this->getPathEffect(); 1692 SkPathEffect* pe = this->getPathEffect();
1688 SkMaskFilter* mf = this->getMaskFilter(); 1693 SkMaskFilter* mf = this->getMaskFilter();
1689 SkRasterizer* ra = this->getRasterizer(); 1694 SkRasterizer* ra = this->getRasterizer();
1690 1695
1691 SkWriteBuffer peBuffer, mfBuffer, raBuffer; 1696 SkWriteBuffer peBuffer, mfBuffer, raBuffer;
1692 size_t descSize = fill_out_rec(*this, &rec, 1697 size_t descSize = fill_out_rec(*this, &rec,
1693 surfaceProps, FakeGamma::On == fakeGamma, dev iceMatrix, 1698 surfaceProps, FakeGamma::On == fakeGamma, dev iceMatrix,
1694 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer); 1699 pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer);
1695 1700
1696 SkAutoDescriptor ad(descSize); 1701 SkAutoDescriptor ad(descSize);
1697 SkDescriptor* desc = ad.getDesc(); 1702 SkDescriptor* desc = ad.getDesc();
1698 1703
1699 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize); 1704 write_out_descriptor(desc, rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, descSize);
1700 1705
1701 SkASSERT(descSize == desc->getLength()); 1706 SkASSERT(descSize == desc->getLength());
1702 1707
1703 #ifdef TEST_DESC 1708 #ifdef TEST_DESC
1704 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize); 1709 test_desc(rec, pe, &peBuffer, mf, &mfBuffer, ra, &raBuffer, desc, descSize);
1705 #endif 1710 #endif
1706 1711
1707 proc(fTypeface.get(), desc, context); 1712 proc(fTypeface.get(), { pe, mf, ra }, desc, context);
1708 } 1713 }
1709 1714
1710 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps, 1715 SkGlyphCache* SkPaint::detachCache(const SkSurfaceProps* surfaceProps,
1711 FakeGamma fakeGamma, 1716 FakeGamma fakeGamma,
1712 const SkMatrix* deviceMatrix) const { 1717 const SkMatrix* deviceMatrix) const {
1713 SkGlyphCache* cache; 1718 SkGlyphCache* cache;
1714 this->descriptorProc(surfaceProps, fakeGamma, deviceMatrix, DetachDescProc, &cache); 1719 this->descriptorProc(surfaceProps, fakeGamma, deviceMatrix, DetachDescProc, &cache);
1715 return cache; 1720 return cache;
1716 } 1721 }
1717 1722
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2364 }
2360 2365
2361 uint32_t SkPaint::getHash() const { 2366 uint32_t SkPaint::getHash() const {
2362 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, 2367 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields,
2363 // so fBitfields should be 10 pointers and 6 32-bit values from the start. 2368 // so fBitfields should be 10 pointers and 6 32-bit values from the start.
2364 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t), 2369 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t),
2365 "SkPaint_notPackedTightly"); 2370 "SkPaint_notPackedTightly");
2366 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), 2371 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
2367 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); 2372 offsetof(SkPaint, fBitfields) + sizeof(fBitfields ));
2368 } 2373 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698