diff options
author | scroggo <scroggo@google.com> | 2016-05-12 06:22:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-12 06:22:30 -0700 |
commit | 9a9a7b29e5e5916a7b6453cd124ca437f14b9da4 (patch) | |
tree | ad5b560f6ed5da12040e5665282fd2227c305ff8 | |
parent | a1b283345b27fef91908b104a30cb89e6fbdaade (diff) |
Revert of Move SkTypeface to sk_sp. (patchset #5 id:80001 of https://codereview.chromium.org/1933393002/ )
Reason for revert:
fontmgr_iterAndroid failing to draw emoji. E.g. 6296da736fbf40aae881650c239420f64e576c3f&unt=true&head=true&query=source_type%3Dgm">https://gold.skia.org/search2?blame=6296da736fbf40aae881650c239420f64e576c3f&unt=true&head=true&query=source_type%3Dgm
Original issue's description:
> Move SkTypeface to sk_sp.
>
> Committed: https://skia.googlesource.com/skia/+/6296da736fbf40aae881650c239420f64e576c3f
TBR=reed@google.com,fmalita@chromium.org,tomhudson@google.com,bungeman@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review-Url: https://codereview.chromium.org/1974783002
74 files changed, 417 insertions, 325 deletions
diff --git a/bench/CmapBench.cpp b/bench/CmapBench.cpp index 49e89bec8c..a2fb5065f4 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::MakeDefault()); + fPaint.setTypeface(SkTypeface::RefDefault())->unref(); } protected: diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp index c5e40af746..2e0429fce3 100644 --- a/bench/SkGlyphCacheBench.cpp +++ b/bench/SkGlyphCacheBench.cpp @@ -53,15 +53,18 @@ 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(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic)); + paint.setTypeface(typeface); for (int work = 0; work < loops; work++) { do_font_stuff(&paint); } SkGraphics::SetFontCacheLimit(oldCacheLimitSize); + SkSafeUnref(typeface); } private: @@ -87,7 +90,7 @@ protected: void onDraw(int loops, SkCanvas*) override { size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit(); SkGraphics::SetFontCacheLimit(fCacheSize); - sk_sp<SkTypeface> typefaces[] = + SkTypeface* typefaces[] = {sk_tool_utils::create_portable_typeface("serif", SkTypeface::kItalic), sk_tool_utils::create_portable_typeface("sans-serif", SkTypeface::kItalic)}; @@ -101,6 +104,8 @@ protected: }); } SkGraphics::SetFontCacheLimit(oldCacheLimitSize); + SkSafeUnref(typefaces[0]); + SkSafeUnref(typefaces[1]); } private: diff --git a/bench/TextBench.cpp b/bench/TextBench.cpp index a048ffd4a1..04f824c700 100644 --- a/bench/TextBench.cpp +++ b/bench/TextBench.cpp @@ -47,7 +47,7 @@ class TextBench : public Benchmark { FontQuality fFQ; bool fDoPos; bool fDoColorEmoji; - sk_sp<SkTypeface> fColorEmojiTypeface; + SkAutoTUnref<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 = MakeResourceAsTypeface("/fonts/Funkster.ttf"); + fColorEmojiTypeface.reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); } if (fDoPos) { diff --git a/bench/TextBlobBench.cpp b/bench/TextBlobBench.cpp index 37bf311119..a350e7b4c4 100644 --- a/bench/TextBlobBench.cpp +++ b/bench/TextBlobBench.cpp @@ -23,11 +23,13 @@ */ class TextBlobBench : public Benchmark { public: - TextBlobBench() {} + TextBlobBench() + : fTypeface(nullptr) { + } protected: void onDelayedSetup() override { - fTypeface = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal); + fTypeface.reset(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal)); // make textblob SkPaint paint; paint.setTypeface(fTypeface); @@ -62,9 +64,9 @@ protected: private: - SkAutoTUnref<const SkTextBlob> fBlob; - SkTDArray<uint16_t> fGlyphs; - sk_sp<SkTypeface> fTypeface; + SkAutoTUnref<const SkTextBlob> fBlob; + SkTDArray<uint16_t> fGlyphs; + SkAutoTUnref<SkTypeface> fTypeface; typedef Benchmark INHERITED; }; @@ -1286,7 +1286,7 @@ SkThread* start_status_thread() { #define PORTABLE_FONT_PREFIX "Toy Liberation " -static sk_sp<SkTypeface> create_from_name(const char familyName[], SkTypeface::Style style) { +static 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 sk_sp<SkTypeface> create_from_name(const char familyName[], SkTypeface::S #undef PORTABLE_FONT_PREFIX -extern sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); +extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); int dm_main(); int dm_main() { diff --git a/fuzz/FilterFuzz.cpp b/fuzz/FilterFuzz.cpp index bbc403c636..cad32466fc 100644 --- a/fuzz/FilterFuzz.cpp +++ b/fuzz/FilterFuzz.cpp @@ -512,7 +512,9 @@ static SkPaint make_paint() { if (false) { // our validating buffer does not support typefaces yet, so skip this for now - paint.setTypeface(SkTypeface::MakeFromName(make_font_name().c_str(),make_typeface_style())); + SkAutoTUnref<SkTypeface> typeface( + SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style())); + paint.setTypeface(typeface); } SkLayerRasterizer::Builder rasterizerBuilder; diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp index b29040ac29..ebb3c6715c 100644 --- a/gm/coloremoji.cpp +++ b/gm/coloremoji.cpp @@ -50,11 +50,11 @@ public: protected: struct EmojiFont { - sk_sp<SkTypeface> typeface; + SkAutoTUnref<SkTypeface> typeface; const char* text; } emojiFont; virtual void onOnceBeforeDraw() override { - emojiFont.typeface = sk_tool_utils::emoji_typeface(); + sk_tool_utils::emoji_typeface(&emojiFont.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(sk_ref_sp(paint.getTypeface())); + shaderPaint.setTypeface(paint.getTypeface()); if (SkToBool(makeLinear)) { shaderPaint.setShader(MakeLinear()); } diff --git a/gm/colortype.cpp b/gm/colortype.cpp index 68dfeee535..c9314de2a4 100644 --- a/gm/colortype.cpp +++ b/gm/colortype.cpp @@ -12,7 +12,13 @@ class ColorTypeGM : public skiagm::GM { public: - ColorTypeGM() {} + ColorTypeGM() + : fColorType(nullptr) { + } + + virtual ~ColorTypeGM() { + SkSafeUnref(fColorType); + } protected: void onOnceBeforeDraw() override { @@ -27,11 +33,12 @@ protected: paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors), 0, &local)); - sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold)); + SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold); if (nullptr == orig) { - orig = SkTypeface::MakeDefault(); + orig = SkTypeface::RefDefault(); } - fColorType = sk_make_sp<SkGTypeface>(std::move(orig), paint); + fColorType = new SkGTypeface(orig, paint); + orig->unref(); } SkString onShortName() override { @@ -55,7 +62,7 @@ protected: } private: - sk_sp<SkTypeface> fColorType; + SkTypeface* fColorType; typedef skiagm::GM INHERITED; }; diff --git a/gm/colortypexfermode.cpp b/gm/colortypexfermode.cpp index 058b92d223..36db2aa3f5 100644 --- a/gm/colortypexfermode.cpp +++ b/gm/colortypexfermode.cpp @@ -19,7 +19,13 @@ class ColorTypeXfermodeGM : public GM { public: const static int W = 64; const static int H = 64; - ColorTypeXfermodeGM() {} + ColorTypeXfermodeGM() + : fColorType(nullptr) { + } + + virtual ~ColorTypeXfermodeGM() { + SkSafeUnref(fColorType); + } protected: void onOnceBeforeDraw() override { @@ -34,11 +40,12 @@ protected: paint.setShader(SkGradientShader::MakeSweep(0, 0, colors, nullptr, SK_ARRAY_COUNT(colors), 0, &local)); - sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold)); + SkTypeface* orig = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kBold); if (nullptr == orig) { - orig = SkTypeface::MakeDefault(); + orig = SkTypeface::RefDefault(); } - fColorType = sk_make_sp<SkGTypeface>(orig, paint); + fColorType = new SkGTypeface(orig, paint); + orig->unref(); fBG.installPixels(SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kOpaque_SkAlphaType), gData, 4); @@ -142,8 +149,8 @@ protected: } private: - SkBitmap fBG; - sk_sp<SkTypeface> fColorType; + SkBitmap fBG; + SkTypeface* fColorType; typedef GM INHERITED; }; diff --git a/gm/dftext.cpp b/gm/dftext.cpp index c7d9a8b1bf..e6aba0894e 100644 --- a/gm/dftext.cpp +++ b/gm/dftext.cpp @@ -19,7 +19,7 @@ public: protected: void onOnceBeforeDraw() override { - fEmojiTypeface = sk_tool_utils::emoji_typeface(); + sk_tool_utils::emoji_typeface(&fEmojiTypeface); fEmojiText = sk_tool_utils::emoji_sample_text(); } @@ -210,7 +210,7 @@ protected: } private: - sk_sp<SkTypeface> fEmojiTypeface; + SkAutoTUnref<SkTypeface> fEmojiTypeface; const char* fEmojiText; typedef skiagm::GM INHERITED; diff --git a/gm/fontcache.cpp b/gm/fontcache.cpp index c4af489304..30f8892c78 100644 --- a/gm/fontcache.cpp +++ b/gm/fontcache.cpp @@ -20,7 +20,15 @@ static SkScalar draw_string(SkCanvas* canvas, const SkString& text, SkScalar x, class FontCacheGM : public skiagm::GM { public: - FontCacheGM() {} + FontCacheGM() { + fTypefaces[0] = nullptr; + fTypefaces[1] = nullptr; + } + + virtual ~FontCacheGM() { + SkSafeUnref(fTypefaces[0]); + SkSafeUnref(fTypefaces[1]); + } protected: SkString onShortName() override { @@ -68,7 +76,7 @@ protected: } private: - sk_sp<SkTypeface> fTypefaces[2]; + SkTypeface* fTypefaces[2]; typedef GM INHERITED; }; diff --git a/gm/fontmgr.cpp b/gm/fontmgr.cpp index a4dc2631ec..1975f998cd 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); - sk_sp<SkTypeface> typeface(fm->matchFamilyStyleCharacter(fontName, fontStyle, - bcp47, bcp47Count, character)); - paint.setTypeface(typeface); + SkTypeface* typeface = fm->matchFamilyStyleCharacter(fontName, fontStyle, + bcp47, bcp47Count, character); + SkSafeUnref(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); - paint.setTypeface(sk_sp<SkTypeface>(fm->legacyCreateTypeface(familyName.c_str(), - typeface->fontStyle()))); + SkTypeface* typefaceCopy = fm->legacyCreateTypeface(familyName.c_str(), typeface->fontStyle()); + SkSafeUnref(paint.setTypeface(typefaceCopy)); 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()); - paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); + SkSafeUnref(paint.setTypeface(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()); - p.setTypeface(sk_sp<SkTypeface>(fset->createTypeface(j))); + SkSafeUnref(p.setTypeface(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); - sk_sp<SkTypeface> face(fset->matchStyle(fs)); + SkTypeface* face = fset->matchStyle(fs); if (face) { SkString str; str.printf("request [%d %d]", fs.weight(), fs.width()); - p.setTypeface(std::move(face)); + p.setTypeface(face)->unref(); (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) { - paint.setTypeface(sk_sp<SkTypeface>(set->createTypeface(j))); + SkSafeUnref(paint.setTypeface(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 b4f2ca370c..f83365bb3e 100644 --- a/gm/fontscalerdistortable.cpp +++ b/gm/fontscalerdistortable.cpp @@ -58,8 +58,9 @@ 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 } }; - paint.setTypeface(sk_sp<SkTypeface>(fontMgr->createFromStream( - distortable->duplicate(), SkFontMgr::FontParameters().setAxes(axes, 1)))); + SkAutoTUnref<SkTypeface> typeface(fontMgr->createFromStream( + distortable->duplicate(), SkFontMgr::FontParameters().setAxes(axes, 1))); + paint.setTypeface(typeface); SkAutoCanvasRestore acr(canvas, true); canvas->translate(SkIntToScalar(30 + i * 100), SkIntToScalar(20)); diff --git a/gm/gammatext.cpp b/gm/gammatext.cpp index c7d4309f97..bc5feb3375 100644 --- a/gm/gammatext.cpp +++ b/gm/gammatext.cpp @@ -19,8 +19,12 @@ static sk_sp<SkShader> make_heatGradient(const SkPoint pts[2]) { } static bool setFont(SkPaint* paint, const char name[]) { - paint->setTypeface(SkTypeface::MakeFromName(name, SkTypeface::kNormal)); - return SkToBool(paint->getTypeface()); + SkTypeface* tf = SkTypeface::CreateFromName(name, SkTypeface::kNormal); + if (tf) { + paint->setTypeface(tf)->unref(); + return true; + } + return false; } /** @@ -104,7 +108,8 @@ static sk_sp<SkShader> make_gradient(SkColor c) { } static void set_face(SkPaint* paint) { - paint->setTypeface(SkTypeface::MakeFromName("serif", SkTypeface::kItalic)); + SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); + SkSafeUnref(paint->setTypeface(face)); } static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& shader) { diff --git a/gm/mixedtextblobs.cpp b/gm/mixedtextblobs.cpp index 9a9bded1db..e66e73caf3 100644 --- a/gm/mixedtextblobs.cpp +++ b/gm/mixedtextblobs.cpp @@ -39,9 +39,9 @@ public: protected: void onOnceBeforeDraw() override { - fEmojiTypeface = sk_tool_utils::emoji_typeface(); + sk_tool_utils::emoji_typeface(&fEmojiTypeface); fEmojiText = sk_tool_utils::emoji_sample_text(); - fReallyBigATypeface = MakeResourceAsTypeface("/fonts/ReallyBigA.ttf"); + fReallyBigATypeface.reset(GetResourceAsTypeface("/fonts/ReallyBigA.ttf")); SkTextBlobBuilder builder; @@ -150,8 +150,8 @@ protected: } private: - sk_sp<SkTypeface> fEmojiTypeface; - sk_sp<SkTypeface> fReallyBigATypeface; + SkAutoTUnref<SkTypeface> fEmojiTypeface; + SkAutoTUnref<SkTypeface> fReallyBigATypeface; const char* fEmojiText; SkAutoTUnref<const SkTextBlob> fBlob; diff --git a/gm/pdf_never_embed.cpp b/gm/pdf_never_embed.cpp index 4fba40e282..ef7974e3d7 100644 --- a/gm/pdf_never_embed.cpp +++ b/gm/pdf_never_embed.cpp @@ -25,15 +25,16 @@ 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(MakeResourceAsTypeface("fonts/Roboto2-Regular_NoEmbed.ttf")); + p.setTypeface(typeface); 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 4eb99361c8..ea77033837 100644 --- a/gm/poly2poly.cpp +++ b/gm/poly2poly.cpp @@ -224,7 +224,7 @@ protected: } void onOnceBeforeDraw() override { - fEmFace = MakeResourceAsTypeface("/fonts/Em.ttf"); + fEmFace.reset(GetResourceAsTypeface("/fonts/Em.ttf")); } void onDraw(SkCanvas* canvas) override { @@ -273,7 +273,7 @@ protected: private: typedef skiagm::GM INHERITED; - sk_sp<SkTypeface> fEmFace; + SkAutoTUnref<SkTypeface> fEmFace; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/gm/textblob.cpp b/gm/textblob.cpp index 525cfd292d..02f3c878a3 100644 --- a/gm/textblob.cpp +++ b/gm/textblob.cpp @@ -72,7 +72,7 @@ public: protected: void onOnceBeforeDraw() override { - fTypeface = sk_tool_utils::create_portable_typeface("serif", SkTypeface::kNormal); + fTypeface.reset(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; - sk_sp<SkTypeface> fTypeface; - const char* fText; + SkTDArray<uint16_t> fGlyphs; + SkAutoTUnref<SkTypeface> fTypeface; + const char* fText; typedef skiagm::GM INHERITED; }; diff --git a/gm/textblobmixedsizes.cpp b/gm/textblobmixedsizes.cpp index 8f5dc85e48..9e57c2fe97 100644 --- a/gm/textblobmixedsizes.cpp +++ b/gm/textblobmixedsizes.cpp @@ -27,6 +27,7 @@ public: protected: void onOnceBeforeDraw() override { + SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/HangingS.ttf")); SkTextBlobBuilder builder; // make textblob. To stress distance fields, we choose sizes appropriately @@ -34,7 +35,7 @@ protected: paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setLCDRenderText(true); - paint.setTypeface(MakeResourceAsTypeface("/fonts/HangingS.ttf")); + paint.setTypeface(typeface); const char* text = "Skia"; diff --git a/gm/textblobrandomfont.cpp b/gm/textblobrandomfont.cpp index 51dbfceab3..267fe7a320 100644 --- a/gm/textblobrandomfont.cpp +++ b/gm/textblobrandomfont.cpp @@ -39,12 +39,13 @@ protected: paint.setLCDRenderText(true); // Setup our random scaler context - sk_sp<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-serif", - SkTypeface::kBold)); + SkAutoTUnref<SkTypeface> orig(sk_tool_utils::create_portable_typeface("sans-serif", + SkTypeface::kBold)); if (nullptr == orig) { - orig = SkTypeface::MakeDefault(); + orig.reset(SkTypeface::RefDefault()); } - paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false)); + SkAutoTUnref<SkTypeface> random(new SkRandomTypeface(orig, paint, false)); + paint.setTypeface(random); SkRect bounds; paint.measureText(text, strlen(text), &bounds); @@ -65,14 +66,16 @@ protected: sk_tool_utils::add_to_text_blob(&builder, bigtext2, paint, 0, offset); // color emoji - sk_sp<SkTypeface> origEmoji = sk_tool_utils::emoji_typeface(); + SkAutoTUnref<SkTypeface> origEmoji; + sk_tool_utils::emoji_typeface(&origEmoji); 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(); - paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, false)); + SkAutoTUnref<SkTypeface> randomEmoji(new SkRandomTypeface(orig, paint, false)); + paint.setTypeface(randomEmoji); sk_tool_utils::add_to_text_blob(&builder, emojiText, paint, 0, offset); } diff --git a/gm/typeface.cpp b/gm/typeface.cpp index e77d27747f..d88efa51bf 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 { - sk_sp<SkTypeface> fFaces[gFaceStylesCount]; + SkTypeface* fFaces[gFaceStylesCount]; bool fApplyKerning; public: @@ -99,10 +99,16 @@ 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::MakeFromName( + fFaces[i] = SkTypeface::CreateFromName( sk_tool_utils::platform_font_name(gFaceStyles[i].fName), gFaceStyles[i].fStyle); } } diff --git a/gm/variedtext.cpp b/gm/variedtext.cpp index e295cbc998..83fe7201fd 100644 --- a/gm/variedtext.cpp +++ b/gm/variedtext.cpp @@ -21,6 +21,13 @@ 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: @@ -51,11 +58,11 @@ protected: SkScalar w = SkIntToScalar(size.fWidth); SkScalar h = SkIntToScalar(size.fHeight); - 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); + 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); SkRandom random; for (int i = 0; i < kCnt; ++i) { @@ -75,11 +82,12 @@ protected: fPtSizes[i] = random.nextRangeScalar(kMinPtSize, kMaxPtSize); - fTypefaceIndices[i] = random.nextULessThan(SK_ARRAY_COUNT(fTypefaces)); + fTypefaces[i] = fTypefacesToUnref[ + random.nextULessThan(SK_ARRAY_COUNT(fTypefacesToUnref))]; SkRect r; fPaint.setColor(fColors[i]); - fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); + fPaint.setTypeface(fTypefaces[i]); fPaint.setTextSize(fPtSizes[i]); fPaint.measureText(fStrings[i].c_str(), fStrings[i].size(), &r); @@ -108,7 +116,7 @@ protected: for (int i = 0; i < kCnt; ++i) { fPaint.setColor(fColors[i]); fPaint.setTextSize(fPtSizes[i]); - fPaint.setTypeface(fTypefaces[fTypefaceIndices[i]]); + fPaint.setTypeface(fTypefaces[i]); canvas->save(); canvas->clipRect(fClipRects[i]); @@ -138,14 +146,14 @@ private: bool fEffectiveClip; bool fLCD; - sk_sp<SkTypeface> fTypefaces[4]; + SkTypeface* fTypefacesToUnref[4]; SkPaint fPaint; // precomputed for each text draw SkString fStrings[kCnt]; SkColor fColors[kCnt]; SkScalar fPtSizes[kCnt]; - int fTypefaceIndices[kCnt]; + SkTypeface* fTypefaces[kCnt]; SkPoint fPositions[kCnt]; SkRect fClipRects[kCnt]; diff --git a/gm/verttext2.cpp b/gm/verttext2.cpp index 79cbdbcc8b..12576c2699 100644 --- a/gm/verttext2.cpp +++ b/gm/verttext2.cpp @@ -17,15 +17,23 @@ namespace skiagm { class VertText2GM : public GM { public: - VertText2GM() {} + VertText2GM() + : fProp(nullptr) + , fMono(nullptr) { + } + + virtual ~VertText2GM() { + SkSafeUnref(fProp); + SkSafeUnref(fMono); + } protected: void onOnceBeforeDraw() override { const int pointSize = 24; textHeight = SkIntToScalar(pointSize); - fProp = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("sans-serif"), + fProp = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("sans-serif"), SkTypeface::kNormal); - fMono = SkTypeface::MakeFromName(sk_tool_utils::platform_font_name("monospace"), + fMono = SkTypeface::CreateFromName(sk_tool_utils::platform_font_name("monospace"), SkTypeface::kNormal); } @@ -66,13 +74,13 @@ protected: } void drawText(SkCanvas* canvas, const SkString& string, - sk_sp<SkTypeface> family, SkPaint::Align alignment) { + SkTypeface* family, SkPaint::Align alignment) { SkPaint paint; paint.setColor(SK_ColorBLACK); paint.setAntiAlias(true); paint.setVerticalText(true); paint.setTextAlign(alignment); - paint.setTypeface(std::move(family)); + paint.setTypeface(family); paint.setTextSize(textHeight); canvas->drawText(string.c_str(), string.size(), y, @@ -84,8 +92,8 @@ protected: private: typedef GM INHERITED; SkScalar y, textHeight; - sk_sp<SkTypeface> fProp; - sk_sp<SkTypeface> fMono; + SkTypeface* fProp; + SkTypeface* fMono; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi index 619e42ed52..55123335e3 100644 --- a/gyp/skia_for_android_framework_defines.gypi +++ b/gyp/skia_for_android_framework_defines.gypi @@ -28,7 +28,6 @@ '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 6c231c963a..e4ebebb244 100644 --- a/include/core/SkFont.h +++ b/include/core/SkFont.h @@ -117,17 +117,17 @@ public: kLCD_MaskType, }; - 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); + static SkFont* Create(SkTypeface*, SkScalar size, MaskType, uint32_t flags); + static SkFont* Create(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. */ - sk_sp<SkFont> makeWithSize(SkScalar size) const; + SkFont* cloneWithSize(SkScalar size) const; - SkTypeface* getTypeface() const { return fTypeface.get(); } + SkTypeface* getTypeface() const { return fTypeface; } 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 sk_sp<SkFont> Testing_CreateFromPaint(const SkPaint&); + static SkFont* Testing_CreateFromPaint(const SkPaint&); private: enum { kAllFlags = 0xFF, }; - SkFont(sk_sp<SkTypeface>, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, - uint32_t flags); + SkFont(SkTypeface*, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType, uint32_t flags); + virtual ~SkFont(); - sk_sp<SkTypeface> fTypeface; + SkTypeface* fTypeface; SkScalar fSize; SkScalar fScaleX; SkScalar fSkewX; diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 293ffedc12..7367fc642d 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -614,10 +614,8 @@ public: paint @return typeface */ - void setTypeface(sk_sp<SkTypeface>); -#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR SkTypeface* setTypeface(SkTypeface* typeface); -#endif + void setTypeface(sk_sp<SkTypeface>); /** Get the paint's rasterizer (or NULL). <p /> diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 3a47bd2bb3..f22d2bd14f 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -92,75 +92,51 @@ public: */ static bool Equal(const SkTypeface* facea, const SkTypeface* faceb); - /** 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 + /** + * 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); - /** 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. + /** 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 @param familyName May be NULL. The name of the font family. @param style The style (normal, bold, italic) of the typeface. - @return the closest-matching typeface. + @return reference to the closest-matching typeface. Call must call + unref() when they are done. */ - 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 + static SkTypeface* CreateFromName(const char familyName[], Style style); - /** 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. + /** 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. @param family May be NULL. The name of the existing type face. @param s The style (normal, bold, italic) of the type face. - @return the closest-matching typeface. + @return reference to the closest-matching typeface. Call must call + unref() when they are done. */ - 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 + static SkTypeface* CreateFromTypeface(const SkTypeface* family, Style s); /** Return a new typeface given a file. If the file does not exist, or is - not a valid font file, returns nullptr. + not a valid font file, returns null. */ - 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 + static SkTypeface* CreateFromFile(const char path[], int index = 0); /** Return a new typeface given a stream. If the stream is - not a valid font file, returns nullptr. Ownership of the stream is + not a valid font file, returns null. Ownership of the stream is transferred, so the caller must not reference it again. */ - 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 + static SkTypeface* CreateFromStream(SkStreamAsset* stream, int index = 0); /** Return a new typeface given font data and configuration. If the data - is not valid font data, returns nullptr. Ownership of the font data is + is not valid font data, returns null. Ownership of the font data is transferred, so the caller must not reference it again. */ - static sk_sp<SkTypeface> MakeFromFontData(SkFontData*); -#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR - static SkTypeface* CreateFromFontData(SkFontData* fd) { - return MakeFromFontData(fd).release(); - } -#endif + static SkTypeface* CreateFromFontData(SkFontData*); /** Write a unique signature to a stream, sufficient to reconstruct a typeface referencing the same font when Deserialize is called. @@ -168,16 +144,12 @@ public: void serialize(SkWStream*) const; /** Given the data previously written by serialize(), return a new instance - of a typeface referring to the same font. If that font is not available, - return nullptr. + 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. Does not affect ownership of SkStream. */ - static sk_sp<SkTypeface> MakeDeserialize(SkStream*); -#ifdef SK_SUPPORT_LEGACY_TYPEFACE_PTR - static SkTypeface* Deserialize(SkStream* stream) { - return MakeDeserialize(stream).release(); - } -#endif + static SkTypeface* Deserialize(SkStream*); enum Encoding { kUTF8_Encoding, @@ -423,6 +395,9 @@ 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 dfa5bd0b13..9f98e356d2 100644 --- a/include/ports/SkFontConfigInterface.h +++ b/include/ports/SkFontConfigInterface.h @@ -97,15 +97,12 @@ 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 this->makeTypeface(identity).release(); + return SkTypeface::CreateFromStream(this->openStream(identity), identity.fTTCIndex); } -#endif /** * Return a singleton instance of a direct subclass that calls into diff --git a/public.bzl b/public.bzl index 4cd21454d5..8eb4d855d9 100644 --- a/public.bzl +++ b/public.bzl @@ -590,7 +590,6 @@ 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 7c6158ada3..6e2b2b1585 100644 --- a/samplecode/ClockFaceView.cpp +++ b/samplecode/ClockFaceView.cpp @@ -170,17 +170,21 @@ static void apply_shader(SkPaint* paint, float scale) } class ClockFaceView : public SkView { - sk_sp<SkTypeface> fFace; + SkTypeface* fFace; SkScalar fInterp; SkScalar fDx; public: ClockFaceView() { - fFace = SkTypeface::MakeFromFile("/Users/reed/Downloads/p052024l.pfb"); + fFace = SkTypeface::CreateFromFile("/Users/reed/Downloads/p052024l.pfb"); fInterp = 0; fDx = SK_Scalar1/64; } + virtual ~ClockFaceView() { + SkSafeUnref(fFace); + } + protected: // overrides from SkEventSink virtual bool onQuery(SkEvent* evt) { @@ -221,7 +225,8 @@ protected: paint.setAntiAlias(true); paint.setTextSize(SkIntToScalar(240)); - paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkTypeface::kBold)); + paint.setTypeface(SkTypeface::CreateFromName("sans-serif", + SkTypeface::kBold)); SkString str("9"); diff --git a/samplecode/SampleAll.cpp b/samplecode/SampleAll.cpp index 738b34e3ae..357a437a67 100644 --- a/samplecode/SampleAll.cpp +++ b/samplecode/SampleAll.cpp @@ -527,7 +527,8 @@ protected: paint.setAntiAlias(true); paint.setTextSize(SkIntToScalar(48)); - paint.setTypeface(SkTypeface::MakeFromName("sans-serif", SkTypeface::kBold)); + paint.setTypeface(SkTypeface::CreateFromName("sans-serif", + SkTypeface::kBold)); SkString str("GOOGLE"); diff --git a/samplecode/SampleAnimatedText.cpp b/samplecode/SampleAnimatedText.cpp index 6bd6d82e8c..89ea6923d7 100755 --- a/samplecode/SampleAnimatedText.cpp +++ b/samplecode/SampleAnimatedText.cpp @@ -73,7 +73,7 @@ protected: void onDrawContent(SkCanvas* canvas) override { SkPaint paint; - paint.setTypeface(SkTypeface::MakeFromFile("/skimages/samplefont.ttf")); + SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromFile("/skimages/samplefont.ttf"))); paint.setAntiAlias(true); paint.setFilterQuality(kMedium_SkFilterQuality); diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index e4362c5a36..1df96c80c8 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::MakeFromTypeface(nullptr, SkTypeface::kBold); + fTypeface = SkTypeface::CreateFromTypeface(nullptr, SkTypeface::kBold); fShowZoomer = false; fZoomLevel = 0; @@ -1061,6 +1061,7 @@ 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 7734ac93d9..ad7a871b98 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. - sk_sp<SkTypeface> fTypeface; + SkTypeface* fTypeface; bool fShowZoomer; SkOSMenu::TriState fLCDState; diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index 88372414ca..6a4f1f822f 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -515,8 +515,9 @@ static SkPaint make_paint() { if (false) { // our validating buffer does not support typefaces yet, so skip this for now - paint.setTypeface(SkTypeface::MakeFromName(make_font_name().c_str(), - make_typeface_style())); + SkAutoTUnref<SkTypeface> typeface( + SkTypeface::CreateFromName(make_font_name().c_str(), make_typeface_style())); + paint.setTypeface(typeface); } SkLayerRasterizer::Builder rasterizerBuilder; diff --git a/samplecode/SampleFontScalerTest.cpp b/samplecode/SampleFontScalerTest.cpp index 72371ed807..ce3b81ee8a 100644 --- a/samplecode/SampleFontScalerTest.cpp +++ b/samplecode/SampleFontScalerTest.cpp @@ -36,16 +36,23 @@ static const struct { static const int gFaceCount = SK_ARRAY_COUNT(gFaces); class FontScalerTestView : public SampleView { - sk_sp<SkTypeface> fFaces[gFaceCount]; + SkTypeface* fFaces[gFaceCount]; public: FontScalerTestView() { for (int i = 0; i < gFaceCount; i++) { - fFaces[i] = SkTypeface::MakeFromName(gFaces[i].fName, gFaces[i].fStyle); + fFaces[i] = SkTypeface::CreateFromName(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) { @@ -85,7 +92,7 @@ protected: // paint.setSubpixelText(true); paint.setAntiAlias(true); paint.setLCDRenderText(true); - paint.setTypeface(SkTypeface::MakeFromName("Times Roman", SkTypeface::kNormal)); + SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("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 edc2dd77a2..9f57907626 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::MakeFromName("Georgia", SkTypeface::kItalic)); + paint.setTypeface(SkTypeface::CreateFromName("Georgia", SkTypeface::kItalic)); paint.setTextSize(75); paint.setAntiAlias(true); paint.setColor(SK_ColorBLUE); diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp index ca09cc749a..6dca10017a 100644 --- a/samplecode/SampleText.cpp +++ b/samplecode/SampleText.cpp @@ -122,7 +122,7 @@ protected: // canvas->drawText(style, strlen(style), SkIntToScalar(20), SkIntToScalar(20), paint); - paint.setTypeface(SkTypeface::MakeFromFile("/skimages/samplefont.ttf")); + SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromFile("/skimages/samplefont.ttf"))); paint.setAntiAlias(true); paint.setFlags(paint.getFlags() | gHints[index].fFlags); diff --git a/samplecode/SampleXfermodesBlur.cpp b/samplecode/SampleXfermodesBlur.cpp index 8a69f000f8..af75f89388 100644 --- a/samplecode/SampleXfermodesBlur.cpp +++ b/samplecode/SampleXfermodesBlur.cpp @@ -28,7 +28,9 @@ #include "SkBlurMaskFilter.h" static void setNamedTypeface(SkPaint* paint, const char name[]) { - paint->setTypeface(SkTypeface::MakeFromName(name, SkTypeface::kNormal)); + SkTypeface* face = SkTypeface::CreateFromName(name, SkTypeface::kNormal); + paint->setTypeface(face); + SkSafeUnref(face); } static uint16_t gBG[] = { 0xFFFF, 0xCCCF, 0xCCCF, 0xFFFF }; @@ -90,7 +92,8 @@ protected: SkPaint paint; paint.setAntiAlias(true); paint.setTextSize(50); - paint.setTypeface(SkTypeface::MakeFromName("Arial Unicode MS", SkTypeface::kNormal)); + paint.setTypeface(SkTypeface::CreateFromName("Arial Unicode MS", SkTypeface::kNormal)); + SkSafeUnref(paint.getTypeface()); 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 1026630eb1..1336ea2dc4 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) - paint->setTypeface(typeface->getTypeface()); + SkSafeUnref(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 5d94f049e8..a7e28ed3e2 100644 --- a/src/animator/SkPaintPart.h +++ b/src/animator/SkPaintPart.h @@ -62,7 +62,8 @@ class SkDrawTypeface : public SkPaintPart { #ifdef SK_DUMP_ENABLED void dump(SkAnimateMaker *) override; #endif - sk_sp<SkTypeface> getTypeface() { return SkTypeface::MakeFromName(fontName.c_str(), style); } + SkTypeface* getTypeface() { + return SkTypeface::CreateFromName(fontName.c_str(), style); } protected: bool add() override; SkString fontName; diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp index 1300011ec4..c39cc185d3 100644 --- a/src/core/SkFont.cpp +++ b/src/core/SkFont.cpp @@ -9,9 +9,13 @@ #include "SkTypeface.h" #include "SkUtils.h" -SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX, MaskType mt, +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, uint32_t flags) - : fTypeface(face ? std::move(face) : SkTypeface::MakeDefault()) + : fTypeface(ref_or_default(face)) , fSize(size) , fScaleX(scaleX) , fSkewX(skewX) @@ -24,8 +28,8 @@ SkFont::SkFont(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar SkASSERT(0 == (flags & ~kAllFlags)); } -sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scaleX, SkScalar skewX, - MaskType mt, uint32_t flags) { +SkFont* SkFont::Create(SkTypeface* face, SkScalar size, SkScalar scaleX, SkScalar skewX, + MaskType mt, uint32_t flags) { if (size <= 0 || !SkScalarIsFinite(size)) { return nullptr; } @@ -36,20 +40,24 @@ sk_sp<SkFont> SkFont::Make(sk_sp<SkTypeface> face, SkScalar size, SkScalar scale return nullptr; } flags &= kAllFlags; - return sk_sp<SkFont>(new SkFont(std::move(face), size, scaleX, skewX, mt, flags)); + return new SkFont(face, size, scaleX, skewX, 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::Create(SkTypeface* face, SkScalar size, MaskType mt, uint32_t flags) { + return SkFont::Create(face, size, 1, 0, mt, flags); } -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::cloneWithSize(SkScalar newSize) const { + return SkFont::Create(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) { @@ -110,7 +118,7 @@ SkScalar SkFont::measureText(const void* text, size_t byteLength, SkTextEncoding #include "SkPaint.h" -sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) { +SkFont* SkFont::Testing_CreateFromPaint(const SkPaint& paint) { uint32_t flags = 0; if (paint.isVerticalText()) { flags |= kVertical_Flag; @@ -142,6 +150,7 @@ sk_sp<SkFont> SkFont::Testing_CreateFromPaint(const SkPaint& paint) { maskType = paint.isLCDRenderText() ? kLCD_MaskType : kA8_MaskType; } - return Make(sk_ref_sp(paint.getTypeface()), paint.getTextSize(), paint.getTextScaleX(), - paint.getTextSkewX(), maskType, flags); + return Create(paint.getTypeface(), + paint.getTextSize(), paint.getTextScaleX(), paint.getTextSkewX(), + maskType, flags); } diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 25b6aec1ec..67bbda1665 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -369,9 +369,7 @@ 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 @@ -1898,7 +1896,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) { this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF)); if (flatFlags & kHasTypeface_FlatFlag) { - this->setTypeface(sk_ref_sp(buffer.readTypeface())); + this->setTypeface(buffer.readTypeface()); } else { this->setTypeface(nullptr); } diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 873c0c4a1d..ed32c6c029 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++) { - sk_sp<SkTypeface> tf(SkTypeface::MakeDeserialize(stream)); + SkAutoTUnref<SkTypeface> tf(SkTypeface::Deserialize(stream)); if (!tf.get()) { // failed to deserialize // fTFPlayback asserts it never has a null, so we plop in // the default here. - tf = SkTypeface::MakeDefault(); + tf.reset(SkTypeface::RefDefault()); } - fTFPlayback.set(i, tf.get()); + fTFPlayback.set(i, tf); } } break; case SK_PICT_PICTURE_TAG: { diff --git a/src/core/SkTextBlob.cpp b/src/core/SkTextBlob.cpp index 1cbb2b6d6d..463312aa6d 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); + paint->setTypeface(fTypeface.get()); 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). - sk_sp<SkTypeface> fTypeface; + SkAutoTUnref<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 3c15878f73..75bb05c2b1 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 -sk_sp<SkTypeface> (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr; +SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = nullptr; void (*gSerializeTypefaceDelegate)(const SkTypeface*, SkWStream* ) = SK_TYPEFACE_DELEGATE; -sk_sp<SkTypeface> (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; +SkTypeface* (*gDeserializeTypefaceDelegate)(SkStream* ) = nullptr; /////////////////////////////////////////////////////////////////////////////// @@ -98,8 +98,8 @@ SkTypeface* SkTypeface::GetDefaultTypeface(Style style) { return defaults[style]; } -sk_sp<SkTypeface> SkTypeface::MakeDefault(Style style) { - return sk_ref_sp(GetDefaultTypeface(style)); +SkTypeface* SkTypeface::RefDefault(Style style) { + return SkRef(GetDefaultTypeface(style)); } uint32_t SkTypeface::UniqueID(const SkTypeface* face) { @@ -115,46 +115,47 @@ bool SkTypeface::Equal(const SkTypeface* facea, const SkTypeface* faceb) { /////////////////////////////////////////////////////////////////////////////// -sk_sp<SkTypeface> SkTypeface::MakeFromName(const char name[], Style style) { +SkTypeface* SkTypeface::CreateFromName(const char name[], Style style) { if (gCreateTypefaceDelegate) { - sk_sp<SkTypeface> result = (*gCreateTypefaceDelegate)(name, style); + SkTypeface* result = (*gCreateTypefaceDelegate)(name, style); if (result) { return result; } } if (nullptr == name) { - return MakeDefault(style); + return RefDefault(style); } SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style))); + return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)); } -sk_sp<SkTypeface> SkTypeface::MakeFromTypeface(SkTypeface* family, Style s) { +SkTypeface* SkTypeface::CreateFromTypeface(const SkTypeface* family, Style s) { if (!family) { - return SkTypeface::MakeDefault(s); + return SkTypeface::RefDefault(s); } if (family->style() == s) { - return sk_ref_sp(family); + family->ref(); + return const_cast<SkTypeface*>(family); } SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - return sk_sp<SkTypeface>(fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s))); + return fm->matchFaceStyle(family, SkFontStyle::FromOldStyle(s)); } -sk_sp<SkTypeface> SkTypeface::MakeFromStream(SkStreamAsset* stream, int index) { +SkTypeface* SkTypeface::CreateFromStream(SkStreamAsset* stream, int index) { SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - return sk_sp<SkTypeface>(fm->createFromStream(stream, index)); + return fm->createFromStream(stream, index); } -sk_sp<SkTypeface> SkTypeface::MakeFromFontData(SkFontData* data) { +SkTypeface* SkTypeface::CreateFromFontData(SkFontData* data) { SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - return sk_sp<SkTypeface>(fm->createFromFontData(data)); + return fm->createFromFontData(data); } -sk_sp<SkTypeface> SkTypeface::MakeFromFile(const char path[], int index) { +SkTypeface* SkTypeface::CreateFromFile(const char path[], int index) { SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault()); - return sk_sp<SkTypeface>(fm->createFromFile(path, index)); + return fm->createFromFile(path, index); } /////////////////////////////////////////////////////////////////////////////// @@ -175,7 +176,7 @@ void SkTypeface::serialize(SkWStream* wstream) const { desc.serialize(wstream); } -sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) { +SkTypeface* SkTypeface::Deserialize(SkStream* stream) { if (gDeserializeTypefaceDelegate) { return (*gDeserializeTypefaceDelegate)(stream); } @@ -187,12 +188,12 @@ sk_sp<SkTypeface> SkTypeface::MakeDeserialize(SkStream* stream) { SkFontData* data = desc.detachFontData(); if (data) { - sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); + SkTypeface* typeface = SkTypeface::CreateFromFontData(data); if (typeface) { return typeface; } } - return SkTypeface::MakeFromName(desc.getFamilyName(), desc.getStyle()); + return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); } /////////////////////////////////////////////////////////////////////////////// @@ -334,7 +335,7 @@ bool SkTypeface::onComputeBounds(SkRect* bounds) const { const SkScalar invTextSize = 1 / textSize; SkPaint paint; - paint.setTypeface(sk_ref_sp(const_cast<SkTypeface*>(this))); + paint.setTypeface(const_cast<SkTypeface*>(this)); paint.setTextSize(textSize); paint.setLinearText(true); diff --git a/src/core/SkTypefacePriv.h b/src/core/SkTypefacePriv.h index f8d7e63efd..dc993d0890 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 sk_sp<SkTypeface> ref_or_default(SkTypeface* face) { - return face ? sk_ref_sp(face) : SkTypeface::MakeDefault(); +static inline SkTypeface* ref_or_default(SkTypeface* face) { + return face ? SkRef(face) : SkTypeface::RefDefault(); } /** * 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 sk_sp<SkTypeface> { +class SkAutoResolveDefaultTypeface : public SkAutoTUnref<SkTypeface> { public: - SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::MakeDefault()) {} + SkAutoResolveDefaultTypeface() : INHERITED(SkTypeface::RefDefault()) {} SkAutoResolveDefaultTypeface(SkTypeface* face) : INHERITED(ref_or_default(face)) {} private: - typedef sk_sp<SkTypeface> INHERITED; + typedef SkAutoTUnref<SkTypeface> INHERITED; }; #endif diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp index 1d34536cbe..0a9601bd7e 100644 --- a/src/fonts/SkGScalerContext.cpp +++ b/src/fonts/SkGScalerContext.cpp @@ -151,11 +151,14 @@ void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { #include "SkTypefaceCache.h" -SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint) +SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint) : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) - , fProxy(std::move(proxy)) - , fPaint(paint) -{} + , fProxy(SkRef(proxy)) + , fPaint(paint) {} + +SkGTypeface::~SkGTypeface() { + fProxy->unref(); +} SkScalerContext* SkGTypeface::onCreateScalerContext(const SkScalerContextEffects& effects, const SkDescriptor* desc) const { diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h index 3eb25a81da..69d02ddf11 100644 --- a/src/fonts/SkGScalerContext.h +++ b/src/fonts/SkGScalerContext.h @@ -13,9 +13,10 @@ class SkGTypeface : public SkTypeface { public: - SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint&); + SkGTypeface(SkTypeface* proxy, const SkPaint&); + virtual ~SkGTypeface(); - SkTypeface* proxy() const { return fProxy.get(); } + SkTypeface* proxy() const { return fProxy; } const SkPaint& paint() const { return fPaint; } protected: @@ -42,8 +43,8 @@ protected: size_t length, void* data) const override; private: - sk_sp<SkTypeface> fProxy; - SkPaint fPaint; + SkTypeface* fProxy; + SkPaint fPaint; }; #endif diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp index 6d3718cbef..245052053e 100644 --- a/src/fonts/SkRandomScalerContext.cpp +++ b/src/fonts/SkRandomScalerContext.cpp @@ -190,12 +190,16 @@ void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { #include "SkTypefaceCache.h" -SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt) +SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint, bool fakeIt) : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) - , fProxy(std::move(proxy)) + , fProxy(SkRef(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 076689d93a..0e08f4b1ae 100644 --- a/src/fonts/SkRandomScalerContext.h +++ b/src/fonts/SkRandomScalerContext.h @@ -18,9 +18,10 @@ class SkRandomTypeface : public SkTypeface { public: - SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint&, bool fakeit); + SkRandomTypeface(SkTypeface* proxy, const SkPaint&, bool fakeit); + virtual ~SkRandomTypeface(); - SkTypeface* proxy() const { return fProxy.get(); } + SkTypeface* proxy() const { return fProxy; } const SkPaint& paint() const { return fPaint; } protected: @@ -47,9 +48,9 @@ protected: size_t length, void* data) const override; private: - sk_sp<SkTypeface> fProxy; - SkPaint fPaint; - bool fFakeIt; + SkTypeface* fProxy; + SkPaint fPaint; + bool fFakeIt; }; #endif diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 97be32c41d..7a66bcd1e9 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(sk_ref_sp(this->typeface())); + paint.setTypeface(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 3e6e0da18a..4aea047cde 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; - sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style)); + SkAutoTUnref<SkTypeface_AndroidSystem> face(family->matchStyle(style)); if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) { continue; @@ -387,6 +387,9 @@ 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 f0805b5432..4c679dfee7 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; - sk_sp<const SkTypeface> tface(paint.getTypeface() ? - sk_ref_sp(paint.getTypeface()) : SkTypeface::MakeDefault()); + SkAutoTUnref<const SkTypeface> tface(paint.getTypeface() ? + SkRef(paint.getTypeface()) : SkTypeface::RefDefault()); SkASSERT(tface); SkTypeface::Style style = tface->style(); diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp index 4409e477e5..886f3d4ffd 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(sk_ref_sp(get_ref<SkTypeface>(L, 2))); + get_obj<SkPaint>(L, 1)->setTypeface(get_ref<SkTypeface>(L, 2)); return 0; } @@ -2049,12 +2049,13 @@ static int lsk_newTypeface(lua_State* L) { } } - sk_sp<SkTypeface> face(SkTypeface::MakeFromName(name, (SkTypeface::Style)style)); + SkTypeface* face = SkTypeface::CreateFromName(name, + (SkTypeface::Style)style); // SkDebugf("---- name <%s> style=%d, face=%p ref=%d\n", name, style, face, face->getRefCnt()); if (nullptr == face) { - face = SkTypeface::MakeDefault(); + face = SkTypeface::RefDefault(); } - push_ref(L, std::move(face)); + push_ref(L, face)->unref(); return 1; } diff --git a/src/utils/SkWhitelistTypefaces.cpp b/src/utils/SkWhitelistTypefaces.cpp index 3368178769..66d32188a0 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* ); -sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* ); +extern 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; } - sk_sp<SkTypeface> defaultFace(SkTypeface::MakeFromName(nullptr, style)); - sk_sp<SkTypeface> foundFace(SkTypeface::MakeFromName(fontName, style)); + SkTypeface* defaultFace = SkTypeface::CreateFromName(nullptr, style); + SkTypeface* foundFace = SkTypeface::CreateFromName(fontName, style); return defaultFace != foundFace; } @@ -183,7 +183,7 @@ void WhitelistSerializeTypeface(const SkTypeface* tf, SkWStream* wstream) { serialize_sub(fontName, tf->style(), wstream); } -sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { +SkTypeface* WhitelistDeserializeTypeface(SkStream* stream) { SkFontDescriptor desc; if (!SkFontDescriptor::Deserialize(stream, &desc)) { return nullptr; @@ -191,7 +191,7 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { SkFontData* data = desc.detachFontData(); if (data) { - sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(data)); + SkTypeface* typeface = SkTypeface::CreateFromFontData(data); if (typeface) { return typeface; } @@ -200,14 +200,14 @@ sk_sp<SkTypeface> WhitelistDeserializeTypeface(SkStream* stream) { if (!strncmp(SUBNAME_PREFIX, familyName, sizeof(SUBNAME_PREFIX) - 1)) { familyName += sizeof(SUBNAME_PREFIX) - 1; } - return SkTypeface::MakeFromName(familyName, desc.getStyle()); + return SkTypeface::CreateFromName(familyName, desc.getStyle()); } bool CheckChecksums() { for (int i = 0; i < whitelistCount; ++i) { const char* fontName = whitelist[i].fFontName; - sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal)); - uint32_t checksum = compute_checksum(tf.get()); + SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal); + uint32_t checksum = compute_checksum(tf); 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; - sk_sp<SkTypeface> tf(SkTypeface::MakeFromName(fontName, SkTypeface::kNormal)); - uint32_t checksum = compute_checksum(tf.get()); + SkTypeface* tf = SkTypeface::CreateFromName(fontName, SkTypeface::kNormal); + uint32_t checksum = compute_checksum(tf); line.printf(checksumEntry, fontName, checksum); sk_fwrite(line.c_str(), line.size(), file); } diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp index ec32d9f031..0b436552a3 100644 --- a/tests/FontHostStreamTest.cpp +++ b/tests/FontHostStreamTest.cpp @@ -69,7 +69,9 @@ DEF_TEST(FontHostStream, reporter) { paint.setColor(SK_ColorGRAY); paint.setTextSize(SkIntToScalar(30)); - paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kNormal)); + SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia", + SkTypeface::kNormal); + SkSafeUnref(paint.setTypeface(fTypeface)); SkIRect origRect = SkIRect::MakeWH(64, 64); SkBitmap origBitmap; @@ -87,18 +89,23 @@ DEF_TEST(FontHostStream, reporter) { drawBG(&origCanvas); origCanvas.drawText("A", 1, point.fX, point.fY, paint); - sk_sp<SkTypeface> typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(paint.getTypeface()) - : SkTypeface::MakeDefault()); + SkTypeface* origTypeface = paint.getTypeface(); + SkAutoTUnref<SkTypeface> aur; + if (nullptr == origTypeface) { + aur.reset(SkTypeface::RefDefault()); + origTypeface = aur.get(); + } + int ttcIndex; - SkAutoTDelete<SkStreamAsset> fontData(typeface->openStream(&ttcIndex)); - sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(fontData.release())); + SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex)); + SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.release()); SkFontDescriptor desc; bool isLocalStream = false; streamTypeface->getFontDescriptor(&desc, &isLocalStream); REPORTER_ASSERT(reporter, isLocalStream); - paint.setTypeface(streamTypeface); + SkSafeUnref(paint.setTypeface(streamTypeface)); drawBG(&streamCanvas); streamCanvas.drawPosText("A", 1, &point, paint); diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp index ebcc4ab2ae..d9a3df414a 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, const sk_sp<SkTypeface>& face) { +static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) { int nativeUPEM = face->getUnitsPerEm(); int tableUPEM = -1; @@ -50,7 +50,7 @@ static void test_unitsPerEm(skiatest::Reporter* reporter, const sk_sp<SkTypeface // Test that countGlyphs() agrees with a direct lookup in the 'maxp' table // (if that table is available). -static void test_countGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) { +static void test_countGlyphs(skiatest::Reporter* reporter, 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, const sk_sp<SkTypeface>& face) { +static void test_charsToGlyphs(skiatest::Reporter* reporter, 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(MakeResourceAsTypeface("/fonts/SpiderSymbol.ttf")); + paint.setTypeface(typeface); 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, const sk_sp<SkTypeface>& face) { +static void test_tables(skiatest::Reporter* reporter, 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) { - sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTypeface::kNormal)); if (face) { #ifdef DUMP_TABLES SkDebugf("%s\n", gNames[i]); @@ -277,7 +277,8 @@ 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++) { - paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal)); + paint.setTypeface(face); 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 414631c58f..92dc18b135 100644 --- a/tests/FontMgrTest.cpp +++ b/tests/FontMgrTest.cpp @@ -19,7 +19,7 @@ static void test_font(skiatest::Reporter* reporter) { uint32_t flags = 0; - sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags)); + SkAutoTUnref<SkFont> font(SkFont::Create(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' - sk_sp<SkFont> newFont(font->makeWithSize(36)); + SkAutoTUnref<SkFont> newFont(font->cloneWithSize(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 = SkFont::Testing_CreateFromPaint(paint); + font.reset(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,12 +64,14 @@ static void test_alias_names(skiatest::Reporter* reporter) { }; for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) { - sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i], + SkTypeface::kNormal)); if (nullptr == first.get()) { continue; } for (int j = 0; j < 10; ++j) { - sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i], + SkTypeface::kNormal)); #if 0 SkString name; face->getFamilyName(&name); diff --git a/tests/FontObjTest.cpp b/tests/FontObjTest.cpp index 66c8bd500f..9d18ce6b2e 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) { - sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); + SkAutoTUnref<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,7 +78,8 @@ 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++) { - paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal)); + paint.setTypeface(face); for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) { paint.setHinting(settings[j].hinting); @@ -102,7 +103,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, width1 == width2); - sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint)); + SkAutoTUnref<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 07ddabc912..58dd773fb8 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(MakeResourceAsTypeface(resource)); + sk_sp<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource)); if (noEmbedTypeface) { REPORTER_ASSERT(reporter, !SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &canon)); diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp index f507467771..bd00adb18d 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::MakeDefault()); + paint.setTypeface(SkTypeface::RefDefault())->unref(); 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::MakeDefault()); + paint.setTypeface(SkTypeface::RefDefault())->unref(); 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 832a80f438..9e36d841df 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::MakeFromName("Arial", SkTypeface::kItalic)); + paint.setTypeface(SkTypeface::CreateFromName("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 9e9b221cd2..4750bbe25d 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(sk_sp<SkTypeface> typeface, const char* text, +static void serialize_and_compare_typeface(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(std::move(typeface)); + paint.setTypeface(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"); - sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile(filename.c_str(), 1)); + SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_str(), 1)); if (!typeface) { INFOF(reporter, "Could not run fontstream test because test.ttc not found."); } else { - serialize_and_compare_typeface(std::move(typeface), "A!", reporter); + serialize_and_compare_typeface(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; - sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData( + SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData( 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(std::move(typeface), "abc", reporter); + serialize_and_compare_typeface(typeface, "abc", reporter); } } } diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp index cbc6b99f84..23f45a4cad 100644 --- a/tests/TextBlobCacheTest.cpp +++ b/tests/TextBlobCacheTest.cpp @@ -99,11 +99,12 @@ 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 - sk_sp<SkTypeface> orig(set->createTypeface(j)); + SkAutoTUnref<SkTypeface> orig(set->createTypeface(j)); if (normal) { paint.setTypeface(orig); } else { - paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, true)); + SkAutoTUnref<SkTypeface> typeface(new SkRandomTypeface(orig, paint, true)); + paint.setTypeface(typeface); } SkTextBlobBuilder builder; diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp index 61070247b4..923669e8c5 100644 --- a/tests/TextBlobTest.cpp +++ b/tests/TextBlobTest.cpp @@ -178,10 +178,12 @@ 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(SkTypeface::MakeDefault()); + font.setTypeface(typeface); 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 6a606d4e95..950449d9c1 100644 --- a/tests/TypefaceTest.cpp +++ b/tests/TypefaceTest.cpp @@ -12,8 +12,8 @@ DEF_TEST(Typeface, reporter) { - sk_sp<SkTypeface> t1(SkTypeface::MakeFromName(nullptr, SkTypeface::kNormal)); - sk_sp<SkTypeface> t2(SkTypeface::MakeDefault(SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> t1(SkTypeface::CreateFromName(nullptr, SkTypeface::kNormal)); + SkAutoTUnref<SkTypeface> t2(SkTypeface::RefDefault(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 - sk_sp<SkTypeface> t3(SkTypeface::MakeFromName("non-existent-font", SkTypeface::kNormal)); - REPORTER_ASSERT(reporter, nullptr == t3); + SkAutoTUnref<SkTypeface> t3(SkTypeface::CreateFromName("non-existent-font", SkTypeface::kNormal)); + REPORTER_ASSERT(reporter, nullptr == t3.get()); #endif } diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 6d3054ab33..0117404ac2 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -49,10 +49,10 @@ SkStreamAsset* GetResourceAsStream(const char* resource) { } } -sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) { +SkTypeface* GetResourceAsTypeface(const char* resource) { SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource)); if (!stream) { return nullptr; } - return SkTypeface::MakeFromStream(stream.release()); + return SkTypeface::CreateFromStream(stream.release()); } diff --git a/tools/Resources.h b/tools/Resources.h index 8115fbbb85..678e4c8627 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); -sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource); +SkTypeface* GetResourceAsTypeface(const char* resource); #endif // Resources_DEFINED diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index b95a9b89d1..4a88fa1b33 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -1214,7 +1214,8 @@ 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); - target->setTypeface(SkTypeface::MakeDeserialize(&buffer)); + SkTypeface* typeface = SkTypeface::Deserialize(&buffer); + target->setTypeface(typeface); } } diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 7343ce4744..f46ebb6e60 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,14 +75,17 @@ const char* platform_os_emoji() { return ""; } -sk_sp<SkTypeface> emoji_typeface() { +void emoji_typeface(SkAutoTUnref<SkTypeface>* tf) { if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) { - return MakeResourceAsTypeface("/fonts/Funkster.ttf"); + tf->reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); + return; } if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { - return SkTypeface::MakeFromName("Apple Color Emoji", SkTypeface::kNormal); + tf->reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal)); + return; } - return nullptr; + tf->reset(nullptr); + return; } const char* emoji_sample_text() { @@ -156,12 +159,13 @@ SkColor color_to_565(SkColor color) { return SkPixel16ToColor(color16); } -sk_sp<SkTypeface> create_portable_typeface(const char* name, SkTypeface::Style style) { +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) { - paint->setTypeface(create_font(name, style)); + SkTypeface* face = create_font(name, style); + SkSafeUnref(paint->setTypeface(face)); } 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 a16c2a2f6e..1d80731fd4 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. */ - sk_sp<SkTypeface> emoji_typeface(); + void emoji_typeface(SkAutoTUnref<SkTypeface>* ); /** * 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. */ - sk_sp<SkTypeface> create_portable_typeface(const char* name, SkTypeface::Style style); + 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 - sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style); + 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 f73576dbf6..adbfa1692b 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); -sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style style) { +SkTypeface* create_font(const char* name, SkTypeface::Style style) { SkTestFontData* fontData = nullptr; const SubFont* sub; if (name) { @@ -47,8 +47,7 @@ sk_sp<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 sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, - SkFontStyle::FromOldStyle(style))); + return fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)); } } else { sub = &gSubFonts[gDefaultFontIndex]; @@ -66,7 +65,7 @@ sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style style) { fontData->fFontCache = SkSafeRef(font); } } - return sk_make_sp<SkTestTypeface>(font, SkFontStyle::FromOldStyle(style)); + return new SkTestTypeface(font, SkFontStyle::FromOldStyle(style)); } } diff --git a/tools/using_skia_and_harfbuzz.cpp b/tools/using_skia_and_harfbuzz.cpp index 86c9accd33..413939d15b 100644 --- a/tools/using_skia_and_harfbuzz.cpp +++ b/tools/using_skia_and_harfbuzz.cpp @@ -142,7 +142,9 @@ struct Face { auto data = SkData::MakeFromFileName(path); assert(data); if (!data) { return; } - fSkiaTypeface = SkTypeface::MakeFromStream(new SkMemoryStream(data), index); + fSkiaTypeface.reset( + SkTypeface::CreateFromStream( + new SkMemoryStream(data), index)); assert(fSkiaTypeface); if (!fSkiaTypeface) { return; } auto destroy = [](void *d) { static_cast<SkData*>(d)->unref(); }; |