OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkScalerContext.h" | 10 #include "SkScalerContext.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 const void* data = desc->findEntry(tag, &len); | 68 const void* data = desc->findEntry(tag, &len); |
69 | 69 |
70 if (data) { | 70 if (data) { |
71 SkOrderedReadBuffer buffer(data, len); | 71 SkOrderedReadBuffer buffer(data, len); |
72 obj = buffer.readFlattenable(); | 72 obj = buffer.readFlattenable(); |
73 SkASSERT(buffer.offset() == buffer.size()); | 73 SkASSERT(buffer.offset() == buffer.size()); |
74 } | 74 } |
75 return obj; | 75 return obj; |
76 } | 76 } |
77 | 77 |
78 SkScalerContext::SkScalerContext(const SkDescriptor* desc) | 78 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc) |
79 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)) ) | 79 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)) ) |
80 | 80 |
81 , fBaseGlyphCount(0) | 81 , fBaseGlyphCount(0) |
82 | 82 , fTypeface(SkRef(typeface)) |
bungeman-skia
2013/03/15 16:12:44
fTypeface is a pointer, not an SkAutoTUnref, so th
reed1
2013/03/15 17:46:44
Not sure I agree that pointers should not be initi
| |
83 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_ SkDescriptorTag))) | 83 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_ SkDescriptorTag))) |
84 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_ SkDescriptorTag))) | 84 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_ SkDescriptorTag))) |
85 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_ SkDescriptorTag))) | 85 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_ SkDescriptorTag))) |
86 | 86 |
87 // Initialize based on our settings. Subclasses can also force this. | 87 // Initialize based on our settings. Subclasses can also force this. |
88 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRas terizer != NULL) | 88 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRas terizer != NULL) |
89 | 89 |
90 , fNextContext(NULL) | 90 , fNextContext(NULL) |
91 | 91 |
92 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask PreBlend(fRec)) | 92 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask PreBlend(fRec)) |
(...skipping 15 matching lines...) Expand all Loading... | |
108 desc->findEntry(kMaskFilter_SkDescriptorTag, NULL)); | 108 desc->findEntry(kMaskFilter_SkDescriptorTag, NULL)); |
109 #endif | 109 #endif |
110 } | 110 } |
111 | 111 |
112 SkScalerContext::~SkScalerContext() { | 112 SkScalerContext::~SkScalerContext() { |
113 SkDELETE(fNextContext); | 113 SkDELETE(fNextContext); |
114 | 114 |
115 SkSafeUnref(fPathEffect); | 115 SkSafeUnref(fPathEffect); |
116 SkSafeUnref(fMaskFilter); | 116 SkSafeUnref(fMaskFilter); |
117 SkSafeUnref(fRasterizer); | 117 SkSafeUnref(fRasterizer); |
118 fTypeface->unref(); | |
bungeman-skia
2013/03/15 16:12:44
Remove if fTypeface is changed to an SkAutoTUnref.
reed1
2013/03/15 17:46:44
Done.
| |
118 } | 119 } |
119 | 120 |
120 static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) { | 121 static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) { |
121 // fonthost will determine the next possible font to search, based | 122 // fonthost will determine the next possible font to search, based |
122 // on the current font in fRec. It will return NULL if ctx is our | 123 // on the current font in fRec. It will return NULL if ctx is our |
123 // last font that can be searched (i.e. ultimate fallback font) | 124 // last font that can be searched (i.e. ultimate fallback font) |
124 uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID, rec.fOrigFontI D); | 125 SkTypeface* newFace = SkFontHost::NextLogicalTypeface(rec.fFontID, rec.fOrig FontID); |
bungeman-skia
2013/03/15 16:12:44
NextLogicalTypeface returns a ref?
reed1
2013/03/15 17:46:44
rewrote dox
| |
125 if (0 == newFontID) { | 126 if (0 == newFace) { |
126 return NULL; | 127 return NULL; |
127 } | 128 } |
129 | |
130 SkAutoTUnref<SkTypeface> aur(newFace); | |
131 uint32_t newFontID = newFace->uniqueID(); | |
128 | 132 |
129 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 133 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
130 SkDescriptor* desc = ad.getDesc(); | 134 SkDescriptor* desc = ad.getDesc(); |
131 | 135 |
132 desc->init(); | 136 desc->init(); |
133 SkScalerContext::Rec* newRec = | 137 SkScalerContext::Rec* newRec = |
134 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, | 138 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, |
135 sizeof(rec), &rec); | 139 sizeof(rec), &rec); |
136 newRec->fFontID = newFontID; | 140 newRec->fFontID = newFontID; |
137 desc->computeChecksum(); | 141 desc->computeChecksum(); |
138 | 142 |
139 return SkFontHost::CreateScalerContext(desc); | 143 return newFace->createScalerContext(desc); |
140 } | 144 } |
141 | 145 |
142 /* Return the next context, creating it if its not already created, but return | 146 /* Return the next context, creating it if its not already created, but return |
143 NULL if the fonthost says there are no more fonts to fallback to. | 147 NULL if the fonthost says there are no more fonts to fallback to. |
144 */ | 148 */ |
145 SkScalerContext* SkScalerContext::getNextContext() { | 149 SkScalerContext* SkScalerContext::getNextContext() { |
146 SkScalerContext* next = fNextContext; | 150 SkScalerContext* next = fNextContext; |
147 // if next is null, then either it isn't cached yet, or we're at the | 151 // if next is null, then either it isn't cached yet, or we're at the |
148 // end of our possible chain | 152 // end of our possible chain |
149 if (NULL == next) { | 153 if (NULL == next) { |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 737 } |
734 return kNone_SkAxisAlignment; | 738 return kNone_SkAxisAlignment; |
735 } | 739 } |
736 | 740 |
737 /////////////////////////////////////////////////////////////////////////////// | 741 /////////////////////////////////////////////////////////////////////////////// |
738 | 742 |
739 #include "SkFontHost.h" | 743 #include "SkFontHost.h" |
740 | 744 |
741 class SkScalerContext_Empty : public SkScalerContext { | 745 class SkScalerContext_Empty : public SkScalerContext { |
742 public: | 746 public: |
743 SkScalerContext_Empty(const SkDescriptor* desc) : SkScalerContext(desc) {} | 747 SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc) |
748 : SkScalerContext(face, desc) {} | |
744 | 749 |
745 protected: | 750 protected: |
746 virtual unsigned generateGlyphCount() SK_OVERRIDE { | 751 virtual unsigned generateGlyphCount() SK_OVERRIDE { |
747 return 0; | 752 return 0; |
748 } | 753 } |
749 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { | 754 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { |
750 return 0; | 755 return 0; |
751 } | 756 } |
752 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { | 757 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { |
753 glyph->zeroMetrics(); | 758 glyph->zeroMetrics(); |
754 } | 759 } |
755 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE { | 760 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE { |
756 glyph->zeroMetrics(); | 761 glyph->zeroMetrics(); |
757 } | 762 } |
758 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE {} | 763 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE {} |
759 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE {} | 764 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE {} |
760 virtual void generateFontMetrics(SkPaint::FontMetrics* mx, | 765 virtual void generateFontMetrics(SkPaint::FontMetrics* mx, |
761 SkPaint::FontMetrics* my) SK_OVERRIDE { | 766 SkPaint::FontMetrics* my) SK_OVERRIDE { |
762 if (mx) { | 767 if (mx) { |
763 sk_bzero(mx, sizeof(*mx)); | 768 sk_bzero(mx, sizeof(*mx)); |
764 } | 769 } |
765 if (my) { | 770 if (my) { |
766 sk_bzero(my, sizeof(*my)); | 771 sk_bzero(my, sizeof(*my)); |
767 } | 772 } |
768 } | 773 } |
769 }; | 774 }; |
770 | 775 |
771 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); | 776 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); |
772 | 777 |
773 SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { | 778 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) { |
774 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); | 779 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); |
775 if (NULL == c) { | 780 if (NULL == c) { |
776 c = SkFontHost::CreateScalerContext(desc); | 781 c = this->onCreateScalerContext(desc); |
777 } | 782 } |
778 if (NULL == c) { | 783 if (NULL == c) { |
779 c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); | 784 c = SkNEW_ARGS(SkScalerContext_Empty, (this, desc)); |
bungeman-skia
2013/03/15 16:12:44
Since all Empty do (almost) the same thing, should
reed1
2013/03/15 17:46:44
1. This case is incredibly rare
2. SkScalerContext
| |
780 } | 785 } |
781 return c; | 786 return c; |
782 } | 787 } |
OLD | NEW |