diff options
author | bungeman <bungeman@google.com> | 2016-05-12 10:09:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-12 10:09:31 -0700 |
commit | 13b9c95295f4c5732e34574789e721a6bc08f7b4 (patch) | |
tree | c3ef0aa2af9890c03cb79968f32166af39fba9ba /tools | |
parent | 40d21de8b6620d724f34bdc85af1dcb593d33fe0 (diff) |
Move SkTypeface to sk_sp.
Committed: https://skia.googlesource.com/skia/+/6296da736fbf40aae881650c239420f64e576c3f
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1933393002
Review-Url: https://codereview.chromium.org/1933393002
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Resources.cpp | 4 | ||||
-rw-r--r-- | tools/Resources.h | 2 | ||||
-rw-r--r-- | tools/debugger/SkDrawCommand.cpp | 3 | ||||
-rw-r--r-- | tools/sk_tool_utils.cpp | 18 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 6 | ||||
-rw-r--r-- | tools/sk_tool_utils_font.cpp | 7 | ||||
-rw-r--r-- | tools/using_skia_and_harfbuzz.cpp | 4 |
7 files changed, 19 insertions, 25 deletions
diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 0117404ac2..6d3054ab33 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -49,10 +49,10 @@ SkStreamAsset* GetResourceAsStream(const char* resource) { } } -SkTypeface* GetResourceAsTypeface(const char* resource) { +sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) { SkAutoTDelete<SkStreamAsset> stream(GetResourceAsStream(resource)); if (!stream) { return nullptr; } - return SkTypeface::CreateFromStream(stream.release()); + return SkTypeface::MakeFromStream(stream.release()); } diff --git a/tools/Resources.h b/tools/Resources.h index 678e4c8627..8115fbbb85 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); -SkTypeface* GetResourceAsTypeface(const char* resource); +sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource); #endif // Resources_DEFINED diff --git a/tools/debugger/SkDrawCommand.cpp b/tools/debugger/SkDrawCommand.cpp index 4a88fa1b33..b95a9b89d1 100644 --- a/tools/debugger/SkDrawCommand.cpp +++ b/tools/debugger/SkDrawCommand.cpp @@ -1214,8 +1214,7 @@ 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); - SkTypeface* typeface = SkTypeface::Deserialize(&buffer); - target->setTypeface(typeface); + target->setTypeface(SkTypeface::MakeDeserialize(&buffer)); } } diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index f46ebb6e60..7343ce4744 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,17 +75,14 @@ const char* platform_os_emoji() { return ""; } -void emoji_typeface(SkAutoTUnref<SkTypeface>* tf) { +sk_sp<SkTypeface> emoji_typeface() { if (!strcmp(sk_tool_utils::platform_os_emoji(), "CBDT")) { - tf->reset(GetResourceAsTypeface("/fonts/Funkster.ttf")); - return; + return MakeResourceAsTypeface("/fonts/Funkster.ttf"); } if (!strcmp(sk_tool_utils::platform_os_emoji(), "SBIX")) { - tf->reset(SkTypeface::CreateFromName("Apple Color Emoji", SkTypeface::kNormal)); - return; + return SkTypeface::MakeFromName("Apple Color Emoji", SkTypeface::kNormal); } - tf->reset(nullptr); - return; + return nullptr; } const char* emoji_sample_text() { @@ -159,13 +156,12 @@ SkColor color_to_565(SkColor color) { return SkPixel16ToColor(color16); } -SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style) { +sk_sp<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) { - SkTypeface* face = create_font(name, style); - SkSafeUnref(paint->setTypeface(face)); + paint->setTypeface(create_font(name, style)); } 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 1d80731fd4..a16c2a2f6e 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. */ - void emoji_typeface(SkAutoTUnref<SkTypeface>* ); + sk_sp<SkTypeface> emoji_typeface(); /** * 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. */ - SkTypeface* create_portable_typeface(const char* name, SkTypeface::Style style); + sk_sp<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 - SkTypeface* create_font(const char* name, SkTypeface::Style); + sk_sp<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 adbfa1692b..f73576dbf6 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); -SkTypeface* create_font(const char* name, SkTypeface::Style style) { +sk_sp<SkTypeface> create_font(const char* name, SkTypeface::Style style) { SkTestFontData* fontData = nullptr; const SubFont* sub; if (name) { @@ -47,7 +47,8 @@ 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 fm->legacyCreateTypeface(name, SkFontStyle::FromOldStyle(style)); + return sk_sp<SkTypeface>(fm->legacyCreateTypeface(name, + SkFontStyle::FromOldStyle(style))); } } else { sub = &gSubFonts[gDefaultFontIndex]; @@ -65,7 +66,7 @@ SkTypeface* create_font(const char* name, SkTypeface::Style style) { fontData->fFontCache = SkSafeRef(font); } } - return new SkTestTypeface(font, SkFontStyle::FromOldStyle(style)); + return sk_make_sp<SkTestTypeface>(font, SkFontStyle::FromOldStyle(style)); } } diff --git a/tools/using_skia_and_harfbuzz.cpp b/tools/using_skia_and_harfbuzz.cpp index 413939d15b..86c9accd33 100644 --- a/tools/using_skia_and_harfbuzz.cpp +++ b/tools/using_skia_and_harfbuzz.cpp @@ -142,9 +142,7 @@ struct Face { auto data = SkData::MakeFromFileName(path); assert(data); if (!data) { return; } - fSkiaTypeface.reset( - SkTypeface::CreateFromStream( - new SkMemoryStream(data), index)); + fSkiaTypeface = SkTypeface::MakeFromStream(new SkMemoryStream(data), index); assert(fSkiaTypeface); if (!fSkiaTypeface) { return; } auto destroy = [](void *d) { static_cast<SkData*>(d)->unref(); }; |