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