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 /tests | |
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
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FontHostStreamTest.cpp | 19 | ||||
-rw-r--r-- | tests/FontHostTest.cpp | 27 | ||||
-rw-r--r-- | tests/FontMgrTest.cpp | 12 | ||||
-rw-r--r-- | tests/FontObjTest.cpp | 7 | ||||
-rw-r--r-- | tests/PDFPrimitivesTest.cpp | 2 | ||||
-rw-r--r-- | tests/PaintTest.cpp | 4 | ||||
-rw-r--r-- | tests/PictureTest.cpp | 2 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 12 | ||||
-rw-r--r-- | tests/TextBlobCacheTest.cpp | 5 | ||||
-rw-r--r-- | tests/TextBlobTest.cpp | 4 | ||||
-rw-r--r-- | tests/TypefaceTest.cpp | 8 |
11 files changed, 58 insertions, 44 deletions
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 } |