Move SkTypeface::CreateXXX to SkTypeface::MakeXXX.

Skia is moving to returning smart pointers from its factory methods.
This updates uses of SkTypeface::CreateXXX to SkTypeface::MakeXXX and
generally updates use of SkTypeface to sk_sp. This will allow for the
removal of the SK_SUPPORT_LEGACY_TYPEFACE_PTR define.

Change-Id: If3e600c6cb86080576667bc77d427da4f6560afa
This commit is contained in:
Ben Wagner
2016-08-05 12:01:04 -04:00
parent 0e47edac42
commit 3ebdaaae86
5 changed files with 22 additions and 35 deletions

View File

@@ -6,17 +6,13 @@
namespace minikin {
MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) :
MinikinFontSkia::MinikinFontSkia(sk_sp<SkTypeface> typeface) :
MinikinFont(typeface->uniqueID()),
mTypeface(typeface) {
mTypeface(std::move(typeface)) {
}
MinikinFontSkia::~MinikinFontSkia() {
SkSafeUnref(mTypeface);
}
static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) {
skPaint->setTypeface(typeface);
static void MinikinFontSkia_SetSkiaPaint(sk_sp<SkTypeface> typeface, SkPaint* skPaint, const MinikinPaint& paint) {
skPaint->setTypeface(std::move(typeface));
skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
// TODO: set more paint parameters from Minikin
skPaint->setTextSize(paint.size);
@@ -65,7 +61,7 @@ const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroy
}
SkTypeface *MinikinFontSkia::GetSkTypeface() {
return mTypeface;
return mTypeface.get();
}
} // namespace minikin

View File

@@ -17,9 +17,7 @@ namespace minikin {
class MinikinFontSkia : public MinikinFont {
public:
explicit MinikinFontSkia(SkTypeface *typeface);
~MinikinFontSkia();
explicit MinikinFontSkia(sk_sp<SkTypeface> typeface);
float GetHorizontalAdvance(uint32_t glyph_id,
const MinikinPaint &paint) const;
@@ -32,7 +30,7 @@ public:
SkTypeface *GetSkTypeface();
private:
SkTypeface *mTypeface;
sk_sp<SkTypeface> mTypeface;
};

View File

@@ -57,8 +57,8 @@ FontCollection *makeFontCollection() {
FontFamily *family = new FontFamily();
for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) {
const char *fn = fns[i];
SkTypeface *skFace = SkTypeface::CreateFromFile(fn);
MinikinFont *font = new MinikinFontSkia(skFace);
sk_sp<SkTypeface> skFace = SkTypeface::MakeFromFile(fn);
MinikinFont *font = new MinikinFontSkia(std::move(skFace));
family->addFont(font);
}
typefaces.push_back(family);
@@ -66,8 +66,8 @@ FontCollection *makeFontCollection() {
#if 1
family = new FontFamily();
const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf";
SkTypeface *skFace = SkTypeface::CreateFromFile(fn);
MinikinFont *font = new MinikinFontSkia(skFace);
sk_sp<SkTypeface> skFace = SkTypeface::MakeFromFile(fn);
MinikinFont *font = new MinikinFontSkia(std::move(skFace));
family->addFont(font);
typefaces.push_back(family);
#endif
@@ -93,13 +93,13 @@ void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float
pos[i].fX = x + layout->getX(i);
pos[i].fY = y + layout->getY(i);
if (i > 0 && skFace != lastFace) {
paint->setTypeface(lastFace);
paint->setTypeface(sk_ref_sp(lastFace));
canvas->drawPosText(glyphs + start, (i - start) << 1, pos + start, *paint);
start = i;
}
lastFace = skFace;
}
paint->setTypeface(skFace);
paint->setTypeface(sk_ref_sp(skFace));
canvas->drawPosText(glyphs + start, (nGlyphs - start) << 1, pos + start, *paint);
delete[] glyphs;
delete[] pos;

View File

@@ -26,30 +26,23 @@ namespace minikin {
// static
MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) {
SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str());
MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface);
SkSafeUnref(typeface);
sk_sp<SkTypeface> typeface = SkTypeface::MakeFromFile(font_path.c_str());
MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface));
return font;
}
// static
MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path,
int index) {
SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str(), index);
MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface);
SkSafeUnref(typeface);
sk_sp<SkTypeface> typeface = SkTypeface::MakeFromFile(font_path.c_str(), index);
MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface));
return font;
}
MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) :
MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_sp<SkTypeface> typeface) :
MinikinFont(typeface->uniqueID()),
mTypeface(typeface),
mTypeface(std::move(typeface)),
mFontPath(font_path) {
SkSafeRef(mTypeface);
}
MinikinFontForTest::~MinikinFontForTest() {
SkSafeUnref(mTypeface);
}
float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */,

View File

@@ -18,6 +18,7 @@
#define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H
#include <minikin/MinikinFont.h>
#include <SkRefCnt.h>
class SkTypeface;
@@ -25,8 +26,7 @@ namespace minikin {
class MinikinFontForTest : public MinikinFont {
public:
MinikinFontForTest(const std::string& font_path, SkTypeface* typeface);
~MinikinFontForTest();
MinikinFontForTest(const std::string& font_path, sk_sp<SkTypeface> typeface);
// Helper function for creating MinikinFontForTest instance from font file.
// Calller need to unref returned object.
@@ -45,7 +45,7 @@ private:
MinikinFontForTest(const MinikinFontForTest&) = delete;
MinikinFontForTest& operator=(MinikinFontForTest&) = delete;
SkTypeface *mTypeface;
sk_sp<SkTypeface> mTypeface;
const std::string mFontPath;
};