aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-05-11 12:38:18 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-11 12:38:18 -0700
commit6296da736fbf40aae881650c239420f64e576c3f (patch)
tree5121ecf46ff7099d8eb66d2b2a4671d5ad94db89 /gm
parentc8699321b924c1f284df93cb29b86000c1d73c0a (diff)
Move SkTypeface to sk_sp.
Diffstat (limited to 'gm')
-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
17 files changed, 74 insertions, 129 deletions
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;
};
///////////////////////////////////////////////////////////////////////////////