aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-05-12 10:09:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-12 10:09:31 -0700
commit13b9c95295f4c5732e34574789e721a6bc08f7b4 (patch)
treec3ef0aa2af9890c03cb79968f32166af39fba9ba
parent40d21de8b6620d724f34bdc85af1dcb593d33fe0 (diff)
Move SkTypeface to sk_sp.
-rw-r--r--bench/CmapBench.cpp2
-rw-r--r--bench/SkGlyphCacheBench.cpp9
-rw-r--r--bench/TextBench.cpp4
-rw-r--r--bench/TextBlobBench.cpp12
-rw-r--r--dm/DM.cpp4
-rw-r--r--fuzz/FilterFuzz.cpp4
-rw-r--r--gm/coloremoji.cpp6
-rw-r--r--gm/colortype.cpp17
-rw-r--r--gm/colortypexfermode.cpp19
-rw-r--r--gm/dftext.cpp4
-rw-r--r--gm/fontcache.cpp12
-rw-r--r--gm/fontmgr.cpp20
-rw-r--r--gm/fontscalerdistortable.cpp5
-rw-r--r--gm/gammatext.cpp11
-rw-r--r--gm/mixedtextblobs.cpp8
-rw-r--r--gm/pdf_never_embed.cpp11
-rw-r--r--gm/poly2poly.cpp4
-rw-r--r--gm/textblob.cpp8
-rw-r--r--gm/textblobmixedsizes.cpp3
-rw-r--r--gm/textblobrandomfont.cpp15
-rw-r--r--gm/typeface.cpp10
-rw-r--r--gm/variedtext.cpp28
-rw-r--r--gm/verttext2.cpp22
-rw-r--r--gyp/skia_for_android_framework_defines.gypi1
-rw-r--r--include/core/SkFont.h18
-rw-r--r--include/core/SkPaint.h4
-rw-r--r--include/core/SkTypeface.h87
-rw-r--r--include/ports/SkFontConfigInterface.h9
-rw-r--r--public.bzl1
-rw-r--r--samplecode/ClockFaceView.cpp11
-rw-r--r--samplecode/SampleAll.cpp3
-rwxr-xr-xsamplecode/SampleAnimatedText.cpp2
-rw-r--r--samplecode/SampleApp.cpp3
-rw-r--r--samplecode/SampleApp.h2
-rw-r--r--samplecode/SampleFilterFuzz.cpp5
-rw-r--r--samplecode/SampleFontScalerTest.cpp13
-rw-r--r--samplecode/SampleSlides.cpp2
-rw-r--r--samplecode/SampleText.cpp2
-rw-r--r--samplecode/SampleXfermodesBlur.cpp7
-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.cpp14
-rw-r--r--src/svg/SkSVGDevice.cpp4
-rw-r--r--src/utils/SkLua.cpp9
-rw-r--r--src/utils/SkWhitelistTypefaces.cpp20
-rw-r--r--tests/FontHostStreamTest.cpp19
-rw-r--r--tests/FontHostTest.cpp27
-rw-r--r--tests/FontMgrTest.cpp12
-rw-r--r--tests/FontObjTest.cpp7
-rw-r--r--tests/PDFPrimitivesTest.cpp2
-rw-r--r--tests/PaintTest.cpp4
-rw-r--r--tests/PictureTest.cpp2
-rw-r--r--tests/SerializationTest.cpp12
-rw-r--r--tests/TextBlobCacheTest.cpp5
-rw-r--r--tests/TextBlobTest.cpp4
-rw-r--r--tests/TypefaceTest.cpp8
-rw-r--r--tools/Resources.cpp4
-rw-r--r--tools/Resources.h2
-rw-r--r--tools/debugger/SkDrawCommand.cpp3
-rw-r--r--tools/sk_tool_utils.cpp18
-rw-r--r--tools/sk_tool_utils.h6
-rw-r--r--tools/sk_tool_utils_font.cpp7
-rw-r--r--tools/using_skia_and_harfbuzz.cpp4
74 files changed, 331 insertions, 420 deletions
diff --git a/bench/CmapBench.cpp b/bench/CmapBench.cpp
index a2fb5065f4..49e89bec8c 100644
--- a/bench/CmapBench.cpp
+++ b/bench/CmapBench.cpp
@@ -77,7 +77,7 @@ public:
// we're jamming values into utf8, so we must keep it legal utf8
fText[i] = 'A' + (i & 31);
}
- fPaint.setTypeface(SkTypeface::RefDefault())->unref();
+ fPaint.setTypeface(SkTypeface::MakeDefault());
}
protected:
diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp
index 2e0429fce3..c5e40af746 100644
--- a/bench/SkGlyphCacheBench.cpp
+++ b/bench/SkGlyphCacheBench.cpp
@@ -53,18 +53,15 @@ protected:
void onDraw(int loops, SkCanvas*) override {
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
SkGraphics::SetFontCacheLimit(fCacheSize);
- SkTypeface* typeface = sk_tool_utils::create_portable_typeface(
- "serif", SkTypeface::kItalic);
SkPaint paint;
paint.setAntiAlias(true);
paint.setSubpixelText(true);
- paint.setTypeface(typeface);
+ paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic));
for (int work = 0; work < loops; work++) {
do_font_stuff(&paint);
}
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
- SkSafeUnref(typeface);
}
private:
@@ -90,7 +87,7 @@ protected:
void onDraw(int loops, SkCanvas*) override {
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
SkGraphics::SetFontCacheLimit(fCacheSize);
- SkTypeface* typefaces[] =
+ sk_sp<SkTypeface> typefaces[] =
{sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic),
sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic)};
@@ -104,8 +101,6 @@ protected:
});
}
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
- SkSafeUnref(typefaces[0]);
- SkSafeUnref(typefaces[1]);
}
private:
diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp
index 04f824c700..a048ffd4a1 100644
--- a/bench/TextBench.cpp
+++ b/bench/TextBench.cpp
@@ -47,7 +47,7 @@ class TextBench : public Benchmark {
FontQuality fFQ;
bool fDoPos;
bool fDoColorEmoji;
- SkAutoTUnref<SkTypeface> fColorEmojiTypeface;
+ sk_sp<SkTypeface> fColorEmojiTypeface;
SkPoint* fPos;
public:
TextBench(const char text[], int ps,
@@ -71,7 +71,7 @@ protected:
void onDelayedSetup() override {
if (fDoColorEmoji) {
SkASSERT(kBW == fFQ);
- fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
+ fColorEmojiTypeface = MakeResourceAsTypeface("/fonts/Funkster.ttf");
}
if (fDoPos) {
diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp
index a350e7b4c4..37bf311119 100644
--- a/bench/TextBlobBench.cpp
+++ b/bench/TextBlobBench.cpp
@@ -23,13 +23,11 @@
*/
class TextBlobBench : public Benchmark {
public:
- TextBlobBench()
- : fTypeface(nullptr) {
- }
+ TextBlobBench() {}
protected:
void onDelayedSetup() override {
- fTypeface.reset(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal));
+ fTypeface = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal);
// make textblob
SkPaint paint;
paint.setTypeface(fTypeface);
@@ -64,9 +62,9 @@ protected:
private:
- SkAutoTUnref<const SkTextBlob> fBlob;
- SkTDArray<uint16_t> fGlyphs;
- SkAutoTUnref<SkTypeface> fTypeface;
+ SkAutoTUnref<const SkTextBlob> fBlob;
+ SkTDArray<uint16_t> fGlyphs;
+ sk_sp<SkTypeface> fTypeface;
typedef Benchmark INHERITED;
};
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 5ebabc0c1b..566029648b 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -1286,7 +1286,7 @@ SkThread* start_status_thread() {
#define PORTABLE_FONT_PREFIX "Toy Liberation "
-static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
+static sk_sp<SkTypeface> create_from_name(const char familyName[], SkTypeface::Style style) {
if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
&& !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
return sk_tool_utils::create_portable_typeface(familyName, style);
@@ -1296,7 +1296,7 @@ static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style s
#undef PORTABLE_FONT_PREFIX
-extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
+extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
int dm_main();
int dm_main() {
diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp
index cad32466fc..bbc403c636 100644
--- a/fuzz/FilterFuzz.cpp
+++ b/fuzz/FilterFuzz.cpp
@@ -512,9 +512,7 @@ static SkPaint make_paint() {
if (false) {
// our validating buffer does not support typefaces yet, so skip this for now
- SkAutoTUnref<SkTypeface> typeface(
- SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
- paint.setTypeface(typeface);
+ paint.setTypeface(SkTypeface::MakeFromName(make_font_name().c_str(),make_typeface_style()));
}
SkLayerRasterizer::Builder rasterizerBuilder;
diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp
index ebb3c6715c..b29040ac29 100644
--- a/gm/coloremoji.cpp
+++ b/gm/coloremoji.cpp
@@ -50,11 +50,11 @@ public:
protected:
struct EmojiFont {
- SkAutoTUnref<SkTypeface> typeface;
+ sk_sp<SkTypeface> typeface;
const char* text;
} emojiFont;
virtual void onOnceBeforeDraw() override {
- sk_tool_utils::emoji_typeface(&emojiFont.typeface);
+ emojiFont.typeface = sk_tool_utils::emoji_typeface();
emojiFont.text = sk_tool_utils::emoji_sample_text();
}
@@ -92,7 +92,7 @@ protected:
for (int makeBlur = 0; makeBlur < 2; makeBlur++) {
for (int makeGray = 0; makeGray < 2; makeGray++) {
SkPaint shaderPaint;
- shaderPaint.setTypeface(paint.getTypeface());
+ shaderPaint.setTypeface(sk_ref_sp(paint.getTypeface()));
if (SkToBool(makeLinear)) {
shaderPaint.setShader(MakeLinear());
}
diff --git a/gm/colortype.cpp b/gm/colortype.cpp
index c9314de2a4..68dfeee535 100644
--- a/gm/colortype.cpp
+++ b/gm/colortype.cpp
@@ -12,13 +12,7 @@
class ColorTypeGM : public skiagm::GM {
public:
- ColorTypeGM()
- : fColorType(nullptr) {
- }
-
- virtual ~ColorTypeGM() {
- SkSafeUnref(fColorType);
- }
+ ColorTypeGM() {}
protected:
void onOnceBeforeDraw() override {
@@ -33,12 +27,11 @@ protected:
paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
0, &local));
- SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
+ sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold));
if (nullptr == orig) {
- orig = SkTypeface::RefDefault();
+ orig = SkTypeface::MakeDefault();
}
- fColorType = new SkGTypeface(orig, paint);
- orig->unref();
+ fColorType = sk_make_sp<SkGTypeface>(std::move(orig), paint);
}
SkString onShortName() override {
@@ -62,7 +55,7 @@ protected:
}
private:
- SkTypeface* fColorType;
+ sk_sp<SkTypeface> fColorType;
typedef skiagm::GM INHERITED;
};
diff --git a/gm/colortypexfermode.cpp b/gm/colortypexfermode.cpp
index 36db2aa3f5..058b92d223 100644
--- a/gm/colortypexfermode.cpp
+++ b/gm/colortypexfermode.cpp
@@ -19,13 +19,7 @@ class ColorTypeXfermodeGM : public GM {
public:
const static int W = 64;
const static int H = 64;
- ColorTypeXfermodeGM()
- : fColorType(nullptr) {
- }
-
- virtual ~ColorTypeXfermodeGM() {
- SkSafeUnref(fColorType);
- }
+ ColorTypeXfermodeGM() {}
protected:
void onOnceBeforeDraw() override {
@@ -40,12 +34,11 @@ protected:
paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors),
0, &local));
- SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
+ sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold));
if (nullptr == orig) {
- orig = SkTypeface::RefDefault();
+ orig = SkTypeface::MakeDefault();
}
- fColorType = new SkGTypeface(orig, paint);
- orig->unref();
+ fColorType = sk_make_sp<SkGTypeface>(orig, paint);
fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType,
kOpaque_SkAlphaType), gData, 4);
@@ -149,8 +142,8 @@ protected:
}
private:
- SkBitmap fBG;
- SkTypeface* fColorType;
+ SkBitmap fBG;
+ sk_sp<SkTypeface> fColorType;
typedef GM INHERITED;
};
diff --git a/gm/dftext.cpp b/gm/dftext.cpp
index e6aba0894e..c7d9a8b1bf 100644
--- a/gm/dftext.cpp
+++ b/gm/dftext.cpp
@@ -19,7 +19,7 @@ public:
protected:
void onOnceBeforeDraw() override {
- sk_tool_utils::emoji_typeface(&fEmojiTypeface);
+ fEmojiTypeface = sk_tool_utils::emoji_typeface();
fEmojiText = sk_tool_utils::emoji_sample_text();
}
@@ -210,7 +210,7 @@ protected:
}
private:
- SkAutoTUnref<SkTypeface> fEmojiTypeface;
+ sk_sp<SkTypeface> fEmojiTypeface;
const char* fEmojiText;
typedef skiagm::GM INHERITED;
diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp
index 30f8892c78..c4af489304 100644
--- a/gm/fontcache.cpp
+++ b/gm/fontcache.cpp
@@ -20,15 +20,7 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x,
class FontCacheGM : public skiagm::GM {
public:
- FontCacheGM() {
- fTypefaces[0] = nullptr;
- fTypefaces[1] = nullptr;
- }
-
- virtual ~FontCacheGM() {
- SkSafeUnref(fTypefaces[0]);
- SkSafeUnref(fTypefaces[1]);
- }
+ FontCacheGM() {}
protected:
SkString onShortName() override {
@@ -76,7 +68,7 @@ protected:
}
private:
- SkTypeface* fTypefaces[2];
+ sk_sp<SkTypeface> fTypefaces[2];
typedef GM INHERITED;
};
diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp
index 1975f998cd..a4dc2631ec 100644
--- a/gm/fontmgr.cpp
+++ b/gm/fontmgr.cpp
@@ -31,9 +31,9 @@ static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
// find typeface containing the requested character and draw it
SkString ch;
ch.appendUnichar(character);
- SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle,
- bcp47, bcp47Count, character);
- SkSafeUnref(paint.setTypeface(typeface));
+ sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle,
+ bcp47, bcp47Count, character));
+ paint.setTypeface(typeface);
x = drawString(canvas, ch, x, y, paint) + 20;
if (nullptr == typeface) {
@@ -45,8 +45,8 @@ static SkScalar drawCharacter(SkCanvas* canvas, uint32_t character, SkScalar x,
// it expects to get the same glyph when following this pattern.
SkString familyName;
typeface->getFamilyName(&familyName);
- SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), typeface->fontStyle());
- SkSafeUnref(paint.setTypeface(typefaceCopy));
+ paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_str(),
+ typeface->fontStyle())));
return drawString(canvas, ch, x, y, paint) + 20;
}
@@ -104,7 +104,7 @@ protected:
set->getStyle(j, &fs, &sname);
sname.appendf(" [%d %d %d]", fs.weight(), fs.width(), fs.slant());
- SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
+ paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
x = drawString(canvas, sname, x, y, paint) + 20;
// check to see that we get different glyphs in japanese and chinese
@@ -155,7 +155,7 @@ protected:
sname.appendf(" [%d %d]", fs.weight(), fs.width());
- SkSafeUnref(p.setTypeface(fset->createTypeface(j)));
+ p.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j)));
(void)drawString(canvas, sname, 0, y, p);
y += 24;
}
@@ -169,11 +169,11 @@ protected:
for (int weight = 100; weight <= 900; weight += 200) {
for (int width = 1; width <= 9; width += 2) {
SkFontStyle fs(weight, width, SkFontStyle::kUpright_Slant);
- SkTypeface* face = fset->matchStyle(fs);
+ sk_sp<SkTypeface> face(fset->matchStyle(fs));
if (face) {
SkString str;
str.printf("request [%d %d]", fs.weight(), fs.width());
- p.setTypeface(face)->unref();
+ p.setTypeface(std::move(face));
(void)drawString(canvas, str, 0, y, p);
y += 24;
}
@@ -274,7 +274,7 @@ protected:
for (int i = 0; i < count; ++i) {
SkAutoTUnref<SkFontStyleSet> set(fm->createStyleSet(i));
for (int j = 0; j < set->count(); ++j) {
- SkSafeUnref(paint.setTypeface(set->createTypeface(j)));
+ paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j)));
if (paint.getTypeface()) {
show_bounds(canvas, paint, x, y, boundsColors[index & 1]);
index += 1;
diff --git a/gm/fontscalerdistortable.cpp b/gm/fontscalerdistortable.cpp
index f83365bb3e..b4f2ca370c 100644
--- a/gm/fontscalerdistortable.cpp
+++ b/gm/fontscalerdistortable.cpp
@@ -58,9 +58,8 @@ protected:
SkFourByteTag tag = SkSetFourByteTag('w','g','h','t');
SkScalar styleValue = SkDoubleToScalar(0.5 + (5*j + i) * ((2.0 - 0.5) / (2 * 5)));
SkFontMgr::FontParameters::Axis axes[] = { { tag, styleValue } };
- SkAutoTUnref<SkTypeface> typeface(fontMgr->createFromStream(
- distortable->duplicate(), SkFontMgr::FontParameters().setAxes(axes, 1)));
- paint.setTypeface(typeface);
+ paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream(
+ distortable->duplicate(), SkFontMgr::FontParameters().setAxes(axes, 1))));
SkAutoCanvasRestore acr(canvas, true);
canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20));
diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp
index bc5feb3375..c7d4309f97 100644
--- a/gm/gammatext.cpp
+++ b/gm/gammatext.cpp
@@ -19,12 +19,8 @@ static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) {
}
static bool setFont(SkPaint* paint, const char name[]) {
- SkTypeface* tf = SkTypeface::CreateFromName(name, SkTypeface::kNormal);
- if (tf) {
- paint->setTypeface(tf)->unref();
- return true;
- }
- return false;
+ paint->setTypeface(SkTypeface::MakeFromName(name, SkTypeface::kNormal));
+ return SkToBool(paint->getTypeface());
}
/**
@@ -108,8 +104,7 @@ static sk_sp<SkShader> make_gradient(SkColor c) {
}
static void set_face(SkPaint* paint) {
- SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic);
- SkSafeUnref(paint->setTypeface(face));
+ paint->setTypeface(SkTypeface::MakeFromName("serif", SkTypeface::kItalic));
}
static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) {
diff --git a/gm/mixedtextblobs.cpp b/gm/mixedtextblobs.cpp
index e66e73caf3..9a9bded1db 100644
--- a/gm/mixedtextblobs.cpp
+++ b/gm/mixedtextblobs.cpp
@@ -39,9 +39,9 @@ public:
protected:
void onOnceBeforeDraw() override {
- sk_tool_utils::emoji_typeface(&fEmojiTypeface);
+ fEmojiTypeface = sk_tool_utils::emoji_typeface();
fEmojiText = sk_tool_utils::emoji_sample_text();
- fReallyBigATypeface.reset(GetResourceAsTypeface("/fonts/ReallyBigA.ttf"));
+ fReallyBigATypeface = MakeResourceAsTypeface("/fonts/ReallyBigA.ttf");
SkTextBlobBuilder builder;
@@ -150,8 +150,8 @@ protected:
}
private:
- SkAutoTUnref<SkTypeface> fEmojiTypeface;
- SkAutoTUnref<SkTypeface> fReallyBigATypeface;
+ sk_sp<SkTypeface> fEmojiTypeface;
+ sk_sp<SkTypeface> fReallyBigATypeface;
const char* fEmojiText;
SkAutoTUnref<const SkTextBlob> fBlob;
diff --git a/gm/pdf_never_embed.cpp b/gm/pdf_never_embed.cpp
index ef7974e3d7..4fba40e282 100644
--- a/gm/pdf_never_embed.cpp
+++ b/gm/pdf_never_embed.cpp
@@ -25,16 +25,15 @@ static void excercise_draw_pos_text(SkCanvas* canvas,
}
DEF_SIMPLE_GM(pdf_never_embed, canvas, 512, 512) {
- const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
- SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface(resource));
- if (!typeface) {
- return;
- }
SkPaint p;
p.setTextSize(60);
- p.setTypeface(typeface);
+ p.setTypeface(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf"));
p.setAntiAlias(true);
+ if (!p.getTypeface()) {
+ return;
+ }
+
const char text[] = "HELLO, WORLD!";
canvas->drawColor(SK_ColorWHITE);
diff --git a/gm/poly2poly.cpp b/gm/poly2poly.cpp
index ea77033837..4eb99361c8 100644
--- a/gm/poly2poly.cpp
+++ b/gm/poly2poly.cpp
@@ -224,7 +224,7 @@ protected:
}
void onOnceBeforeDraw() override {
- fEmFace.reset(GetResourceAsTypeface("/fonts/Em.ttf"));
+ fEmFace = MakeResourceAsTypeface("/fonts/Em.ttf");
}
void onDraw(SkCanvas* canvas) override {
@@ -273,7 +273,7 @@ protected:
private:
typedef skiagm::GM INHERITED;
- SkAutoTUnref<SkTypeface> fEmFace;
+ sk_sp<SkTypeface> fEmFace;
};
//////////////////////////////////////////////////////////////////////////////
diff --git a/gm/textblob.cpp b/gm/textblob.cpp
index 02f3c878a3..525cfd292d 100644
--- a/gm/textblob.cpp
+++ b/gm/textblob.cpp
@@ -72,7 +72,7 @@ public:
protected:
void onOnceBeforeDraw() override {
- fTypeface.reset(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal));
+ fTypeface = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal);
SkPaint p;
p.setTypeface(fTypeface);
size_t txtLen = strlen(fText);
@@ -180,9 +180,9 @@ private:
return builder.build();
}
- SkTDArray<uint16_t> fGlyphs;
- SkAutoTUnref<SkTypeface> fTypeface;
- const char* fText;
+ SkTDArray<uint16_t> fGlyphs;
+ sk_sp<SkTypeface> fTypeface;
+ const char* fText;
typedef skiagm::GM INHERITED;
};
diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp
index 9e57c2fe97..8f5dc85e48 100644
--- a/gm/textblobmixedsizes.cpp
+++ b/gm/textblobmixedsizes.cpp
@@ -27,7 +27,6 @@ public:
protected:
void onOnceBeforeDraw() override {
- SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/HangingS.ttf"));
SkTextBlobBuilder builder;
// make textblob. To stress distance fields, we choose sizes appropriately
@@ -35,7 +34,7 @@ protected:
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setLCDRenderText(true);
- paint.setTypeface(typeface);
+ paint.setTypeface(MakeResourceAsTypeface("/fonts/HangingS.ttf"));
const char* text = "Skia";
diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp
index 267fe7a320..51dbfceab3 100644
--- a/gm/textblobrandomfont.cpp
+++ b/gm/textblobrandomfont.cpp
@@ -39,13 +39,12 @@ protected:
paint.setLCDRenderText(true);
// Setup our random scaler context
- SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-serif",
- SkTypeface::kBold));
+ sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-serif",
+ SkTypeface::kBold));
if (nullptr == orig) {
- orig.reset(SkTypeface::RefDefault());
+ orig = SkTypeface::MakeDefault();
}
- SkAutoTUnref<SkTypeface> random(new SkRandomTypeface(orig, paint, false));
- paint.setTypeface(random);
+ paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false));
SkRect bounds;
paint.measureText(text, strlen(text), &bounds);
@@ -66,16 +65,14 @@ protected:
sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset);
// color emoji
- SkAutoTUnref<SkTypeface> origEmoji;
- sk_tool_utils::emoji_typeface(&origEmoji);
+ sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface();
const char* osName = sk_tool_utils::platform_os_name();
// The mac emoji string will break us
if (origEmoji && (!strcmp(osName, "Android") || !strcmp(osName, "Ubuntu"))) {
const char* emojiText = sk_tool_utils::emoji_sample_text();
paint.measureText(emojiText, strlen(emojiText), &bounds);
offset += bounds.height();
- SkAutoTUnref<SkTypeface> randomEmoji(new SkRandomTypeface(orig, paint, false));
- paint.setTypeface(randomEmoji);
+ paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false));
sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offset);
}
diff --git a/gm/typeface.cpp b/gm/typeface.cpp
index d88efa51bf..e77d27747f 100644
--- a/gm/typeface.cpp
+++ b/gm/typeface.cpp
@@ -90,7 +90,7 @@ static const struct {
static const int gFaceStylesCount = SK_ARRAY_COUNT(gFaceStyles);
class TypefaceStylesGM : public skiagm::GM {
- SkTypeface* fFaces[gFaceStylesCount];
+ sk_sp<SkTypeface> fFaces[gFaceStylesCount];
bool fApplyKerning;
public:
@@ -99,16 +99,10 @@ public:
memset(fFaces, 0, sizeof(fFaces));
}
- virtual ~TypefaceStylesGM() {
- for (int i = 0; i < gFaceStylesCount; i++) {
- SkSafeUnref(fFaces[i]);
- }
- }
-
protected:
void onOnceBeforeDraw() override {
for (int i = 0; i < gFaceStylesCount; i++) {
- fFaces[i] = SkTypeface::CreateFromName(
+ fFaces[i] = SkTypeface::MakeFromName(
sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFaceStyles[i].fStyle);
}
}
diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp
index 83fe7201fd..e295cbc998 100644
--- a/gm/variedtext.cpp
+++ b/gm/variedtext.cpp
@@ -21,13 +21,6 @@ public:
VariedTextGM(bool effectiveClip, bool lcd)
: fEffectiveClip(effectiveClip)
, fLCD(lcd) {
- memset(fTypefacesToUnref, 0, sizeof(fTypefacesToUnref));
- }
-
- ~VariedTextGM() {
- for (size_t i = 0; i < SK_ARRAY_COUNT(fTypefacesToUnref); ++i) {
- SkSafeUnref(fTypefacesToUnref[i]);
- }
}
protected:
@@ -58,11 +51,11 @@ protected:
SkScalar w = SkIntToScalar(size.fWidth);
SkScalar h = SkIntToScalar(size.fHeight);
- static_assert(4 == SK_ARRAY_COUNT(fTypefacesToUnref), "typeface_cnt");
- fTypefacesToUnref[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kNormal);
- fTypefacesToUnref[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kBold);
- fTypefacesToUnref[2] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal);
- fTypefacesToUnref[3] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
+ static_assert(4 == SK_ARRAY_COUNT(fTypefaces), "typeface_cnt");
+ fTypefaces[0] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kNormal);
+ fTypefaces[1] = sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kBold);
+ fTypefaces[2] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal);
+ fTypefaces[3] = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold);
SkRandom random;
for (int i = 0; i < kCnt; ++i) {
@@ -82,12 +75,11 @@ protected:
fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize);
- fTypefaces[i] = fTypefacesToUnref[
- random.nextULessThan(SK_ARRAY_COUNT(fTypefacesToUnref))];
+ fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces));
SkRect r;
fPaint.setColor(fColors[i]);
- fPaint.setTypeface(fTypefaces[i]);
+ fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]);
fPaint.setTextSize(fPtSizes[i]);
fPaint.measureText(fStrings[i].c_str(), fStrings[i].size(), &r);
@@ -116,7 +108,7 @@ protected:
for (int i = 0; i < kCnt; ++i) {
fPaint.setColor(fColors[i]);
fPaint.setTextSize(fPtSizes[i]);
- fPaint.setTypeface(fTypefaces[i]);
+ fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]);
canvas->save();
canvas->clipRect(fClipRects[i]);
@@ -146,14 +138,14 @@ private:
bool fEffectiveClip;
bool fLCD;
- SkTypeface* fTypefacesToUnref[4];
+ sk_sp<SkTypeface> fTypefaces[4];
SkPaint fPaint;
// precomputed for each text draw
SkString fStrings[kCnt];
SkColor fColors[kCnt];
SkScalar fPtSizes[kCnt];
- SkTypeface* fTypefaces[kCnt];
+ int fTypefaceIndices[kCnt];
SkPoint fPositions[kCnt];
SkRect fClipRects[kCnt];
diff --git a/gm/verttext2.cpp b/gm/verttext2.cpp
index 12576c2699..79cbdbcc8b 100644
--- a/gm/verttext2.cpp
+++ b/gm/verttext2.cpp
@@ -17,23 +17,15 @@ namespace skiagm {
class VertText2GM : public GM {
public:
- VertText2GM()
- : fProp(nullptr)
- , fMono(nullptr) {
- }
-
- virtual ~VertText2GM() {
- SkSafeUnref(fProp);
- SkSafeUnref(fMono);
- }
+ VertText2GM() {}
protected:
void onOnceBeforeDraw() override {
const int pointSize = 24;
textHeight = SkIntToScalar(pointSize);
- fProp = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("sans-serif"),
+ fProp = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("sans-serif"),
SkTypeface::kNormal);
- fMono = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("monospace"),
+ fMono = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("monospace"),
SkTypeface::kNormal);
}
@@ -74,13 +66,13 @@ protected:
}
void drawText(SkCanvas* canvas, const SkString& string,
- SkTypeface* family, SkPaint::Align alignment) {
+ sk_sp<SkTypeface> family, SkPaint::Align alignment) {
SkPaint paint;
paint.setColor(SK_ColorBLACK);
paint.setAntiAlias(true);
paint.setVerticalText(true);
paint.setTextAlign(alignment);
- paint.setTypeface(family);
+ paint.setTypeface(std::move(family));
paint.setTextSize(textHeight);
canvas->drawText(string.c_str(), string.size(), y,
@@ -92,8 +84,8 @@ protected:
private:
typedef GM INHERITED;
SkScalar y, textHeight;
- SkTypeface* fProp;
- SkTypeface* fMono;
+ sk_sp<SkTypeface> fProp;
+ sk_sp<SkTypeface> fMono;
};
///////////////////////////////////////////////////////////////////////////////
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi
index 55123335e3..619e42ed52 100644
--- a/gyp/skia_for_android_framework_defines.gypi
+++ b/gyp/skia_for_android_framework_defines.gypi
@@ -28,6 +28,7 @@
'SK_SUPPORT_LEGACY_MASKFILTER_PTR',
'SK_SUPPORT_LEGACY_IMAGEFACTORY',
'SK_SUPPORT_LEGACY_XFERMODE_PTR',
+ 'SK_SUPPORT_LEGACY_TYPEFACE_PTR',
],
},
}
diff --git a/include/core/SkFont.h b/include/core/SkFont.h
index e4ebebb244..6c231c963a 100644
--- a/include/core/SkFont.h
+++ b/include/core/SkFont.h
@@ -117,17 +117,17 @@ public:
kLCD_MaskType,
};
- static SkFont* Create(SkTypeface*, SkScalar size, MaskType, uint32_t flags);
- static SkFont* Create(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX,
- MaskType, uint32_t flags);
+ static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, MaskType, uint32_t flags);
+ static sk_sp<SkFont> Make(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX,
+ MaskType, uint32_t flags);
/**
* Return a font with the same attributes of this font, but with the specified size.
* If size is not supported (e.g. <= 0 or non-finite) NULL will be returned.
*/
- SkFont* cloneWithSize(SkScalar size) const;
+ sk_sp<SkFont> makeWithSize(SkScalar size) const;
- SkTypeface* getTypeface() const { return fTypeface; }
+ SkTypeface* getTypeface() const { return fTypeface.get(); }
SkScalar getSize() const { return fSize; }
SkScalar getScaleX() const { return fScaleX; }
SkScalar getSkewX() const { return fSkewX; }
@@ -145,17 +145,17 @@ public:
SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding) const;
- static SkFont* Testing_CreateFromPaint(const SkPaint&);
+ static sk_sp<SkFont> Testing_CreateFromPaint(const SkPaint&);
private:
enum {
kAllFlags = 0xFF,
};
- SkFont(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, uint32_t flags);
- virtual ~SkFont();
+ SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType,
+ uint32_t flags);
- SkTypeface* fTypeface;
+ sk_sp<SkTypeface> fTypeface;
SkScalar fSize;
SkScalar fScaleX;
SkScalar fSkewX;
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 7367fc642d..293ffedc12 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -614,8 +614,10 @@ public:
paint
@return typeface
*/
- SkTypeface* setTypeface(SkTypeface* typeface);
void setTypeface(sk_sp<SkTypeface>);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ SkTypeface* setTypeface(SkTypeface* typeface);
+#endif
/** Get the paint's rasterizer (or NULL).
<p />
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index f22d2bd14f..3a47bd2bb3 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -92,51 +92,75 @@ public:
*/
static bool Equal(const SkTypeface* facea, const SkTypeface* faceb);
- /**
- * Returns a ref() to the default typeface. The caller must call unref()
- * when they are done referencing the object. Never returns NULL.
- */
- static SkTypeface* RefDefault(Style style = SkTypeface::kNormal);
+ /** Returns the default typeface, which is never nullptr. */
+ static sk_sp<SkTypeface> MakeDefault(Style style = SkTypeface::kNormal);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* RefDefault(Style style = SkTypeface::kNormal) {
+ return MakeDefault(style).release();
+ }
+#endif
- /** Return a new reference to the typeface that most closely matches the
- requested familyName and style. Pass null as the familyName to return
- the default font for the requested style. Will never return null
+ /** Return the typeface that most closely matches the requested familyName and style.
+ Pass nullptr as the familyName to request the default font for the requested style.
+ Will never return nullptr.
@param familyName May be NULL. The name of the font family.
@param style The style (normal, bold, italic) of the typeface.
- @return reference to the closest-matching typeface. Call must call
- unref() when they are done.
+ @return the closest-matching typeface.
*/
- static SkTypeface* CreateFromName(const char familyName[], Style style);
+ static sk_sp<SkTypeface> MakeFromName(const char familyName[], Style style);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* CreateFromName(const char familyName[], Style style) {
+ return MakeFromName(familyName, style).release();
+ }
+#endif
- /** Return a new reference to the typeface that most closely matches the
- requested typeface and specified Style. Use this call if you want to
- pick a new style from the same family of the existing typeface.
- If family is NULL, this selects from the default font's family.
+ /** Return the typeface that most closely matches the requested typeface and style.
+ Use this to pick a new style from the same family of the existing typeface.
+ If family is nullptr, this selects from the default font's family.
@param family May be NULL. The name of the existing type face.
@param s The style (normal, bold, italic) of the type face.
- @return reference to the closest-matching typeface. Call must call
- unref() when they are done.
+ @return the closest-matching typeface.
*/
- static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s);
+ static sk_sp<SkTypeface> MakeFromTypeface(SkTypeface* family, Style);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style style) {
+ return MakeFromTypeface(const_cast<SkTypeface*>(family), style).release();
+ }
+#endif
/** Return a new typeface given a file. If the file does not exist, or is
- not a valid font file, returns null.
+ not a valid font file, returns nullptr.
*/
- static SkTypeface* CreateFromFile(const char path[], int index = 0);
+ static sk_sp<SkTypeface> MakeFromFile(const char path[], int index = 0);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* CreateFromFile(const char path[], int index = 0) {
+ return MakeFromFile(path, index).release();
+ }
+#endif
/** Return a new typeface given a stream. If the stream is
- not a valid font file, returns null. Ownership of the stream is
+ not a valid font file, returns nullptr. Ownership of the stream is
transferred, so the caller must not reference it again.
*/
- static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0);
+ static sk_sp<SkTypeface> MakeFromStream(SkStreamAsset* stream, int index = 0);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0) {
+ return MakeFromStream(stream, index).release();
+ }
+#endif
/** Return a new typeface given font data and configuration. If the data
- is not valid font data, returns null. Ownership of the font data is
+ is not valid font data, returns nullptr. Ownership of the font data is
transferred, so the caller must not reference it again.
*/
- static SkTypeface* CreateFromFontData(SkFontData*);
+ static sk_sp<SkTypeface> MakeFromFontData(SkFontData*);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* CreateFromFontData(SkFontData* fd) {
+ return MakeFromFontData(fd).release();
+ }
+#endif
/** Write a unique signature to a stream, sufficient to reconstruct a
typeface referencing the same font when Deserialize is called.
@@ -144,12 +168,16 @@ public:
void serialize(SkWStream*) const;
/** Given the data previously written by serialize(), return a new instance
- to a typeface referring to the same font. If that font is not available,
- return null. If an instance is returned, the caller is responsible for
- calling unref() when they are done with it.
+ of a typeface referring to the same font. If that font is not available,
+ return nullptr.
Does not affect ownership of SkStream.
*/
- static SkTypeface* Deserialize(SkStream*);
+ static sk_sp<SkTypeface> MakeDeserialize(SkStream*);
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
+ static SkTypeface* Deserialize(SkStream* stream) {
+ return MakeDeserialize(stream).release();
+ }
+#endif
enum Encoding {
kUTF8_Encoding,
@@ -395,9 +423,6 @@ private:
uint32_t glyphIDsCount = 0) const;
private:
- static SkTypeface* CreateDefault(int style); // SkLazyPtr requires an int, not a Style.
- static void DeleteDefault(SkTypeface*);
-
SkFontID fUniqueID;
SkFontStyle fStyle;
mutable SkRect fBounds;
diff --git a/include/ports/SkFontConfigInterface.h b/include/ports/SkFontConfigInterface.h
index 9f98e356d2..dfa5bd0b13 100644
--- a/include/ports/SkFontConfigInterface.h
+++ b/include/ports/SkFontConfigInterface.h
@@ -97,12 +97,15 @@ public:
*
* The default implementation simply returns a new typeface built using data obtained from
* openStream(), but derived classes may implement more complex caching schemes.
- *
- * Callers are responsible for unref-ing the result.
*/
+ virtual sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity) {
+ return SkTypeface::MakeFromStream(this->openStream(identity), identity.fTTCIndex);
+ }
+#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR
virtual SkTypeface* createTypeface(const FontIdentity& identity) {
- return SkTypeface::CreateFromStream(this->openStream(identity), identity.fTTCIndex);
+ return this->makeTypeface(identity).release();
}
+#endif
/**
* Return a singleton instance of a direct subclass that calls into
diff --git a/public.bzl b/public.bzl
index 8eb4d855d9..4cd21454d5 100644
--- a/public.bzl
+++ b/public.bzl
@@ -590,6 +590,7 @@ DEFINES_ALL = [
"SK_SUPPORT_LEGACY_MASKFILTER_PTR",
"SK_SUPPORT_LEGACY_IMAGEFACTORY",
"SK_SUPPORT_LEGACY_XFERMODE_PTR",
+ "SK_SUPPORT_LEGACY_TYPEFACE_PTR",
]
################################################################################
diff --git a/samplecode/ClockFaceView.cpp b/samplecode/ClockFaceView.cpp
index 6e2b2b1585..7c6158ada3 100644
--- a/samplecode/ClockFaceView.cpp
+++ b/samplecode/ClockFaceView.cpp
@@ -170,21 +170,17 @@ static void apply_shader(SkPaint* paint, float scale)
}
class ClockFaceView : public SkView {
- SkTypeface* fFace;
+ sk_sp<SkTypeface> fFace;
SkScalar fInterp;
SkScalar fDx;
public:
ClockFaceView() {
- fFace = SkTypeface::CreateFromFile("/Users/reed/Downloads/p052024l.pfb");
+ fFace = SkTypeface::MakeFromFile("/Users/reed/Downloads/p052024l.pfb");
fInterp = 0;
fDx = SK_Scalar1/64;
}
- virtual ~ClockFaceView() {
- SkSafeUnref(fFace);
- }
-
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
@@ -225,8 +221,7 @@ protected:
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(240));
- paint.setTypeface(SkTypeface::CreateFromName("sans-serif",
- SkTypeface::kBold));
+ paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkTypeface::kBold));
SkString str("9");
diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp
index 357a437a67..738b34e3ae 100644
--- a/samplecode/SampleAll.cpp
+++ b/samplecode/SampleAll.cpp
@@ -527,8 +527,7 @@ protected:
paint.setAntiAlias(true);
paint.setTextSize(SkIntToScalar(48));
- paint.setTypeface(SkTypeface::CreateFromName("sans-serif",
- SkTypeface::kBold));
+ paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkTypeface::kBold));
SkString str("GOOGLE");
diff --git a/samplecode/SampleAnimatedText.cpp b/samplecode/SampleAnimatedText.cpp
index 89ea6923d7..6bd6d82e8c 100755
--- a/samplecode/SampleAnimatedText.cpp
+++ b/samplecode/SampleAnimatedText.cpp
@@ -73,7 +73,7 @@ protected:
void onDrawContent(SkCanvas* canvas) override {
SkPaint paint;
- SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromFile("/skimages/samplefont.ttf")));
+ paint.setTypeface(SkTypeface::MakeFromFile("/skimages/samplefont.ttf"));
paint.setAntiAlias(true);
paint.setFilterQuality(kMedium_SkFilterQuality);
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 1df96c80c8..e4362c5a36 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -935,7 +935,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fMouseX = fMouseY = 0;
fFatBitsScale = 8;
- fTypeface = SkTypeface::CreateFromTypeface(nullptr, SkTypeface::kBold);
+ fTypeface = SkTypeface::MakeFromTypeface(nullptr, SkTypeface::kBold);
fShowZoomer = false;
fZoomLevel = 0;
@@ -1061,7 +1061,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
}
SampleWindow::~SampleWindow() {
- SkSafeUnref(fTypeface);
SkSafeUnref(fDevManager);
}
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index ad7a871b98..7734ac93d9 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -204,7 +204,7 @@ private:
int fMouseX, fMouseY;
int fFatBitsScale;
// Used by the text showing position and color values.
- SkTypeface* fTypeface;
+ sk_sp<SkTypeface> fTypeface;
bool fShowZoomer;
SkOSMenu::TriState fLCDState;
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 6a4f1f822f..88372414ca 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -515,9 +515,8 @@ static SkPaint make_paint() {
if (false) {
// our validating buffer does not support typefaces yet, so skip this for now
- SkAutoTUnref<SkTypeface> typeface(
- SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style()));
- paint.setTypeface(typeface);
+ paint.setTypeface(SkTypeface::MakeFromName(make_font_name().c_str(),
+ make_typeface_style()));
}
SkLayerRasterizer::Builder rasterizerBuilder;
diff --git a/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp
index ce3b81ee8a..72371ed807 100644
--- a/samplecode/SampleFontScalerTest.cpp
+++ b/samplecode/SampleFontScalerTest.cpp
@@ -36,23 +36,16 @@ static const struct {
static const int gFaceCount = SK_ARRAY_COUNT(gFaces);
class FontScalerTestView : public SampleView {
- SkTypeface* fFaces[gFaceCount];
+ sk_sp<SkTypeface> fFaces[gFaceCount];
public:
FontScalerTestView() {
for (int i = 0; i < gFaceCount; i++) {
- fFaces[i] = SkTypeface::CreateFromName(gFaces[i].fName,
- gFaces[i].fStyle);
+ fFaces[i] = SkTypeface::MakeFromName(gFaces[i].fName, gFaces[i].fStyle);
}
// this->setBGColor(0xFFDDDDDD);
}
- virtual ~FontScalerTestView() {
- for (int i = 0; i < gFaceCount; i++) {
- SkSafeUnref(fFaces[i]);
- }
- }
-
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) {
@@ -92,7 +85,7 @@ protected:
// paint.setSubpixelText(true);
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
- SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal)));
+ paint.setTypeface(SkTypeface::MakeFromName("Times Roman", SkTypeface::kNormal));
// const char* text = "abcdefghijklmnopqrstuvwxyz";
const char* text = "Hamburgefons ooo mmm";
diff --git a/samplecode/SampleSlides.cpp b/samplecode/SampleSlides.cpp
index 9f57907626..edc2dd77a2 100644
--- a/samplecode/SampleSlides.cpp
+++ b/samplecode/SampleSlides.cpp
@@ -625,7 +625,7 @@ static void texteffect_slide(SkCanvas* canvas) {
SkScalar x = 20;
SkScalar y = 80;
SkPaint paint;
- paint.setTypeface(SkTypeface::CreateFromName("Georgia", SkTypeface::kItalic));
+ paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kItalic));
paint.setTextSize(75);
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLUE);
diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp
index 6dca10017a..ca09cc749a 100644
--- a/samplecode/SampleText.cpp
+++ b/samplecode/SampleText.cpp
@@ -122,7 +122,7 @@ protected:
// canvas->drawText(style, strlen(style), SkIntToScalar(20), SkIntToScalar(20), paint);
- SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromFile("/skimages/samplefont.ttf")));
+ paint.setTypeface(SkTypeface::MakeFromFile("/skimages/samplefont.ttf"));
paint.setAntiAlias(true);
paint.setFlags(paint.getFlags() | gHints[index].fFlags);
diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp
index af75f89388..8a69f000f8 100644
--- a/samplecode/SampleXfermodesBlur.cpp
+++ b/samplecode/SampleXfermodesBlur.cpp
@@ -28,9 +28,7 @@
#include "SkBlurMaskFilter.h"
static void setNamedTypeface(SkPaint* paint, const char name[]) {
- SkTypeface* face = SkTypeface::CreateFromName(name, SkTypeface::kNormal);
- paint->setTypeface(face);
- SkSafeUnref(face);
+ paint->setTypeface(SkTypeface::MakeFromName(name, SkTypeface::kNormal));
}
static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF };
@@ -92,8 +90,7 @@ protected:
SkPaint paint;
paint.setAntiAlias(true);
paint.setTextSize(50);
- paint.setTypeface(SkTypeface::CreateFromName("Arial Unicode MS", SkTypeface::kNormal));
- SkSafeUnref(paint.getTypeface());
+ paint.setTypeface(SkTypeface::MakeFromName("Arial Unicode MS", SkTypeface::kNormal));
char buffer[10];
size_t len = SkUTF8_FromUnichar(0x8500, buffer);
canvas->drawText(buffer, len, 40, 40, paint);
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..2e619af0fb 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -364,14 +364,14 @@ protected:
return nullptr;
}
- static SkTypeface_AndroidSystem* find_family_style_character(
+ static sk_sp<SkTypeface_AndroidSystem> find_family_style_character(
const SkTDArray<NameToFamily>& fallbackNameToFamilyMap,
const SkFontStyle& style, bool elegant,
const SkString& langTag, SkUnichar character)
{
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;
@@ -388,7 +388,7 @@ protected:
uint16_t glyphID;
paint.textToGlyphs(&character, sizeof(character), &glyphID);
if (glyphID != 0) {
- return face.release();
+ return face;
}
}
return nullptr;
@@ -410,23 +410,23 @@ protected:
for (int bcp47Index = bcp47Count; bcp47Index --> 0;) {
SkLanguage lang(bcp47[bcp47Index]);
while (!lang.getTag().isEmpty()) {
- SkTypeface_AndroidSystem* matchingTypeface =
+ sk_sp<SkTypeface_AndroidSystem> matchingTypeface =
find_family_style_character(fFallbackNameToFamilyMap,
style, SkToBool(elegant),
lang.getTag(), character);
if (matchingTypeface) {
- return matchingTypeface;
+ return matchingTypeface.release();
}
lang = lang.getParent();
}
}
- SkTypeface_AndroidSystem* matchingTypeface =
+ sk_sp<SkTypeface_AndroidSystem> matchingTypeface =
find_family_style_character(fFallbackNameToFamilyMap,
style, SkToBool(elegant),
SkString(), character);
if (matchingTypeface) {
- return matchingTypeface;
+ return matchingTypeface.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);
}
diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp
index 0b436552a3..ec32d9f031 100644
--- a/tests/FontHostStreamTest.cpp
+++ b/tests/FontHostStreamTest.cpp
@@ -69,9 +69,7 @@ DEF_TEST(FontHostStream, reporter) {
paint.setColor(SK_ColorGRAY);
paint.setTextSize(SkIntToScalar(30));
- SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia",
- SkTypeface::kNormal);
- SkSafeUnref(paint.setTypeface(fTypeface));
+ paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kNormal));
SkIRect origRect = SkIRect::MakeWH(64, 64);
SkBitmap origBitmap;
@@ -89,23 +87,18 @@ DEF_TEST(FontHostStream, reporter) {
drawBG(&origCanvas);
origCanvas.drawText("A", 1, point.fX, point.fY, paint);
- SkTypeface* origTypeface = paint.getTypeface();
- SkAutoTUnref<SkTypeface> aur;
- if (nullptr == origTypeface) {
- aur.reset(SkTypeface::RefDefault());
- origTypeface = aur.get();
- }
-
+ sk_sp<SkTypeface> typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(paint.getTypeface())
+ : SkTypeface::MakeDefault());
int ttcIndex;
- SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex));
- SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.release());
+ SkAutoTDelete<SkStreamAsset> fontData(typeface->openStream(&ttcIndex));
+ sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(fontData.release()));
SkFontDescriptor desc;
bool isLocalStream = false;
streamTypeface->getFontDescriptor(&desc, &isLocalStream);
REPORTER_ASSERT(reporter, isLocalStream);
- SkSafeUnref(paint.setTypeface(streamTypeface));
+ paint.setTypeface(streamTypeface);
drawBG(&streamCanvas);
streamCanvas.drawPosText("A", 1, &point, paint);
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index d9a3df414a..ebcc4ab2ae 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -31,7 +31,7 @@ static const struct TagSize {
// Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table
// (if that table is available).
-static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_unitsPerEm(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
int nativeUPEM = face->getUnitsPerEm();
int tableUPEM = -1;
@@ -50,7 +50,7 @@ static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
// Test that countGlyphs() agrees with a direct lookup in the 'maxp' table
// (if that table is available).
-static void test_countGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_countGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
int nativeGlyphs = face->countGlyphs();
int tableGlyphs = -1;
@@ -86,7 +86,7 @@ struct CharsToGlyphs_TestData {
};
// Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs.
-static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_charsToGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
uint16_t paintGlyphIds[256];
uint16_t faceGlyphIds[256];
@@ -154,22 +154,22 @@ static void test_fontstream(skiatest::Reporter* reporter) {
}
static void test_symbolfont(skiatest::Reporter* reporter) {
- SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/SpiderSymbol.ttf"));
- if (!typeface) {
- SkDebugf("Skipping FontHostTest::test_symbolfont\n");
- return;
- }
-
SkUnichar c = 0xf021;
uint16_t g;
SkPaint paint;
- paint.setTypeface(typeface);
+ paint.setTypeface(MakeResourceAsTypeface("/fonts/SpiderSymbol.ttf"));
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
paint.textToGlyphs(&c, 4, &g);
+
+ if (!paint.getTypeface()) {
+ SkDebugf("Skipping FontHostTest::test_symbolfont\n");
+ return;
+ }
+
REPORTER_ASSERT(reporter, g == 3);
}
-static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
if (false) { // avoid bit rot, suppress warning
SkFontID fontID = face->uniqueID();
REPORTER_ASSERT(reporter, fontID);
@@ -223,7 +223,7 @@ static void test_tables(skiatest::Reporter* reporter) {
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTypeface::kNormal));
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkTypeface::kNormal));
if (face) {
#ifdef DUMP_TABLES
SkDebugf("%s\n", gNames[i]);
@@ -277,8 +277,7 @@ static void test_advances(skiatest::Reporter* reporter) {
char txt[] = "long.text.with.lots.of.dots.";
for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal));
- paint.setTypeface(face);
+ paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal));
for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
paint.setHinting(settings[j].hinting);
diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp
index 92dc18b135..414631c58f 100644
--- a/tests/FontMgrTest.cpp
+++ b/tests/FontMgrTest.cpp
@@ -19,7 +19,7 @@
static void test_font(skiatest::Reporter* reporter) {
uint32_t flags = 0;
- SkAutoTUnref<SkFont> font(SkFont::Create(nullptr, 24, SkFont::kA8_MaskType, flags));
+ sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags));
REPORTER_ASSERT(reporter, font->getTypeface());
REPORTER_ASSERT(reporter, 24 == font->getSize());
@@ -39,7 +39,7 @@ static void test_font(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
- SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36));
+ sk_sp<SkFont> newFont(font->makeWithSize(36));
REPORTER_ASSERT(reporter, newFont.get());
REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we haven't changed
@@ -47,7 +47,7 @@ static void test_font(skiatest::Reporter* reporter) {
SkPaint paint;
paint.setTextSize(18);
- font.reset(SkFont::Testing_CreateFromPaint(paint));
+ font = SkFont::Testing_CreateFromPaint(paint);
REPORTER_ASSERT(reporter, font.get());
REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
@@ -64,14 +64,12 @@ static void test_alias_names(skiatest::Reporter* reporter) {
};
for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
- SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i],
- SkTypeface::kNormal));
+ sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal));
if (nullptr == first.get()) {
continue;
}
for (int j = 0; j < 10; ++j) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i],
- SkTypeface::kNormal));
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal));
#if 0
SkString name;
face->getFamilyName(&name);
diff --git a/tests/FontObjTest.cpp b/tests/FontObjTest.cpp
index 9d18ce6b2e..66c8bd500f 100644
--- a/tests/FontObjTest.cpp
+++ b/tests/FontObjTest.cpp
@@ -23,7 +23,7 @@ static bool is_enable_bytecode_hints(const SkPaint& paint) {
}
static void test_cachedfont(skiatest::Reporter* reporter, const SkPaint& paint) {
- SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
+ sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
// Currently SkFont resolves null into the default, so only test if paint's is not null
if (paint.getTypeface()) {
@@ -78,8 +78,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) {
char txt[] = "long.text.with.lots.of.dots.";
for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal));
- paint.setTypeface(face);
+ paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal));
for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
paint.setHinting(settings[j].hinting);
@@ -103,7 +102,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, width1 == width2);
- SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
+ sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8_SkTextEncoding);
// measureText not yet implemented...
REPORTER_ASSERT(reporter, font_width1 == -1);
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 58dd773fb8..07ddabc912 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -430,7 +430,7 @@ DEF_TEST(PDFFontCanEmbedTypeface, reporter) {
SkPDFCanon canon;
const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
- sk_sp<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource));
+ sk_sp<SkTypeface> noEmbedTypeface(MakeResourceAsTypeface(resource));
if (noEmbedTypeface) {
REPORTER_ASSERT(reporter,
!SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &canon));
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index bd00adb18d..f507467771 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -80,7 +80,7 @@ DEF_TEST(Paint_cmap, reporter) {
SkRandom rand;
SkPaint paint;
- paint.setTypeface(SkTypeface::RefDefault())->unref();
+ paint.setTypeface(SkTypeface::MakeDefault());
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < 1000; ++i) {
@@ -333,7 +333,7 @@ DEF_TEST(Paint_getHash, r) {
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
// SkTypeface is the first field we hash, so test it specially.
- paint.setTypeface(SkTypeface::RefDefault())->unref();
+ paint.setTypeface(SkTypeface::MakeDefault());
REPORTER_ASSERT(r, paint.getHash() != defaultHash);
paint.setTypeface(nullptr);
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 9e36d841df..832a80f438 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1177,7 +1177,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10);
SkPaint paint;
- paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic));
+ paint.setTypeface(SkTypeface::MakeFromName("Arial", SkTypeface::kItalic));
canvas->drawText("Q", 1, 0, 10, paint);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->hasText());
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 4750bbe25d..9e9b221cd2 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -322,14 +322,14 @@ static void compare_bitmaps(skiatest::Reporter* reporter,
}
REPORTER_ASSERT(reporter, 0 == pixelErrors);
}
-static void serialize_and_compare_typeface(SkTypeface* typeface, const char* text,
+static void serialize_and_compare_typeface(sk_sp<SkTypeface> typeface, const char* text,
skiatest::Reporter* reporter)
{
// Create a paint with the typeface.
SkPaint paint;
paint.setColor(SK_ColorGRAY);
paint.setTextSize(SkIntToScalar(30));
- paint.setTypeface(typeface);
+ paint.setTypeface(std::move(typeface));
// Paint some text.
SkPictureRecorder recorder;
@@ -357,11 +357,11 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
{
// Load typeface from file to test CreateFromFile with index.
SkString filename = GetResourcePath("/fonts/test.ttc");
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_str(), 1));
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile(filename.c_str(), 1));
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because test.ttc not found.");
} else {
- serialize_and_compare_typeface(typeface, "A!", reporter);
+ serialize_and_compare_typeface(std::move(typeface), "A!", reporter);
}
}
@@ -372,12 +372,12 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not found.");
} else {
SkFixed axis = SK_FixedSqrt2;
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData(
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(
new SkFontData(distortable.release(), 0, &axis, 1)));
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not created.");
} else {
- serialize_and_compare_typeface(typeface, "abc", reporter);
+ serialize_and_compare_typeface(std::move(typeface), "abc", reporter);
}
}
}
diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp
index 23f45a4cad..cbc6b99f84 100644
--- a/tests/TextBlobCacheTest.cpp
+++ b/tests/TextBlobCacheTest.cpp
@@ -99,12 +99,11 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte
set->getStyle(j, &fs, nullptr);
// We use a typeface which randomy returns unexpected mask formats to fuzz
- SkAutoTUnref<SkTypeface> orig(set->createTypeface(j));
+ sk_sp<SkTypeface> orig(set->createTypeface(j));
if (normal) {
paint.setTypeface(orig);
} else {
- SkAutoTUnref<SkTypeface> typeface(new SkRandomTypeface(orig, paint, true));
- paint.setTypeface(typeface);
+ paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, true));
}
SkTextBlobBuilder builder;
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index 923669e8c5..61070247b4 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -178,12 +178,10 @@ public:
SkPaint font;
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::RefDefault());
-
// Kitchen sink font.
font.setTextSize(42);
font.setTextScaleX(4.2f);
- font.setTypeface(typeface);
+ font.setTypeface(SkTypeface::MakeDefault());
font.setTextSkewX(0.42f);
font.setTextAlign(SkPaint::kCenter_Align);
font.setHinting(SkPaint::kFull_Hinting);
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index 950449d9c1..6a606d4e95 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -12,8 +12,8 @@
DEF_TEST(Typeface, reporter) {
- SkAutoTUnref<SkTypeface> t1(SkTypeface::CreateFromName(nullptr, SkTypeface::kNormal));
- SkAutoTUnref<SkTypeface> t2(SkTypeface::RefDefault(SkTypeface::kNormal));
+ sk_sp<SkTypeface> t1(SkTypeface::MakeFromName(nullptr, SkTypeface::kNormal));
+ sk_sp<SkTypeface> t2(SkTypeface::MakeDefault(SkTypeface::kNormal));
REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), t2.get()));
REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t1.get()));
@@ -22,8 +22,8 @@ DEF_TEST(Typeface, reporter) {
REPORTER_ASSERT(reporter, SkTypeface::Equal(t2.get(), 0));
#ifdef SK_BUILD_FOR_ANDROID
- SkAutoTUnref<SkTypeface> t3(SkTypeface::CreateFromName("non-existent-font", SkTypeface::kNormal));
- REPORTER_ASSERT(reporter, nullptr == t3.get());
+ sk_sp<SkTypeface> t3(SkTypeface::MakeFromName("non-existent-font", SkTypeface::kNormal));
+ REPORTER_ASSERT(reporter, nullptr == t3);
#endif
}
diff --git a/tools/Resources.cpp b/tools/Resources.cpp
index 0117404ac2..6d3054ab33 100644
--- a/tools/Resources.cpp
+++ b/tools/Resources.cpp
@@ -49,10 +49,10 @@ SkStreamAsset* GetResourceAsStream(const char* resource) {
}
}
-SkTypeface* GetResourceAsTypeface(const char* resource) {
+sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) {
SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource));
if (!stream) {
return nullptr;
}
- return SkTypeface::CreateFromStream(stream.release());
+ return SkTypeface::MakeFromStream(stream.release());
}
diff --git a/tools/Resources.h b/tools/Resources.h
index 678e4c8627..8115fbbb85 100644
--- a/tools/Resources.h
+++ b/tools/Resources.h
@@ -22,6 +22,6 @@ void SetResourcePath(const char* );
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst);
sk_sp<SkImage> GetResourceAsImage(const char* resource);
SkStreamAsset* GetResourceAsStream(const char* resource);
-SkTypeface* GetResourceAsTypeface(const char* resource);
+sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource);
#endif // Resources_DEFINED
diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp
index 4a88fa1b33..b95a9b89d1 100644
--- a/tools/debugger/SkDrawCommand.cpp
+++ b/tools/debugger/SkDrawCommand.cpp
@@ -1214,8 +1214,7 @@ static void extract_json_paint_typeface(Json::Value& jsonPaint, UrlDataManager&
const void* data;
Json::ArrayIndex length = decode_data(jsonData, urlDataManager, &data);
SkMemoryStream buffer(data, length);
- SkTypeface* typeface = SkTypeface::Deserialize(&buffer);
- target->setTypeface(typeface);
+ target->setTypeface(SkTypeface::MakeDeserialize(&buffer));
}
}
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index f46ebb6e60..7343ce4744 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
@@ -75,17 +75,14 @@ const char* platform_os_emoji() {
return "";
}
-void emoji_typeface(SkAutoTUnref<SkTypeface>* tf) {
+sk_sp<SkTypeface> emoji_typeface() {
if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) {
- tf->reset(GetResourceAsTypeface("/fonts/Funkster.ttf"));
- return;
+ return MakeResourceAsTypeface("/fonts/Funkster.ttf");
}
if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) {
- tf->reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal));
- return;
+ return SkTypeface::MakeFromName("Apple Color Emoji", SkTypeface::kNormal);
}
- tf->reset(nullptr);
- return;
+ return nullptr;
}
const char* emoji_sample_text() {
@@ -159,13 +156,12 @@ SkColor color_to_565(SkColor color) {
return SkPixel16ToColor(color16);
}
-SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) {
+sk_sp<SkTypeface> create_portable_typeface(const char* name, SkTypeface::Style style) {
return create_font(name, style);
}
void set_portable_typeface(SkPaint* paint, const char* name, SkTypeface::Style style) {
- SkTypeface* face = create_font(name, style);
- SkSafeUnref(paint->setTypeface(face));
+ paint->setTypeface(create_font(name, style));
}
void write_pixels(SkCanvas* canvas, const SkBitmap& bitmap, int x, int y,
diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h
index 1d80731fd4..a16c2a2f6e 100644
--- a/tools/sk_tool_utils.h
+++ b/tools/sk_tool_utils.h
@@ -36,7 +36,7 @@ namespace sk_tool_utils {
/**
* Return a color emoji typeface if available.
*/
- void emoji_typeface(SkAutoTUnref<SkTypeface>* );
+ sk_sp<SkTypeface> emoji_typeface();
/**
* If the platform supports color emoji, return sample text the emoji can render.
@@ -77,7 +77,7 @@ namespace sk_tool_utils {
/**
* Returns a platform-independent text renderer.
*/
- SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style);
+ sk_sp<SkTypeface> create_portable_typeface(const char* name, SkTypeface::Style style);
/** Call to clean up portable font references. */
void release_portable_typefaces();
@@ -89,7 +89,7 @@ namespace sk_tool_utils {
void write_pixels(SkCanvas*, const SkBitmap&, int x, int y, SkColorType, SkAlphaType);
// private to sk_tool_utils
- SkTypeface* create_font(const char* name, SkTypeface::Style);
+ sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style);
/** Returns a newly created CheckerboardShader. */
sk_sp<SkShader> create_checkerboard_shader(SkColor c1, SkColor c2, int size);
diff --git a/tools/sk_tool_utils_font.cpp b/tools/sk_tool_utils_font.cpp
index adbfa1692b..f73576dbf6 100644
--- a/tools/sk_tool_utils_font.cpp
+++ b/tools/sk_tool_utils_font.cpp
@@ -29,7 +29,7 @@ void release_portable_typefaces() {
SK_DECLARE_STATIC_MUTEX(gTestFontMutex);
-SkTypeface* create_font(const char* name, SkTypeface::Style style) {
+sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style style) {
SkTestFontData* fontData = nullptr;
const SubFont* sub;
if (name) {
@@ -47,7 +47,8 @@ SkTypeface* create_font(const char* name, SkTypeface::Style style) {
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
// so we reimplement its core logic here inline without the recursive aspect.
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
- return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style));
+ return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name,
+ SkFontStyle::FromOldStyle(style)));
}
} else {
sub = &gSubFonts[gDefaultFontIndex];
@@ -65,7 +66,7 @@ SkTypeface* create_font(const char* name, SkTypeface::Style style) {
fontData->fFontCache = SkSafeRef(font);
}
}
- return new SkTestTypeface(font, SkFontStyle::FromOldStyle(style));
+ return sk_make_sp<SkTestTypeface>(font, SkFontStyle::FromOldStyle(style));
}
}
diff --git a/tools/using_skia_and_harfbuzz.cpp b/tools/using_skia_and_harfbuzz.cpp
index 413939d15b..86c9accd33 100644
--- a/tools/using_skia_and_harfbuzz.cpp
+++ b/tools/using_skia_and_harfbuzz.cpp
@@ -142,9 +142,7 @@ struct Face {
auto data = SkData::MakeFromFileName(path);
assert(data);
if (!data) { return; }
- fSkiaTypeface.reset(
- SkTypeface::CreateFromStream(
- new SkMemoryStream(data), index));
+ fSkiaTypeface = SkTypeface::MakeFromStream(new SkMemoryStream(data), index);
assert(fSkiaTypeface);
if (!fSkiaTypeface) { return; }
auto destroy = [](void *d) { static_cast<SkData*>(d)->unref(); };