Index: src/core/SkScalerContext.cpp |
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp |
index cf4098bbdda9ccc07358d55415b6693f883e4aa8..ad753dfd21d060260b43cf2f1f2b5076d389fe0f 100644 |
--- a/src/core/SkScalerContext.cpp |
+++ b/src/core/SkScalerContext.cpp |
@@ -62,30 +62,14 @@ void SkGlyph::zeroMetrics() { |
#define DUMP_RECx |
#endif |
-static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag, |
- SkFlattenable::Type ft) { |
- SkFlattenable* obj = nullptr; |
- uint32_t len; |
- const void* data = desc->findEntry(tag, &len); |
- |
- if (data) { |
- SkReadBuffer buffer(data, len); |
- obj = buffer.readFlattenable(ft); |
- SkASSERT(buffer.offset() == buffer.size()); |
- } |
- return obj; |
-} |
- |
-SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc) |
+SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkScalerContextEffects& effects, |
+ const SkDescriptor* desc) |
: fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, nullptr))) |
- , fTypeface(SkRef(typeface)) |
- , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_SkDescriptorTag, |
- SkFlattenable::kSkPathEffect_Type))) |
- , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_SkDescriptorTag, |
- SkFlattenable::kSkMaskFilter_Type))) |
- , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_SkDescriptorTag, |
- SkFlattenable::kSkRasterizer_Type))) |
+ , fTypeface(sk_ref_sp(typeface)) |
+ , fPathEffect(sk_ref_sp(effects.fPathEffect)) |
+ , fMaskFilter(sk_ref_sp(effects.fMaskFilter)) |
+ , fRasterizer(sk_ref_sp(effects.fRasterizer)) |
// Initialize based on our settings. Subclasses can also force this. |
, fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != nullptr || fRasterizer != nullptr) |
@@ -109,11 +93,7 @@ SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc) |
#endif |
} |
-SkScalerContext::~SkScalerContext() { |
- SkSafeUnref(fPathEffect); |
- SkSafeUnref(fMaskFilter); |
- SkSafeUnref(fRasterizer); |
-} |
+SkScalerContext::~SkScalerContext() {} |
void SkScalerContext::getAdvance(SkGlyph* glyph) { |
// mark us as just having a valid advance |
@@ -156,7 +136,7 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) { |
SkMask mask; |
if (fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, |
- fMaskFilter, &mask, |
+ fMaskFilter.get(), &mask, |
SkMask::kJustComputeBounds_CreateMode)) { |
glyph->fLeft = mask.fBounds.fLeft; |
glyph->fTop = mask.fBounds.fTop; |
@@ -485,10 +465,9 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) { |
tmpGlyph.initGlyphIdFrom(origGlyph); |
// need the original bounds, sans our maskfilter |
- SkMaskFilter* mf = fMaskFilter; |
- fMaskFilter = nullptr; // temp disable |
+ SkMaskFilter* mf = fMaskFilter.release(); // temp disable |
this->getMetrics(&tmpGlyph); |
- fMaskFilter = mf; // restore |
+ fMaskFilter = sk_sp<SkMaskFilter>(mf); // restore |
// we need the prefilter bounds to be <= filter bounds |
SkASSERT(tmpGlyph.fWidth <= origGlyph.fWidth); |
@@ -516,7 +495,7 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) { |
sk_bzero(glyph->fImage, mask.computeImageSize()); |
if (!fRasterizer->rasterize(fillPath, fillToDevMatrix, nullptr, |
- fMaskFilter, &mask, |
+ fMaskFilter.get(), &mask, |
SkMask::kJustRenderImage_CreateMode)) { |
return; |
} |
@@ -851,8 +830,9 @@ SkAxisAlignment SkScalerContext::computeAxisAlignmentForHText() { |
class SkScalerContext_Empty : public SkScalerContext { |
public: |
- SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc) |
- : SkScalerContext(face, desc) {} |
+ SkScalerContext_Empty(SkTypeface* typeface, const SkScalerContextEffects& effects, |
+ const SkDescriptor* desc) |
+ : SkScalerContext(typeface, effects, desc) {} |
protected: |
unsigned generateGlyphCount() override { |
@@ -878,12 +858,13 @@ protected: |
extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); |
-SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, |
+SkScalerContext* SkTypeface::createScalerContext(const SkScalerContextEffects& effects, |
+ const SkDescriptor* desc, |
bool allowFailure) const { |
- SkScalerContext* c = this->onCreateScalerContext(desc); |
+ SkScalerContext* c = this->onCreateScalerContext(effects, desc); |
if (!c && !allowFailure) { |
- c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), desc); |
+ c = new SkScalerContext_Empty(const_cast<SkTypeface*>(this), effects, desc); |
} |
return c; |
} |