aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
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 /tests
parentc8699321b924c1f284df93cb29b86000c1d73c0a (diff)
Move SkTypeface to sk_sp.
Diffstat (limited to 'tests')
-rw-r--r--tests/FontHostStreamTest.cpp19
-rw-r--r--tests/FontHostTest.cpp27
-rw-r--r--tests/FontMgrTest.cpp12
-rw-r--r--tests/FontObjTest.cpp7
-rw-r--r--tests/PDFPrimitivesTest.cpp2
-rw-r--r--tests/PaintTest.cpp4
-rw-r--r--tests/PictureTest.cpp2
-rw-r--r--tests/SerializationTest.cpp12
-rw-r--r--tests/TextBlobCacheTest.cpp5
-rw-r--r--tests/TextBlobTest.cpp4
-rw-r--r--tests/TypefaceTest.cpp8
11 files changed, 44 insertions, 58 deletions
diff --git a/tests/FontHostStreamTest.cpp b/tests/FontHostStreamTest.cpp
index 0b436552a3..ec32d9f031 100644
--- a/tests/FontHostStreamTest.cpp
+++ b/tests/FontHostStreamTest.cpp
@@ -69,9 +69,7 @@ DEF_TEST(FontHostStream, reporter) {
paint.setColor(SK_ColorGRAY);
paint.setTextSize(SkIntToScalar(30));
- SkTypeface* fTypeface = SkTypeface::CreateFromName("Georgia",
- SkTypeface::kNormal);
- SkSafeUnref(paint.setTypeface(fTypeface));
+ paint.setTypeface(SkTypeface::MakeFromName("Georgia", SkTypeface::kNormal));
SkIRect origRect = SkIRect::MakeWH(64, 64);
SkBitmap origBitmap;
@@ -89,23 +87,18 @@ DEF_TEST(FontHostStream, reporter) {
drawBG(&origCanvas);
origCanvas.drawText("A", 1, point.fX, point.fY, paint);
- SkTypeface* origTypeface = paint.getTypeface();
- SkAutoTUnref<SkTypeface> aur;
- if (nullptr == origTypeface) {
- aur.reset(SkTypeface::RefDefault());
- origTypeface = aur.get();
- }
-
+ sk_sp<SkTypeface> typeface(SkToBool(paint.getTypeface()) ? sk_ref_sp(paint.getTypeface())
+ : SkTypeface::MakeDefault());
int ttcIndex;
- SkAutoTDelete<SkStreamAsset> fontData(origTypeface->openStream(&ttcIndex));
- SkTypeface* streamTypeface = SkTypeface::CreateFromStream(fontData.release());
+ SkAutoTDelete<SkStreamAsset> fontData(typeface->openStream(&ttcIndex));
+ sk_sp<SkTypeface> streamTypeface(SkTypeface::MakeFromStream(fontData.release()));
SkFontDescriptor desc;
bool isLocalStream = false;
streamTypeface->getFontDescriptor(&desc, &isLocalStream);
REPORTER_ASSERT(reporter, isLocalStream);
- SkSafeUnref(paint.setTypeface(streamTypeface));
+ paint.setTypeface(streamTypeface);
drawBG(&streamCanvas);
streamCanvas.drawPosText("A", 1, &point, paint);
diff --git a/tests/FontHostTest.cpp b/tests/FontHostTest.cpp
index d9a3df414a..ebcc4ab2ae 100644
--- a/tests/FontHostTest.cpp
+++ b/tests/FontHostTest.cpp
@@ -31,7 +31,7 @@ static const struct TagSize {
// Test that getUnitsPerEm() agrees with a direct lookup in the 'head' table
// (if that table is available).
-static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_unitsPerEm(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
int nativeUPEM = face->getUnitsPerEm();
int tableUPEM = -1;
@@ -50,7 +50,7 @@ static void test_unitsPerEm(skiatest::Reporter* reporter, SkTypeface* face) {
// Test that countGlyphs() agrees with a direct lookup in the 'maxp' table
// (if that table is available).
-static void test_countGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_countGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
int nativeGlyphs = face->countGlyphs();
int tableGlyphs = -1;
@@ -86,7 +86,7 @@ struct CharsToGlyphs_TestData {
};
// Test that SkPaint::textToGlyphs agrees with SkTypeface::charsToGlyphs.
-static void test_charsToGlyphs(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_charsToGlyphs(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
uint16_t paintGlyphIds[256];
uint16_t faceGlyphIds[256];
@@ -154,22 +154,22 @@ static void test_fontstream(skiatest::Reporter* reporter) {
}
static void test_symbolfont(skiatest::Reporter* reporter) {
- SkAutoTUnref<SkTypeface> typeface(GetResourceAsTypeface("/fonts/SpiderSymbol.ttf"));
- if (!typeface) {
- SkDebugf("Skipping FontHostTest::test_symbolfont\n");
- return;
- }
-
SkUnichar c = 0xf021;
uint16_t g;
SkPaint paint;
- paint.setTypeface(typeface);
+ paint.setTypeface(MakeResourceAsTypeface("/fonts/SpiderSymbol.ttf"));
paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
paint.textToGlyphs(&c, 4, &g);
+
+ if (!paint.getTypeface()) {
+ SkDebugf("Skipping FontHostTest::test_symbolfont\n");
+ return;
+ }
+
REPORTER_ASSERT(reporter, g == 3);
}
-static void test_tables(skiatest::Reporter* reporter, SkTypeface* face) {
+static void test_tables(skiatest::Reporter* reporter, const sk_sp<SkTypeface>& face) {
if (false) { // avoid bit rot, suppress warning
SkFontID fontID = face->uniqueID();
REPORTER_ASSERT(reporter, fontID);
@@ -223,7 +223,7 @@ static void test_tables(skiatest::Reporter* reporter) {
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); ++i) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(gNames[i], SkTypeface::kNormal));
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(gNames[i], SkTypeface::kNormal));
if (face) {
#ifdef DUMP_TABLES
SkDebugf("%s\n", gNames[i]);
@@ -277,8 +277,7 @@ static void test_advances(skiatest::Reporter* reporter) {
char txt[] = "long.text.with.lots.of.dots.";
for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal));
- paint.setTypeface(face);
+ paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal));
for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
paint.setHinting(settings[j].hinting);
diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp
index 92dc18b135..414631c58f 100644
--- a/tests/FontMgrTest.cpp
+++ b/tests/FontMgrTest.cpp
@@ -19,7 +19,7 @@
static void test_font(skiatest::Reporter* reporter) {
uint32_t flags = 0;
- SkAutoTUnref<SkFont> font(SkFont::Create(nullptr, 24, SkFont::kA8_MaskType, flags));
+ sk_sp<SkFont> font(SkFont::Make(nullptr, 24, SkFont::kA8_MaskType, flags));
REPORTER_ASSERT(reporter, font->getTypeface());
REPORTER_ASSERT(reporter, 24 == font->getSize());
@@ -39,7 +39,7 @@ static void test_font(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, glyphs[0] != glyphs[1]); // 'h' != 'e'
REPORTER_ASSERT(reporter, glyphs[2] == glyphs[3]); // 'l' == 'l'
- SkAutoTUnref<SkFont> newFont(font->cloneWithSize(36));
+ sk_sp<SkFont> newFont(font->makeWithSize(36));
REPORTER_ASSERT(reporter, newFont.get());
REPORTER_ASSERT(reporter, font->getTypeface() == newFont->getTypeface());
REPORTER_ASSERT(reporter, 36 == newFont->getSize()); // double check we haven't changed
@@ -47,7 +47,7 @@ static void test_font(skiatest::Reporter* reporter) {
SkPaint paint;
paint.setTextSize(18);
- font.reset(SkFont::Testing_CreateFromPaint(paint));
+ font = SkFont::Testing_CreateFromPaint(paint);
REPORTER_ASSERT(reporter, font.get());
REPORTER_ASSERT(reporter, font->getSize() == paint.getTextSize());
REPORTER_ASSERT(reporter, SkFont::kBW_MaskType == font->getMaskType());
@@ -64,14 +64,12 @@ static void test_alias_names(skiatest::Reporter* reporter) {
};
for (size_t i = 0; i < SK_ARRAY_COUNT(inNames); ++i) {
- SkAutoTUnref<SkTypeface> first(SkTypeface::CreateFromName(inNames[i],
- SkTypeface::kNormal));
+ sk_sp<SkTypeface> first(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal));
if (nullptr == first.get()) {
continue;
}
for (int j = 0; j < 10; ++j) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(inNames[i],
- SkTypeface::kNormal));
+ sk_sp<SkTypeface> face(SkTypeface::MakeFromName(inNames[i], SkTypeface::kNormal));
#if 0
SkString name;
face->getFamilyName(&name);
diff --git a/tests/FontObjTest.cpp b/tests/FontObjTest.cpp
index 9d18ce6b2e..66c8bd500f 100644
--- a/tests/FontObjTest.cpp
+++ b/tests/FontObjTest.cpp
@@ -23,7 +23,7 @@ static bool is_enable_bytecode_hints(const SkPaint& paint) {
}
static void test_cachedfont(skiatest::Reporter* reporter, const SkPaint& paint) {
- SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
+ sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
// Currently SkFont resolves null into the default, so only test if paint's is not null
if (paint.getTypeface()) {
@@ -78,8 +78,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) {
char txt[] = "long.text.with.lots.of.dots.";
for (size_t i = 0; i < SK_ARRAY_COUNT(faces); i++) {
- SkAutoTUnref<SkTypeface> face(SkTypeface::CreateFromName(faces[i], SkTypeface::kNormal));
- paint.setTypeface(face);
+ paint.setTypeface(SkTypeface::MakeFromName(faces[i], SkTypeface::kNormal));
for (size_t j = 0; j < SK_ARRAY_COUNT(settings); j++) {
paint.setHinting(settings[j].hinting);
@@ -103,7 +102,7 @@ static void test_cachedfont(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, width1 == width2);
- SkAutoTUnref<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
+ sk_sp<SkFont> font(SkFont::Testing_CreateFromPaint(paint));
SkScalar font_width1 = font->measureText(txt, strlen(txt), kUTF8_SkTextEncoding);
// measureText not yet implemented...
REPORTER_ASSERT(reporter, font_width1 == -1);
diff --git a/tests/PDFPrimitivesTest.cpp b/tests/PDFPrimitivesTest.cpp
index 58dd773fb8..07ddabc912 100644
--- a/tests/PDFPrimitivesTest.cpp
+++ b/tests/PDFPrimitivesTest.cpp
@@ -430,7 +430,7 @@ DEF_TEST(PDFFontCanEmbedTypeface, reporter) {
SkPDFCanon canon;
const char resource[] = "fonts/Roboto2-Regular_NoEmbed.ttf";
- sk_sp<SkTypeface> noEmbedTypeface(GetResourceAsTypeface(resource));
+ sk_sp<SkTypeface> noEmbedTypeface(MakeResourceAsTypeface(resource));
if (noEmbedTypeface) {
REPORTER_ASSERT(reporter,
!SkPDFFont::CanEmbedTypeface(noEmbedTypeface.get(), &canon));
diff --git a/tests/PaintTest.cpp b/tests/PaintTest.cpp
index bd00adb18d..f507467771 100644
--- a/tests/PaintTest.cpp
+++ b/tests/PaintTest.cpp
@@ -80,7 +80,7 @@ DEF_TEST(Paint_cmap, reporter) {
SkRandom rand;
SkPaint paint;
- paint.setTypeface(SkTypeface::RefDefault())->unref();
+ paint.setTypeface(SkTypeface::MakeDefault());
SkTypeface* face = paint.getTypeface();
for (int i = 0; i < 1000; ++i) {
@@ -333,7 +333,7 @@ DEF_TEST(Paint_getHash, r) {
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
// SkTypeface is the first field we hash, so test it specially.
- paint.setTypeface(SkTypeface::RefDefault())->unref();
+ paint.setTypeface(SkTypeface::MakeDefault());
REPORTER_ASSERT(r, paint.getHash() != defaultHash);
paint.setTypeface(nullptr);
REPORTER_ASSERT(r, paint.getHash() == defaultHash);
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 9e36d841df..832a80f438 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1177,7 +1177,7 @@ static void test_typeface(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(10, 10);
SkPaint paint;
- paint.setTypeface(SkTypeface::CreateFromName("Arial", SkTypeface::kItalic));
+ paint.setTypeface(SkTypeface::MakeFromName("Arial", SkTypeface::kItalic));
canvas->drawText("Q", 1, 0, 10, paint);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, picture->hasText());
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index 4750bbe25d..9e9b221cd2 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -322,14 +322,14 @@ static void compare_bitmaps(skiatest::Reporter* reporter,
}
REPORTER_ASSERT(reporter, 0 == pixelErrors);
}
-static void serialize_and_compare_typeface(SkTypeface* typeface, const char* text,
+static void serialize_and_compare_typeface(sk_sp<SkTypeface> typeface, const char* text,
skiatest::Reporter* reporter)
{
// Create a paint with the typeface.
SkPaint paint;
paint.setColor(SK_ColorGRAY);
paint.setTextSize(SkIntToScalar(30));
- paint.setTypeface(typeface);
+ paint.setTypeface(std::move(typeface));
// Paint some text.
SkPictureRecorder recorder;
@@ -357,11 +357,11 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
{
// Load typeface from file to test CreateFromFile with index.
SkString filename = GetResourcePath("/fonts/test.ttc");
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFile(filename.c_str(), 1));
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFile(filename.c_str(), 1));
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because test.ttc not found.");
} else {
- serialize_and_compare_typeface(typeface, "A!", reporter);
+ serialize_and_compare_typeface(std::move(typeface), "A!", reporter);
}
}
@@ -372,12 +372,12 @@ static void TestPictureTypefaceSerialization(skiatest::Reporter* reporter) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not found.");
} else {
SkFixed axis = SK_FixedSqrt2;
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::CreateFromFontData(
+ sk_sp<SkTypeface> typeface(SkTypeface::MakeFromFontData(
new SkFontData(distortable.release(), 0, &axis, 1)));
if (!typeface) {
INFOF(reporter, "Could not run fontstream test because Distortable.ttf not created.");
} else {
- serialize_and_compare_typeface(typeface, "abc", reporter);
+ serialize_and_compare_typeface(std::move(typeface), "abc", reporter);
}
}
}
diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp
index 23f45a4cad..cbc6b99f84 100644
--- a/tests/TextBlobCacheTest.cpp
+++ b/tests/TextBlobCacheTest.cpp
@@ -99,12 +99,11 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte
set->getStyle(j, &fs, nullptr);
// We use a typeface which randomy returns unexpected mask formats to fuzz
- SkAutoTUnref<SkTypeface> orig(set->createTypeface(j));
+ sk_sp<SkTypeface> orig(set->createTypeface(j));
if (normal) {
paint.setTypeface(orig);
} else {
- SkAutoTUnref<SkTypeface> typeface(new SkRandomTypeface(orig, paint, true));
- paint.setTypeface(typeface);
+ paint.setTypeface(sk_make_sp<SkRandomTypeface>(orig, paint, true));
}
SkTextBlobBuilder builder;
diff --git a/tests/TextBlobTest.cpp b/tests/TextBlobTest.cpp
index 923669e8c5..61070247b4 100644
--- a/tests/TextBlobTest.cpp
+++ b/tests/TextBlobTest.cpp
@@ -178,12 +178,10 @@ public:
SkPaint font;
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- SkAutoTUnref<SkTypeface> typeface(SkTypeface::RefDefault());
-
// Kitchen sink font.
font.setTextSize(42);
font.setTextScaleX(4.2f);
- font.setTypeface(typeface);
+ font.setTypeface(SkTypeface::MakeDefault());
font.setTextSkewX(0.42f);
font.setTextAlign(SkPaint::kCenter_Align);
font.setHinting(SkPaint::kFull_Hinting);
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index 950449d9c1..6a606d4e95 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -12,8 +12,8 @@
DEF_TEST(Typeface, reporter) {
- SkAutoTUnref<SkTypeface> t1(SkTypeface::CreateFromName(nullptr, SkTypeface::kNormal));
- SkAutoTUnref<SkTypeface> t2(SkTypeface::RefDefault(SkTypeface::kNormal));
+ sk_sp<SkTypeface> t1(SkTypeface::MakeFromName(nullptr, SkTypeface::kNormal));
+ sk_sp<SkTypeface> t2(SkTypeface::MakeDefault(SkTypeface::kNormal));
REPORTER_ASSERT(reporter, SkTypeface::Equal(t1.get(), t2.get()));
REPORTER_ASSERT(reporter, SkTypeface::Equal(0, t1.get()));
@@ -22,8 +22,8 @@ DEF_TEST(Typeface, reporter) {
REPORTER_ASSERT(reporter, SkTypeface::Equal(t2.get(), 0));
#ifdef SK_BUILD_FOR_ANDROID
- SkAutoTUnref<SkTypeface> t3(SkTypeface::CreateFromName("non-existent-font", SkTypeface::kNormal));
- REPORTER_ASSERT(reporter, nullptr == t3.get());
+ sk_sp<SkTypeface> t3(SkTypeface::MakeFromName("non-existent-font", SkTypeface::kNormal));
+ REPORTER_ASSERT(reporter, nullptr == t3);
#endif
}