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

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

Issue 1872253004: Revert of Pass effects directly to fontcache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
« no previous file with comments | « src/core/SkScalerContext.h ('k') | src/core/SkTypeface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include "SkScalerContext.h" 9 #include "SkScalerContext.h"
10 #include "SkAutoPixmapStorage.h" 10 #include "SkAutoPixmapStorage.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 fRsbDelta = 0; 55 fRsbDelta = 0;
56 fLsbDelta = 0; 56 fLsbDelta = 0;
57 } 57 }
58 58
59 /////////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////////
60 60
61 #ifdef SK_DEBUG 61 #ifdef SK_DEBUG
62 #define DUMP_RECx 62 #define DUMP_RECx
63 #endif 63 #endif
64 64
65 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkScalerContextEffe cts& effects, 65 static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
66 const SkDescriptor* desc) 66 SkFlattenable::Type ft) {
67 SkFlattenable* obj = nullptr;
68 uint32_t len;
69 const void* data = desc->findEntry(tag, &len);
70
71 if (data) {
72 SkReadBuffer buffer(data, len);
73 obj = buffer.readFlattenable(ft);
74 SkASSERT(buffer.offset() == buffer.size());
75 }
76 return obj;
77 }
78
79 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
67 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullpt r))) 80 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullpt r)))
68 81
69 , fTypeface(sk_ref_sp(typeface)) 82 , fTypeface(SkRef(typeface))
70 , fPathEffect(sk_ref_sp(effects.fPathEffect)) 83 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_ SkDescriptorTag,
71 , fMaskFilter(sk_ref_sp(effects.fMaskFilter)) 84 SkFlattenable::kSkPathEffect_Type)) )
72 , fRasterizer(sk_ref_sp(effects.fRasterizer)) 85 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_ SkDescriptorTag,
86 SkFlattenable::kSkMaskFilter_Type)) )
87 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_ SkDescriptorTag,
88 SkFlattenable::kSkRasterizer_Type)) )
73 // Initialize based on our settings. Subclasses can also force this. 89 // Initialize based on our settings. Subclasses can also force this.
74 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || f Rasterizer != nullptr) 90 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || f Rasterizer != nullptr)
75 91
76 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask PreBlend(fRec)) 92 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask PreBlend(fRec))
77 , fPreBlendForFilter(fMaskFilter ? SkScalerContext::GetMaskPreBlend(fRec) 93 , fPreBlendForFilter(fMaskFilter ? SkScalerContext::GetMaskPreBlend(fRec)
78 : SkMaskGamma::PreBlend()) 94 : SkMaskGamma::PreBlend())
79 { 95 {
80 #ifdef DUMP_REC 96 #ifdef DUMP_REC
81 desc->assertChecksum(); 97 desc->assertChecksum();
82 SkDebugf("SkScalerContext checksum %x count %d length %d\n", 98 SkDebugf("SkScalerContext checksum %x count %d length %d\n",
83 desc->getChecksum(), desc->getCount(), desc->getLength()); 99 desc->getChecksum(), desc->getCount(), desc->getLength());
84 SkDebugf(" textsize %g prescale %g preskew %g post [%g %g %g %g]\n", 100 SkDebugf(" textsize %g prescale %g preskew %g post [%g %g %g %g]\n",
85 rec->fTextSize, rec->fPreScaleX, rec->fPreSkewX, rec->fPost2x2[0][0], 101 rec->fTextSize, rec->fPreScaleX, rec->fPreSkewX, rec->fPost2x2[0][0],
86 rec->fPost2x2[0][1], rec->fPost2x2[1][0], rec->fPost2x2[1][1]); 102 rec->fPost2x2[0][1], rec->fPost2x2[1][0], rec->fPost2x2[1][1]);
87 SkDebugf(" frame %g miter %g hints %d framefill %d format %d join %d cap %d \n", 103 SkDebugf(" frame %g miter %g hints %d framefill %d format %d join %d cap %d \n",
88 rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill, 104 rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill,
89 rec->fMaskFormat, rec->fStrokeJoin, rec->fStrokeCap); 105 rec->fMaskFormat, rec->fStrokeJoin, rec->fStrokeCap);
90 SkDebugf(" pathEffect %x maskFilter %x\n", 106 SkDebugf(" pathEffect %x maskFilter %x\n",
91 desc->findEntry(kPathEffect_SkDescriptorTag, nullptr), 107 desc->findEntry(kPathEffect_SkDescriptorTag, nullptr),
92 desc->findEntry(kMaskFilter_SkDescriptorTag, nullptr)); 108 desc->findEntry(kMaskFilter_SkDescriptorTag, nullptr));
93 #endif 109 #endif
94 } 110 }
95 111
96 SkScalerContext::~SkScalerContext() {} 112 SkScalerContext::~SkScalerContext() {
113 SkSafeUnref(fPathEffect);
114 SkSafeUnref(fMaskFilter);
115 SkSafeUnref(fRasterizer);
116 }
97 117
98 void SkScalerContext::getAdvance(SkGlyph* glyph) { 118 void SkScalerContext::getAdvance(SkGlyph* glyph) {
99 // mark us as just having a valid advance 119 // mark us as just having a valid advance
100 glyph->fMaskFormat = MASK_FORMAT_JUST_ADVANCE; 120 glyph->fMaskFormat = MASK_FORMAT_JUST_ADVANCE;
101 // we mark the format before making the call, in case the impl 121 // we mark the format before making the call, in case the impl
102 // internally ends up calling its generateMetrics, which is OK 122 // internally ends up calling its generateMetrics, which is OK
103 // albeit slower than strictly necessary 123 // albeit slower than strictly necessary
104 generateAdvance(glyph); 124 generateAdvance(glyph);
105 } 125 }
106 126
(...skipping 22 matching lines...) Expand all
129 if (fGenerateImageFromPath) { 149 if (fGenerateImageFromPath) {
130 SkPath devPath, fillPath; 150 SkPath devPath, fillPath;
131 SkMatrix fillToDevMatrix; 151 SkMatrix fillToDevMatrix;
132 152
133 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); 153 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
134 154
135 if (fRasterizer) { 155 if (fRasterizer) {
136 SkMask mask; 156 SkMask mask;
137 157
138 if (fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, 158 if (fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr,
139 fMaskFilter.get(), &mask, 159 fMaskFilter, &mask,
140 SkMask::kJustComputeBounds_CreateMode)) { 160 SkMask::kJustComputeBounds_CreateMode)) {
141 glyph->fLeft = mask.fBounds.fLeft; 161 glyph->fLeft = mask.fBounds.fLeft;
142 glyph->fTop = mask.fBounds.fTop; 162 glyph->fTop = mask.fBounds.fTop;
143 glyph->fWidth = SkToU16(mask.fBounds.width()); 163 glyph->fWidth = SkToU16(mask.fBounds.width());
144 glyph->fHeight = SkToU16(mask.fBounds.height()); 164 glyph->fHeight = SkToU16(mask.fBounds.height());
145 } else { 165 } else {
146 goto SK_ERROR; 166 goto SK_ERROR;
147 } 167 }
148 } else { 168 } else {
149 // just use devPath 169 // just use devPath
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 // If we are going to draw-from-path, then we cannot generate color, since 478 // If we are going to draw-from-path, then we cannot generate color, since
459 // the path only makes a mask. This case should have been caught up in 479 // the path only makes a mask. This case should have been caught up in
460 // generateMetrics(). 480 // generateMetrics().
461 SkASSERT(!fGenerateImageFromPath || 481 SkASSERT(!fGenerateImageFromPath ||
462 SkMask::kARGB32_Format != origGlyph.fMaskFormat); 482 SkMask::kARGB32_Format != origGlyph.fMaskFormat);
463 483
464 if (fMaskFilter) { // restore the prefilter bounds 484 if (fMaskFilter) { // restore the prefilter bounds
465 tmpGlyph.initGlyphIdFrom(origGlyph); 485 tmpGlyph.initGlyphIdFrom(origGlyph);
466 486
467 // need the original bounds, sans our maskfilter 487 // need the original bounds, sans our maskfilter
468 SkMaskFilter* mf = fMaskFilter.release(); // temp disable 488 SkMaskFilter* mf = fMaskFilter;
489 fMaskFilter = nullptr; // temp disable
469 this->getMetrics(&tmpGlyph); 490 this->getMetrics(&tmpGlyph);
470 fMaskFilter = sk_sp<SkMaskFilter>(mf); // restore 491 fMaskFilter = mf; // restore
471 492
472 // we need the prefilter bounds to be <= filter bounds 493 // we need the prefilter bounds to be <= filter bounds
473 SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); 494 SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth);
474 SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight); 495 SkASSERT(tmpGlyph.fHeight <= origGlyph.fHeight);
475 496
476 if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) { 497 if (tmpGlyph.fMaskFormat == origGlyph.fMaskFormat) {
477 tmpGlyph.fImage = origGlyph.fImage; 498 tmpGlyph.fImage = origGlyph.fImage;
478 } else { 499 } else {
479 tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize()); 500 tmpGlyphImageStorage.reset(tmpGlyph.computeImageSize());
480 tmpGlyph.fImage = tmpGlyphImageStorage.get(); 501 tmpGlyph.fImage = tmpGlyphImageStorage.get();
481 } 502 }
482 glyph = &tmpGlyph; 503 glyph = &tmpGlyph;
483 } 504 }
484 505
485 if (fGenerateImageFromPath) { 506 if (fGenerateImageFromPath) {
486 SkPath devPath, fillPath; 507 SkPath devPath, fillPath;
487 SkMatrix fillToDevMatrix; 508 SkMatrix fillToDevMatrix;
488 SkMask mask; 509 SkMask mask;
489 510
490 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix); 511 this->internalGetPath(*glyph, &fillPath, &devPath, &fillToDevMatrix);
491 glyph->toMask(&mask); 512 glyph->toMask(&mask);
492 513
493 if (fRasterizer) { 514 if (fRasterizer) {
494 mask.fFormat = SkMask::kA8_Format; 515 mask.fFormat = SkMask::kA8_Format;
495 sk_bzero(glyph->fImage, mask.computeImageSize()); 516 sk_bzero(glyph->fImage, mask.computeImageSize());
496 517
497 if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, 518 if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr,
498 fMaskFilter.get(), &mask, 519 fMaskFilter, &mask,
499 SkMask::kJustRenderImage_CreateMode)) { 520 SkMask::kJustRenderImage_CreateMode)) {
500 return; 521 return;
501 } 522 }
502 if (fPreBlend.isApplicable()) { 523 if (fPreBlend.isApplicable()) {
503 applyLUTToA8Mask(mask, fPreBlend.fG); 524 applyLUTToA8Mask(mask, fPreBlend.fG);
504 } 525 }
505 } else { 526 } else {
506 SkASSERT(SkMask::kARGB32_Format != mask.fFormat); 527 SkASSERT(SkMask::kARGB32_Format != mask.fFormat);
507 generateMask(mask, devPath, fPreBlend); 528 generateMask(mask, devPath, fPreBlend);
508 } 529 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 // The x axis is mapped onto the y axis. 844 // The x axis is mapped onto the y axis.
824 return kY_SkAxisAlignment; 845 return kY_SkAxisAlignment;
825 } 846 }
826 return kNone_SkAxisAlignment; 847 return kNone_SkAxisAlignment;
827 } 848 }
828 849
829 /////////////////////////////////////////////////////////////////////////////// 850 ///////////////////////////////////////////////////////////////////////////////
830 851
831 class SkScalerContext_Empty : public SkScalerContext { 852 class SkScalerContext_Empty : public SkScalerContext {
832 public: 853 public:
833 SkScalerContext_Empty(SkTypeface* typeface, const SkScalerContextEffects& ef fects, 854 SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc)
834 const SkDescriptor* desc) 855 : SkScalerContext(face, desc) {}
835 : SkScalerContext(typeface, effects, desc) {}
836 856
837 protected: 857 protected:
838 unsigned generateGlyphCount() override { 858 unsigned generateGlyphCount() override {
839 return 0; 859 return 0;
840 } 860 }
841 uint16_t generateCharToGlyph(SkUnichar uni) override { 861 uint16_t generateCharToGlyph(SkUnichar uni) override {
842 return 0; 862 return 0;
843 } 863 }
844 void generateAdvance(SkGlyph* glyph) override { 864 void generateAdvance(SkGlyph* glyph) override {
845 glyph->zeroMetrics(); 865 glyph->zeroMetrics();
846 } 866 }
847 void generateMetrics(SkGlyph* glyph) override { 867 void generateMetrics(SkGlyph* glyph) override {
848 glyph->zeroMetrics(); 868 glyph->zeroMetrics();
849 } 869 }
850 void generateImage(const SkGlyph& glyph) override {} 870 void generateImage(const SkGlyph& glyph) override {}
851 void generatePath(const SkGlyph& glyph, SkPath* path) override {} 871 void generatePath(const SkGlyph& glyph, SkPath* path) override {}
852 void generateFontMetrics(SkPaint::FontMetrics* metrics) override { 872 void generateFontMetrics(SkPaint::FontMetrics* metrics) override {
853 if (metrics) { 873 if (metrics) {
854 sk_bzero(metrics, sizeof(*metrics)); 874 sk_bzero(metrics, sizeof(*metrics));
855 } 875 }
856 } 876 }
857 }; 877 };
858 878
859 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); 879 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc);
860 880
861 SkScalerContext* SkTypeface::createScalerContext(const SkScalerContextEffects& e ffects, 881 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
862 const SkDescriptor* desc,
863 bool allowFailure) const { 882 bool allowFailure) const {
864 SkScalerContext* c = this->onCreateScalerContext(effects, desc); 883 SkScalerContext* c = this->onCreateScalerContext(desc);
865 884
866 if (!c && !allowFailure) { 885 if (!c && !allowFailure) {
867 c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), effects, de sc); 886 c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), desc);
868 } 887 }
869 return c; 888 return c;
870 } 889 }
OLDNEW
« no previous file with comments | « src/core/SkScalerContext.h ('k') | src/core/SkTypeface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698