Commit ba3e738c authored by bungeman's avatar bungeman Committed by Commit bot

Remove use of legacy SkFontMgr factories.

This moves SkFontMgr creation and use to owning pointers.

BUG=skia:5077

Review-Url: https://codereview.chromium.org/2618443002
Cr-Commit-Position: refs/heads/master@{#442926}
parent c896d034
...@@ -63,7 +63,7 @@ std::string GetAndroidFontsDirectory() { ...@@ -63,7 +63,7 @@ std::string GetAndroidFontsDirectory() {
return android_fonts_dir; return android_fonts_dir;
} }
SkFontMgr* CreateAndroidFontMgr(std::string android_fonts_dir) { sk_sp<SkFontMgr> CreateAndroidFontMgr(std::string android_fonts_dir) {
SkFontMgr_Android_CustomFonts custom; SkFontMgr_Android_CustomFonts custom;
custom.fSystemFontUse = custom.fSystemFontUse =
SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom; SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom;
......
...@@ -70,14 +70,11 @@ void InitializeDWriteFontProxy() { ...@@ -70,14 +70,11 @@ void InitializeDWriteFontProxy() {
&font_fallback, g_font_collection.Get(), sender); &font_fallback, g_font_collection.Get(), sender);
} }
sk_sp<SkFontMgr> skia_font_manager(SkFontMgr_New_DirectWrite( sk_sp<SkFontMgr> skia_font_manager = SkFontMgr_New_DirectWrite(
factory.Get(), g_font_collection.Get(), font_fallback.Get())); factory.Get(), g_font_collection.Get(), font_fallback.Get());
blink::WebFontRendering::setSkiaFontManager(skia_font_manager.get()); blink::WebFontRendering::setSkiaFontManager(skia_font_manager);
// Add an extra ref for SetDefaultSkiaFactory, which keeps a ref but doesn't SetDefaultSkiaFactory(std::move(skia_font_manager));
// addref.
skia_font_manager->ref();
SetDefaultSkiaFactory(skia_font_manager.get());
// When IDWriteFontFallback is not available (prior to Win8.1) Skia will // When IDWriteFontFallback is not available (prior to Win8.1) Skia will
// still attempt to use DirectWrite to determine fallback fonts (in // still attempt to use DirectWrite to determine fallback fonts (in
......
...@@ -416,7 +416,7 @@ void PatchServiceManagerCalls() { ...@@ -416,7 +416,7 @@ void PatchServiceManagerCalls() {
GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) {
if (!g_warmup_fontmgr) if (!g_warmup_fontmgr)
g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); g_warmup_fontmgr = SkFontMgr_New_DirectWrite().release();
DCHECK(g_warmup_fontmgr); DCHECK(g_warmup_fontmgr);
return new GdiFontPatchDataImpl(path); return new GdiFontPatchDataImpl(path);
} }
...@@ -429,8 +429,9 @@ void ResetEmulatedGdiHandlesForTesting() { ...@@ -429,8 +429,9 @@ void ResetEmulatedGdiHandlesForTesting() {
g_fake_gdi_object_factory.Get().ResetObjectHandles(); g_fake_gdi_object_factory.Get().ResetObjectHandles();
} }
void SetPreSandboxWarmupFontMgrForTesting(SkFontMgr* fontmgr) { void SetPreSandboxWarmupFontMgrForTesting(sk_sp<SkFontMgr> fontmgr) {
g_warmup_fontmgr = fontmgr; SkSafeUnref(g_warmup_fontmgr);
g_warmup_fontmgr = fontmgr.release();
} }
} // namespace content } // namespace content
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
class SkFontMgr; class SkFontMgr;
template <typename T> class sk_sp;
namespace content { namespace content {
...@@ -39,7 +40,8 @@ CONTENT_EXPORT void ResetEmulatedGdiHandlesForTesting(); ...@@ -39,7 +40,8 @@ CONTENT_EXPORT void ResetEmulatedGdiHandlesForTesting();
// Sets the pre-sandbox warmup font manager directly. This should only be used // Sets the pre-sandbox warmup font manager directly. This should only be used
// for testing the implementation. // for testing the implementation.
CONTENT_EXPORT void SetPreSandboxWarmupFontMgrForTesting(SkFontMgr* fontmgr); CONTENT_EXPORT void SetPreSandboxWarmupFontMgrForTesting(
sk_sp<SkFontMgr> fontmgr);
// Directwrite connects to the font cache service to retrieve information about // Directwrite connects to the font cache service to retrieve information about
// fonts installed on the system etc. This works well outside the sandbox and // fonts installed on the system etc. This works well outside the sandbox and
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/sys_byteorder.h" #include "base/sys_byteorder.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/core/SkString.h" #include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/ports/SkFontMgr.h" #include "third_party/skia/include/ports/SkFontMgr.h"
...@@ -130,7 +131,9 @@ const wchar_t* kTestFontFamilyInvalid = L"InvalidFont"; ...@@ -130,7 +131,9 @@ const wchar_t* kTestFontFamilyInvalid = L"InvalidFont";
class TestSkFontMgr : public SkFontMgr { class TestSkFontMgr : public SkFontMgr {
public: public:
TestSkFontMgr() { content::SetPreSandboxWarmupFontMgrForTesting(this); } TestSkFontMgr() {
content::SetPreSandboxWarmupFontMgrForTesting(sk_ref_sp(this));
}
~TestSkFontMgr() override { ~TestSkFontMgr() override {
content::SetPreSandboxWarmupFontMgrForTesting(nullptr); content::SetPreSandboxWarmupFontMgrForTesting(nullptr);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "content/shell/app/blink_test_platform_support.h" #include "content/shell/app/blink_test_platform_support.h"
#include "skia/ext/fontmgr_default_android.h" #include "skia/ext/fontmgr_default_android.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkFontMgr_android.h" #include "third_party/skia/include/ports/SkFontMgr_android.h"
namespace { namespace {
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#elif defined(OS_WIN) #elif defined(OS_WIN)
#include "content/child/font_warmup_win.h" #include "content/child/font_warmup_win.h"
#include "third_party/WebKit/public/web/win/WebFontRendering.h" #include "third_party/WebKit/public/web/win/WebFontRendering.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/ports/SkFontMgr.h" #include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkTypeface_win.h" #include "third_party/skia/include/ports/SkTypeface_win.h"
#include "ui/gfx/win/direct_write.h" #include "ui/gfx/win/direct_write.h"
...@@ -438,7 +439,7 @@ void EnableRendererLayoutTestMode() { ...@@ -438,7 +439,7 @@ void EnableRendererLayoutTestMode() {
base::MakeUnique<LayoutTestDependenciesImpl>()); base::MakeUnique<LayoutTestDependenciesImpl>());
#if defined(OS_WIN) #if defined(OS_WIN)
RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite()); RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite().get());
#endif #endif
} }
......
...@@ -41,10 +41,7 @@ config("skia_config") { ...@@ -41,10 +41,7 @@ config("skia_config") {
"//third_party/skia/include/utils", "//third_party/skia/include/utils",
] ]
defines = [ defines = [ "SK_IGNORE_DW_GRAY_FIX" ]
"SK_IGNORE_DW_GRAY_FIX",
"SK_LEGACY_FONTMGR_FACTORY",
]
defines += skia_for_chromium_defines defines += skia_for_chromium_defines
defines += [] defines += []
......
...@@ -8,14 +8,15 @@ ...@@ -8,14 +8,15 @@
#include "third_party/skia/include/ports/SkFontMgr_android.h" #include "third_party/skia/include/ports/SkFontMgr_android.h"
namespace { namespace {
// An owning leaky bare pointer.
SkFontMgr* g_default_fontmgr; SkFontMgr* g_default_fontmgr;
} // namespace } // namespace
SK_API void SetDefaultSkiaFactory(SkFontMgr* fontmgr) { SK_API void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr) {
g_default_fontmgr = fontmgr; g_default_fontmgr = fontmgr.release();
} }
SK_API SkFontMgr* SkFontMgr::Factory() { SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
return g_default_fontmgr ? SkRef(g_default_fontmgr) return g_default_fontmgr ? sk_ref_sp(g_default_fontmgr)
: SkFontMgr_New_Android(nullptr); : SkFontMgr_New_Android(nullptr);
} }
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h" #include "third_party/skia/include/core/SkTypes.h"
class SkFontMgr; class SkFontMgr;
template <typename T> class sk_sp;
SK_API void SetDefaultSkiaFactory(SkFontMgr* fontmgr); SK_API void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr);
#endif // SKIA_EXT_FONTMGR_DEFAULT_ANDROID_H_ #endif // SKIA_EXT_FONTMGR_DEFAULT_ANDROID_H_
...@@ -13,13 +13,14 @@ namespace { ...@@ -13,13 +13,14 @@ namespace {
SkFontMgr* g_default_fontmgr; SkFontMgr* g_default_fontmgr;
} // namespace } // namespace
void SetDefaultSkiaFactory(SkFontMgr* fontmgr) { void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr) {
g_default_fontmgr = fontmgr; SkASSERT(g_default_fontmgr == nullptr);
g_default_fontmgr = fontmgr.release();
} }
SK_API SkFontMgr* SkFontMgr::Factory() { SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
if (g_default_fontmgr) { if (g_default_fontmgr) {
return SkRef(g_default_fontmgr); return sk_ref_sp(g_default_fontmgr);
} }
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr; return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr;
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h" #include "third_party/skia/include/core/SkTypes.h"
class SkFontMgr; class SkFontMgr;
template <typename T> class sk_sp;
void SK_API SetDefaultSkiaFactory(SkFontMgr* fontmgr); void SK_API SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr);
#endif // SKIA_EXT_FONTMGR_DEFAULT_LINUX_H_ #endif // SKIA_EXT_FONTMGR_DEFAULT_LINUX_H_
...@@ -9,19 +9,21 @@ ...@@ -9,19 +9,21 @@
namespace { namespace {
// This is a leaky bare owning pointer.
SkFontMgr* g_default_fontmgr; SkFontMgr* g_default_fontmgr;
} // namespace } // namespace
void SetDefaultSkiaFactory(SkFontMgr* fontmgr) { void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr) {
g_default_fontmgr = fontmgr; SkASSERT(g_default_fontmgr == nullptr);
g_default_fontmgr = fontmgr.release();
} }
SK_API SkFontMgr* SkFontMgr::Factory() { SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
// This will be set when DirectWrite is in use, and an SkFontMgr has been // This will be set when DirectWrite is in use, and an SkFontMgr has been
// created with the pre-sandbox warmed up one. Otherwise, we fallback to a // created with the pre-sandbox warmed up one. Otherwise, we fallback to a
// GDI SkFontMgr which is used in the browser. // GDI SkFontMgr which is used in the browser.
if (g_default_fontmgr) if (g_default_fontmgr)
return SkRef(g_default_fontmgr); return sk_ref_sp(g_default_fontmgr);
return SkFontMgr_New_GDI(); return SkFontMgr_New_GDI();
} }
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h" #include "third_party/skia/include/core/SkTypes.h"
class SkFontMgr; class SkFontMgr;
template <typename T> class sk_sp;
void SK_API SetDefaultSkiaFactory(SkFontMgr* fontmgr); void SK_API SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr);
#endif // SKIA_EXT_FONTMGR_DEFAULT_WIN_H_ #endif // SKIA_EXT_FONTMGR_DEFAULT_WIN_H_
...@@ -233,12 +233,9 @@ FontVerticalDataCache& fontVerticalDataCacheInstance() { ...@@ -233,12 +233,9 @@ FontVerticalDataCache& fontVerticalDataCacheInstance() {
return fontVerticalDataCache; return fontVerticalDataCache;
} }
void FontCache::setFontManager(const sk_sp<SkFontMgr>& fontManager) { void FontCache::setFontManager(sk_sp<SkFontMgr> fontManager) {
DCHECK(!s_staticFontManager); DCHECK(!s_staticFontManager);
s_staticFontManager = fontManager.get(); s_staticFontManager = fontManager.release();
// Explicitly AddRef since we're going to hold on to the object for the life
// of the program.
s_staticFontManager->ref();
} }
PassRefPtr<OpenTypeVerticalData> FontCache::getVerticalData( PassRefPtr<OpenTypeVerticalData> FontCache::getVerticalData(
......
...@@ -114,7 +114,7 @@ class PLATFORM_EXPORT FontCache { ...@@ -114,7 +114,7 @@ class PLATFORM_EXPORT FontCache {
void invalidate(); void invalidate();
SkFontMgr* fontManager() { return m_fontManager.get(); } SkFontMgr* fontManager() { return m_fontManager.get(); }
static void setFontManager(const sk_sp<SkFontMgr>&); static void setFontManager(sk_sp<SkFontMgr>);
#if !OS(MACOSX) #if !OS(MACOSX)
static const AtomicString& systemFontFamily(); static const AtomicString& systemFontFamily();
...@@ -246,6 +246,7 @@ class PLATFORM_EXPORT FontCache { ...@@ -246,6 +246,7 @@ class PLATFORM_EXPORT FontCache {
sk_sp<SkFontMgr> m_fontManager; sk_sp<SkFontMgr> m_fontManager;
// A leaky owning bare pointer.
static SkFontMgr* s_staticFontManager; static SkFontMgr* s_staticFontManager;
#if OS(WIN) #if OS(WIN)
......
...@@ -34,14 +34,8 @@ ...@@ -34,14 +34,8 @@
namespace blink { namespace blink {
FontCache::FontCache() : m_purgePreventCount(0) { FontCache::FontCache()
if (s_staticFontManager) { : m_purgePreventCount(0), m_fontManager(sk_ref_sp(s_staticFontManager)) {}
adopted(s_staticFontManager);
m_fontManager = sk_ref_sp(s_staticFontManager);
} else {
m_fontManager = nullptr;
}
}
static AtomicString& mutableSystemFontFamily() { static AtomicString& mutableSystemFontFamily() {
DEFINE_STATIC_LOCAL(AtomicString, systemFontFamily, ()); DEFINE_STATIC_LOCAL(AtomicString, systemFontFamily, ());
......
...@@ -104,7 +104,7 @@ void FontCache::setStatusFontMetrics(const wchar_t* familyName, ...@@ -104,7 +104,7 @@ void FontCache::setStatusFontMetrics(const wchar_t* familyName,
FontCache::FontCache() : m_purgePreventCount(0) { FontCache::FontCache() : m_purgePreventCount(0) {
m_fontManager = sk_ref_sp(s_staticFontManager); m_fontManager = sk_ref_sp(s_staticFontManager);
if (!m_fontManager) if (!m_fontManager)
m_fontManager.reset(SkFontMgr_New_DirectWrite()); m_fontManager = SkFontMgr_New_DirectWrite();
ASSERT(m_fontManager.get()); ASSERT(m_fontManager.get());
} }
......
...@@ -41,9 +41,8 @@ using blink::FontPlatformData; ...@@ -41,9 +41,8 @@ using blink::FontPlatformData;
namespace blink { namespace blink {
// static // static
void WebFontRendering::setSkiaFontManager(SkFontMgr* fontMgr) { void WebFontRendering::setSkiaFontManager(sk_sp<SkFontMgr> fontMgr) {
WTF::adopted(fontMgr); FontCache::setFontManager(std::move(fontMgr));
FontCache::setFontManager(sk_ref_sp(fontMgr));
} }
// static // static
......
...@@ -9,9 +9,8 @@ ...@@ -9,9 +9,8 @@
namespace blink { namespace blink {
// static // static
void WebFontRendering::setSkiaFontManager(SkFontMgr* fontMgr) { void WebFontRendering::setSkiaFontManager(sk_sp<SkFontMgr> fontMgr) {
WTF::adopted(fontMgr); FontCache::setFontManager(std::move(fontMgr));
FontCache::setFontManager(sk_ref_sp(fontMgr));
} }
// static // static
......
...@@ -42,7 +42,7 @@ class WebFontRendering { ...@@ -42,7 +42,7 @@ class WebFontRendering {
public: public:
// Set global font renderering preferences. // Set global font renderering preferences.
BLINK_EXPORT static void setSkiaFontManager(SkFontMgr*); BLINK_EXPORT static void setSkiaFontManager(sk_sp<SkFontMgr>);
BLINK_EXPORT static void setHinting(SkPaint::Hinting); BLINK_EXPORT static void setHinting(SkPaint::Hinting);
BLINK_EXPORT static void setAutoHint(bool); BLINK_EXPORT static void setAutoHint(bool);
BLINK_EXPORT static void setUseBitmaps(bool); BLINK_EXPORT static void setUseBitmaps(bool);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define WebFontRendering_h #define WebFontRendering_h
#include "public/platform/WebCommon.h" #include "public/platform/WebCommon.h"
#include "third_party/skia/include/core/SkRefCnt.h"
class SkFontMgr; class SkFontMgr;
class SkTypeface; class SkTypeface;
...@@ -14,7 +15,7 @@ namespace blink { ...@@ -14,7 +15,7 @@ namespace blink {
class WebFontRendering { class WebFontRendering {
public: public:
BLINK_EXPORT static void setSkiaFontManager(SkFontMgr*); BLINK_EXPORT static void setSkiaFontManager(sk_sp<SkFontMgr>);
BLINK_EXPORT static void setDeviceScaleFactor(float); BLINK_EXPORT static void setDeviceScaleFactor(float);
BLINK_EXPORT static void addSideloadedFontForTesting(SkTypeface*); BLINK_EXPORT static void addSideloadedFontForTesting(SkTypeface*);
BLINK_EXPORT static void setMenuFontMetrics(const wchar_t* familyName, BLINK_EXPORT static void setMenuFontMetrics(const wchar_t* familyName,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "skia/ext/fontmgr_default_win.h" #include "skia/ext/fontmgr_default_win.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkTypeface_win.h" #include "third_party/skia/include/ports/SkTypeface_win.h"
#include "ui/gfx/platform_font_win.h" #include "ui/gfx/platform_font_win.h"
#include "ui/gfx/switches.h" #include "ui/gfx/switches.h"
...@@ -52,10 +53,11 @@ void MaybeInitializeDirectWrite() { ...@@ -52,10 +53,11 @@ void MaybeInitializeDirectWrite() {
// factory. The GetSystemFontCollection method in the IDWriteFactory // factory. The GetSystemFontCollection method in the IDWriteFactory
// interface fails with E_INVALIDARG on certain Windows 7 gold versions // interface fails with E_INVALIDARG on certain Windows 7 gold versions
// (6.1.7600.*). We should just use GDI in these cases. // (6.1.7600.*). We should just use GDI in these cases.
SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); sk_sp<SkFontMgr> direct_write_font_mgr =
SkFontMgr_New_DirectWrite(factory.get());
if (!direct_write_font_mgr) if (!direct_write_font_mgr)
return; return;
SetDefaultSkiaFactory(direct_write_font_mgr); SetDefaultSkiaFactory(std::move(direct_write_font_mgr));
gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); gfx::PlatformFontWin::SetDirectWriteFactory(factory.get());
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment