aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-05-11 12:38:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-11 12:38:18 -0700
commit6296da736fbf40aae881650c239420f64e576c3f (patch)
tree5121ecf46ff7099d8eb66d2b2a4671d5ad94db89 /src
parentc8699321b924c1f284df93cb29b86000c1d73c0a (diff)
Move SkTypeface to sk_sp.
Diffstat (limited to 'src')
-rw-r--r--src/animator/SkDrawPaint.cpp2
-rw-r--r--src/animator/SkPaintPart.h3
-rw-r--r--src/core/SkFont.cpp35
-rw-r--r--src/core/SkPaint.cpp4
-rw-r--r--src/core/SkPictureData.cpp6
-rw-r--r--src/core/SkTextBlob.cpp4
-rw-r--r--src/core/SkTypeface.cpp45
-rw-r--r--src/core/SkTypefacePriv.h10
-rw-r--r--src/fonts/SkGScalerContext.cpp11
-rw-r--r--src/fonts/SkGScalerContext.h9
-rw-r--r--src/fonts/SkRandomScalerContext.cpp8
-rw-r--r--src/fonts/SkRandomScalerContext.h11
-rw-r--r--src/pdf/SkPDFFont.cpp2
-rw-r--r--src/ports/SkFontMgr_android.cpp5
-rw-r--r--src/svg/SkSVGDevice.cpp4
-rw-r--r--src/utils/SkLua.cpp9
-rw-r--r--src/utils/SkWhitelistTypefaces.cpp20
17 files changed, 83 insertions, 105 deletions
diff --git a/src/animator/SkDrawPaint.cpp b/src/animator/SkDrawPaint.cpp
index 1336ea2dc4..1026630eb1 100644
--- a/src/animator/SkDrawPaint.cpp
+++ b/src/animator/SkDrawPaint.cpp
@@ -259,7 +259,7 @@ void SkDrawPaint::setupPaint(SkPaint* paint) const {
if (typeface == nullptr)
paint->setTypeface(nullptr);
else if (typeface != (SkDrawTypeface*) -1)
- SkSafeUnref(paint->setTypeface(typeface->getTypeface()));
+ paint->setTypeface(typeface->getTypeface());
if (underline != -1)
paint->setUnderlineText(SkToBool(underline));
if (xfermode != -1)
diff --git a/src/animator/SkPaintPart.h b/src/animator/SkPaintPart.h
index a7e28ed3e2..5d94f049e8 100644
--- a/src/animator/SkPaintPart.h
+++ b/src/animator/SkPaintPart.h
@@ -62,8 +62,7 @@ class SkDrawTypeface : public SkPaintPart {
#ifdef SK_DUMP_ENABLED
void dump(SkAnimateMaker *) override;
#endif
- SkTypeface* getTypeface() {
- return SkTypeface::CreateFromName(fontName.c_str(), style); }
+ sk_sp<SkTypeface> getTypeface() { return SkTypeface::MakeFromName(fontName.c_str(), style); }
protected:
bool add() override;
SkString fontName;
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index c39cc185d3..1300011ec4 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -9,13 +9,9 @@
#include "SkTypeface.h"
#include "SkUtils.h"
-static SkTypeface* ref_or_default(SkTypeface* face) {
- return face ? SkRef(face) : SkTypeface::RefDefault();
-}
-
-SkFont::SkFont(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
+SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt,
uint32_t flags)
- : fTypeface(ref_or_default(face))
+ : fTypeface(face ? std::move(face) : SkTypeface::MakeDefault())
, fSize(size)
, fScaleX(scaleX)
, fSkewX(skewX)
@@ -28,8 +24,8 @@ SkFont::SkFont(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX,
SkASSERT(0 == (flags & ~kAllFlags));
}
-SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX,
- MaskType mt, uint32_t flags) {
+sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX,
+ MaskType mt, uint32_t flags) {
if (size <= 0 || !SkScalarIsFinite(size)) {
return nullptr;
}
@@ -40,24 +36,20 @@ SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScala
return nullptr;
}
flags &= kAllFlags;
- return new SkFont(face, size, scaleX, skewX, mt, flags);
+ return sk_sp<SkFont>(new SkFont(std::move(face), size, scaleX, skewX, mt, flags));
}
-SkFont* SkFont::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t flags) {
- return SkFont::Create(face, size, 1, 0, mt, flags);
+sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, MaskType mt, uint32_t flags) {
+ return SkFont::Make(std::move(face), size, 1, 0, mt, flags);
}
-SkFont* SkFont::cloneWithSize(SkScalar newSize) const {
- return SkFont::Create(this->getTypeface(), newSize, this->getScaleX(), this->getSkewX(),
- this->getMaskType(), this->getFlags());
+sk_sp<SkFont> SkFont::makeWithSize(SkScalar newSize) const {
+ return SkFont::Make(sk_ref_sp(this->getTypeface()), newSize, this->getScaleX(),
+ this->getSkewX(), this->getMaskType(), this->getFlags());
}
///////////////////////////////////////////////////////////////////////////////////////////////////
-SkFont::~SkFont() {
- SkSafeUnref(fTypeface);
-}
-
int SkFont::textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
uint16_t glyphs[], int maxGlyphCount) const {
if (0 == byteLength) {
@@ -118,7 +110,7 @@ SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding
#include "SkPaint.h"
-SkFont* SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
+sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
uint32_t flags = 0;
if (paint.isVerticalText()) {
flags |= kVertical_Flag;
@@ -150,7 +142,6 @@ SkFont* SkFont::Testing_CreateFromPaint(const SkPaint& paint) {
maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType;
}
- return Create(paint.getTypeface(),
- paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX(),
- maskType, flags);
+ return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(),
+ paint.getTextSkewX(), maskType, flags);
}
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 67bbda1665..25b6aec1ec 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -369,7 +369,9 @@ void SkPaint::setLooper(sk_sp<SkDrawLooper> looper) { fLooper = std::move(looper
this->f##Field.reset(SkSafeRef(f)); \
return f; \
}
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
SET_PTR(Typeface)
+#endif
#ifdef SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR
SET_PTR(Rasterizer)
#endif
@@ -1896,7 +1898,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
if (flatFlags & kHasTypeface_FlatFlag) {
- this->setTypeface(buffer.readTypeface());
+ this->setTypeface(sk_ref_sp(buffer.readTypeface()));
} else {
this->setTypeface(nullptr);
}
diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp
index ed32c6c029..873c0c4a1d 100644
--- a/src/core/SkPictureData.cpp
+++ b/src/core/SkPictureData.cpp
@@ -405,13 +405,13 @@ bool SkPictureData::parseStreamTag(SkStream* stream,
const int count = SkToInt(size);
fTFPlayback.setCount(count);
for (int i = 0; i < count; i++) {
- SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream));
+ sk_sp<SkTypeface> tf(SkTypeface::MakeDeserialize(stream));
if (!tf.get()) { // failed to deserialize
// fTFPlayback asserts it never has a null, so we plop in
// the default here.
- tf.reset(SkTypeface::RefDefault());
+ tf = SkTypeface::MakeDefault();
}
- fTFPlayback.set(i, tf);
+ fTFPlayback.set(i, tf.get());
}
} break;
case SK_PICT_PICTURE_TAG: {
diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp
index 463312aa6d..1cbb2b6d6d 100644
--- a/src/core/SkTextBlob.cpp
+++ b/src/core/SkTextBlob.cpp
@@ -27,7 +27,7 @@ public:
void applyToPaint(SkPaint* paint) const {
paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- paint->setTypeface(fTypeface.get());
+ paint->setTypeface(fTypeface);
paint->setTextSize(fSize);
paint->setTextScaleX(fScaleX);
paint->setTextSkewX(fSkewX);
@@ -73,7 +73,7 @@ private:
// Keep this SkAutoTUnref off the first position, to avoid interfering with SkNoncopyable
// empty baseclass optimization (http://code.google.com/p/skia/issues/detail?id=3694).
- SkAutoTUnref<SkTypeface> fTypeface;
+ sk_sp<SkTypeface> fTypeface;
SkScalar fSkewX;
static_assert(SkPaint::kAlignCount < 4, "insufficient_align_bits");
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 75bb05c2b1..3c15878f73 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -27,9 +27,9 @@ extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
#define SK_TYPEFACE_DELEGATE nullptr
#endif
-SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr;
+sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr;
void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE_DELEGATE;
-SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
+sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr;
///////////////////////////////////////////////////////////////////////////////
@@ -98,8 +98,8 @@ SkTypeface* SkTypeface::GetDefaultTypeface(Style style) {
return defaults[style];
}
-SkTypeface* SkTypeface::RefDefault(Style style) {
- return SkRef(GetDefaultTypeface(style));
+sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) {
+ return sk_ref_sp(GetDefaultTypeface(style));
}
uint32_t SkTypeface::UniqueID(const SkTypeface* face) {
@@ -115,47 +115,46 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) {
///////////////////////////////////////////////////////////////////////////////
-SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) {
+sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) {
if (gCreateTypefaceDelegate) {
- SkTypeface* result = (*gCreateTypefaceDelegate)(name, style);
+ sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style);
if (result) {
return result;
}
}
if (nullptr == name) {
- return RefDefault(style);
+ return MakeDefault(style);
}
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style));
+ return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)));
}
-SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) {
+sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) {
if (!family) {
- return SkTypeface::RefDefault(s);
+ return SkTypeface::MakeDefault(s);
}
if (family->style() == s) {
- family->ref();
- return const_cast<SkTypeface*>(family);
+ return sk_ref_sp(family);
}
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s));
+ return sk_sp<SkTypeface>(fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s)));
}
-SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) {
+sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->createFromStream(stream, index);
+ return sk_sp<SkTypeface>(fm->createFromStream(stream, index));
}
-SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) {
+sk_sp<SkTypeface> SkTypeface::MakeFromFontData(SkFontData* data) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->createFromFontData(data);
+ return sk_sp<SkTypeface>(fm->createFromFontData(data));
}
-SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) {
+sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) {
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->createFromFile(path, index);
+ return sk_sp<SkTypeface>(fm->createFromFile(path, index));
}
///////////////////////////////////////////////////////////////////////////////
@@ -176,7 +175,7 @@ void SkTypeface::serialize(SkWStream* wstream) const {
desc.serialize(wstream);
}
-SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
+sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) {
if (gDeserializeTypefaceDelegate) {
return (*gDeserializeTypefaceDelegate)(stream);
}
@@ -188,12 +187,12 @@ SkTypeface* SkTypeface::Deserialize(SkStream* stream) {
SkFontData* data = desc.detachFontData();
if (data) {
- SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
if (typeface) {
return typeface;
}
}
- return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle());
+ return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle());
}
///////////////////////////////////////////////////////////////////////////////
@@ -335,7 +334,7 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const {
const SkScalar invTextSize = 1 / textSize;
SkPaint paint;
- paint.setTypeface(const_cast<SkTypeface*>(this));
+ paint.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this)));
paint.setTextSize(textSize);
paint.setLinearText(true);
diff --git a/src/core/SkTypefacePriv.h b/src/core/SkTypefacePriv.h
index dc993d0890..f8d7e63efd 100644
--- a/src/core/SkTypefacePriv.h
+++ b/src/core/SkTypefacePriv.h
@@ -16,23 +16,23 @@
* If the parameter is non-null, it will be ref'd and returned, otherwise
* it will be the default typeface.
*/
-static inline SkTypeface* ref_or_default(SkTypeface* face) {
- return face ? SkRef(face) : SkTypeface::RefDefault();
+static inline sk_sp<SkTypeface> ref_or_default(SkTypeface* face) {
+ return face ? sk_ref_sp(face) : SkTypeface::MakeDefault();
}
/**
* Always resolves to a non-null typeface, either the value passed to its
* constructor, or the default typeface if null was passed.
*/
-class SkAutoResolveDefaultTypeface : public SkAutoTUnref<SkTypeface> {
+class SkAutoResolveDefaultTypeface : public sk_sp<SkTypeface> {
public:
- SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::RefDefault()) {}
+ SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::MakeDefault()) {}
SkAutoResolveDefaultTypeface(SkTypeface* face)
: INHERITED(ref_or_default(face)) {}
private:
- typedef SkAutoTUnref<SkTypeface> INHERITED;
+ typedef sk_sp<SkTypeface> INHERITED;
};
#endif
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp
index 0a9601bd7e..1d34536cbe 100644
--- a/src/fonts/SkGScalerContext.cpp
+++ b/src/fonts/SkGScalerContext.cpp
@@ -151,14 +151,11 @@ void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
#include "SkTypefaceCache.h"
-SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint)
+SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint)
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
- , fProxy(SkRef(proxy))
- , fPaint(paint) {}
-
-SkGTypeface::~SkGTypeface() {
- fProxy->unref();
-}
+ , fProxy(std::move(proxy))
+ , fPaint(paint)
+{}
SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h
index 69d02ddf11..3eb25a81da 100644
--- a/src/fonts/SkGScalerContext.h
+++ b/src/fonts/SkGScalerContext.h
@@ -13,10 +13,9 @@
class SkGTypeface : public SkTypeface {
public:
- SkGTypeface(SkTypeface* proxy, const SkPaint&);
- virtual ~SkGTypeface();
+ SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint&);
- SkTypeface* proxy() const { return fProxy; }
+ SkTypeface* proxy() const { return fProxy.get(); }
const SkPaint& paint() const { return fPaint; }
protected:
@@ -43,8 +42,8 @@ protected:
size_t length, void* data) const override;
private:
- SkTypeface* fProxy;
- SkPaint fPaint;
+ sk_sp<SkTypeface> fProxy;
+ SkPaint fPaint;
};
#endif
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index 245052053e..6d3718cbef 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -190,16 +190,12 @@ void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) {
#include "SkTypefaceCache.h"
-SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt)
+SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt)
: SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
- , fProxy(SkRef(proxy))
+ , fProxy(std::move(proxy))
, fPaint(paint)
, fFakeIt(fakeIt) {}
-SkRandomTypeface::~SkRandomTypeface() {
- fProxy->unref();
-}
-
SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), effects, desc, fFakeIt);
diff --git a/src/fonts/SkRandomScalerContext.h b/src/fonts/SkRandomScalerContext.h
index 0e08f4b1ae..076689d93a 100644
--- a/src/fonts/SkRandomScalerContext.h
+++ b/src/fonts/SkRandomScalerContext.h
@@ -18,10 +18,9 @@
class SkRandomTypeface : public SkTypeface {
public:
- SkRandomTypeface(SkTypeface* proxy, const SkPaint&, bool fakeit);
- virtual ~SkRandomTypeface();
+ SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint&, bool fakeit);
- SkTypeface* proxy() const { return fProxy; }
+ SkTypeface* proxy() const { return fProxy.get(); }
const SkPaint& paint() const { return fPaint; }
protected:
@@ -48,9 +47,9 @@ protected:
size_t length, void* data) const override;
private:
- SkTypeface* fProxy;
- SkPaint fPaint;
- bool fFakeIt;
+ sk_sp<SkTypeface> fProxy;
+ SkPaint fPaint;
+ bool fFakeIt;
};
#endif
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 7a66bcd1e9..97be32c41d 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -1327,7 +1327,7 @@ SkPDFType3Font::~SkPDFType3Font() {}
bool SkPDFType3Font::populate(uint16_t glyphID) {
SkPaint paint;
- paint.setTypeface(typeface());
+ paint.setTypeface(sk_ref_sp(this->typeface()));
paint.setTextSize(1000);
const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
SkAutoGlyphCache autoCache(paint, &props, nullptr);
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 4aea047cde..3e6e0da18a 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -371,7 +371,7 @@ protected:
{
for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
- SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style));
+ sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style));
if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) {
continue;
@@ -387,9 +387,6 @@ protected:
uint16_t glyphID;
paint.textToGlyphs(&character, sizeof(character), &glyphID);
- if (glyphID != 0) {
- return face.release();
- }
}
return nullptr;
}
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index 4c679dfee7..f0805b5432 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -534,8 +534,8 @@ void SkSVGDevice::AutoElement::addTextAttributes(const SkPaint& paint) {
SkString familyName;
SkTHashSet<SkString> familySet;
- SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ?
- SkRef(paint.getTypeface()) : SkTypeface::RefDefault());
+ sk_sp<const SkTypeface> tface(paint.getTypeface() ?
+ sk_ref_sp(paint.getTypeface()) : SkTypeface::MakeDefault());
SkASSERT(tface);
SkTypeface::Style style = tface->style();
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index 886f3d4ffd..4409e477e5 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -925,7 +925,7 @@ static int lpaint_getTypeface(lua_State* L) {
}
static int lpaint_setTypeface(lua_State* L) {
- get_obj<SkPaint>(L, 1)->setTypeface(get_ref<SkTypeface>(L, 2));
+ get_obj<SkPaint>(L, 1)->setTypeface(sk_ref_sp(get_ref<SkTypeface>(L, 2)));
return 0;
}
@@ -2049,13 +2049,12 @@ static int lsk_newTypeface(lua_State* L) {
}
}
- SkTypeface* face = SkTypeface::CreateFromName(name,
- (SkTypeface::Style)style);
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, (SkTypeface::Style)style));
// SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt());
if (nullptr == face) {
- face = SkTypeface::RefDefault();
+ face = SkTypeface::MakeDefault();
}
- push_ref(L, face)->unref();
+ push_ref(L, std::move(face));
return 1;
}
diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp
index 66d32188a0..3368178769 100644
--- a/src/utils/SkWhitelistTypefaces.cpp
+++ b/src/utils/SkWhitelistTypefaces.cpp
@@ -18,7 +18,7 @@
#define WHITELIST_DEBUG 0
extern void WhitelistSerializeTypeface(const SkTypeface*, SkWStream* );
-extern SkTypeface* WhitelistDeserializeTypeface(SkStream* );
+sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* );
extern bool CheckChecksums();
extern bool GenerateChecksums();
@@ -32,8 +32,8 @@ static bool font_name_is_local(const char* fontName, SkTypeface::Style style) {
if (!strcmp(fontName, "DejaVu Sans")) {
return true;
}
- SkTypeface* defaultFace = SkTypeface::CreateFromName(nullptr, style);
- SkTypeface* foundFace = SkTypeface::CreateFromName(fontName, style);
+ sk_sp<SkTypeface> defaultFace(SkTypeface::MakeFromName(nullptr, style));
+ sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(fontName, style));
return defaultFace != foundFace;
}
@@ -183,7 +183,7 @@ void WhitelistSerializeTypeface(const SkTypeface* tf, SkWStream* wstream) {
serialize_sub(fontName, tf->style(), wstream);
}
-SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) {
+sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) {
SkFontDescriptor desc;
if (!SkFontDescriptor::Deserialize(stream, &desc)) {
return nullptr;
@@ -191,7 +191,7 @@ SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) {
SkFontData* data = desc.detachFontData();
if (data) {
- SkTypeface* typeface = SkTypeface::CreateFromFontData(data);
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data));
if (typeface) {
return typeface;
}
@@ -200,14 +200,14 @@ SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) {
if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) {
familyName += sizeof(SUBNAME_PREFIX) - 1;
}
- return SkTypeface::CreateFromName(familyName, desc.getStyle());
+ return SkTypeface::MakeFromName(familyName, desc.getStyle());
}
bool CheckChecksums() {
for (int i = 0; i < whitelistCount; ++i) {
const char* fontName = whitelist[i].fFontName;
- SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal);
- uint32_t checksum = compute_checksum(tf);
+ sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal));
+ uint32_t checksum = compute_checksum(tf.get());
if (whitelist[i].fChecksum != checksum) {
return false;
}
@@ -261,8 +261,8 @@ bool GenerateChecksums() {
sk_fwrite(line.c_str(), line.size(), file);
for (int i = 0; i < whitelistCount; ++i) {
const char* fontName = whitelist[i].fFontName;
- SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal);
- uint32_t checksum = compute_checksum(tf);
+ sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal));
+ uint32_t checksum = compute_checksum(tf.get());
line.printf(checksumEntry, fontName, checksum);
sk_fwrite(line.c_str(), line.size(), file);
}