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() {
return android_fonts_dir;
}
SkFontMgr* CreateAndroidFontMgr(std::string android_fonts_dir) {
sk_sp<SkFontMgr> CreateAndroidFontMgr(std::string android_fonts_dir) {
SkFontMgr_Android_CustomFonts custom;
custom.fSystemFontUse =
SkFontMgr_Android_CustomFonts::SystemFontUse::kOnlyCustom;
......
......@@ -70,14 +70,11 @@ void InitializeDWriteFontProxy() {
&font_fallback, g_font_collection.Get(), sender);
}
sk_sp<SkFontMgr> skia_font_manager(SkFontMgr_New_DirectWrite(
factory.Get(), g_font_collection.Get(), font_fallback.Get()));
blink::WebFontRendering::setSkiaFontManager(skia_font_manager.get());
// Add an extra ref for SetDefaultSkiaFactory, which keeps a ref but doesn't
// addref.
skia_font_manager->ref();
SetDefaultSkiaFactory(skia_font_manager.get());
sk_sp<SkFontMgr> skia_font_manager = SkFontMgr_New_DirectWrite(
factory.Get(), g_font_collection.Get(), font_fallback.Get());
blink::WebFontRendering::setSkiaFontManager(skia_font_manager);
SetDefaultSkiaFactory(std::move(skia_font_manager));
// When IDWriteFontFallback is not available (prior to Win8.1) Skia will
// still attempt to use DirectWrite to determine fallback fonts (in
......
......@@ -416,7 +416,7 @@ void PatchServiceManagerCalls() {
GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) {
if (!g_warmup_fontmgr)
g_warmup_fontmgr = SkFontMgr_New_DirectWrite();
g_warmup_fontmgr = SkFontMgr_New_DirectWrite().release();
DCHECK(g_warmup_fontmgr);
return new GdiFontPatchDataImpl(path);
}
......@@ -429,8 +429,9 @@ void ResetEmulatedGdiHandlesForTesting() {
g_fake_gdi_object_factory.Get().ResetObjectHandles();
}
void SetPreSandboxWarmupFontMgrForTesting(SkFontMgr* fontmgr) {
g_warmup_fontmgr = fontmgr;
void SetPreSandboxWarmupFontMgrForTesting(sk_sp<SkFontMgr> fontmgr) {
SkSafeUnref(g_warmup_fontmgr);
g_warmup_fontmgr = fontmgr.release();
}
} // namespace content
......@@ -12,6 +12,7 @@
#include "content/common/content_export.h"
class SkFontMgr;
template <typename T> class sk_sp;
namespace content {
......@@ -39,7 +40,8 @@ CONTENT_EXPORT void ResetEmulatedGdiHandlesForTesting();
// Sets the pre-sandbox warmup font manager directly. This should only be used
// 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
// fonts installed on the system etc. This works well outside the sandbox and
......
......@@ -16,6 +16,7 @@
#include "base/sys_byteorder.h"
#include "base/win/windows_version.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/SkTypeface.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
......@@ -130,7 +131,9 @@ const wchar_t* kTestFontFamilyInvalid = L"InvalidFont";
class TestSkFontMgr : public SkFontMgr {
public:
TestSkFontMgr() { content::SetPreSandboxWarmupFontMgrForTesting(this); }
TestSkFontMgr() {
content::SetPreSandboxWarmupFontMgrForTesting(sk_ref_sp(this));
}
~TestSkFontMgr() override {
content::SetPreSandboxWarmupFontMgrForTesting(nullptr);
}
......
......@@ -5,6 +5,7 @@
#include "content/shell/app/blink_test_platform_support.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"
namespace {
......
......@@ -61,6 +61,7 @@
#elif defined(OS_WIN)
#include "content/child/font_warmup_win.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/SkTypeface_win.h"
#include "ui/gfx/win/direct_write.h"
......@@ -438,7 +439,7 @@ void EnableRendererLayoutTestMode() {
base::MakeUnique<LayoutTestDependenciesImpl>());
#if defined(OS_WIN)
RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite());
RegisterSideloadedTypefaces(SkFontMgr_New_DirectWrite().get());
#endif
}
......
......@@ -41,10 +41,7 @@ config("skia_config") {
"//third_party/skia/include/utils",
]
defines = [
"SK_IGNORE_DW_GRAY_FIX",
"SK_LEGACY_FONTMGR_FACTORY",
]
defines = [ "SK_IGNORE_DW_GRAY_FIX" ]
defines += skia_for_chromium_defines
defines += []
......
......@@ -8,14 +8,15 @@
#include "third_party/skia/include/ports/SkFontMgr_android.h"
namespace {
// An owning leaky bare pointer.
SkFontMgr* g_default_fontmgr;
} // namespace
SK_API void SetDefaultSkiaFactory(SkFontMgr* fontmgr) {
g_default_fontmgr = fontmgr;
SK_API void SetDefaultSkiaFactory(sk_sp<SkFontMgr> fontmgr) {
g_default_fontmgr = fontmgr.release();
}
SK_API SkFontMgr* SkFontMgr::Factory() {
return g_default_fontmgr ? SkRef(g_default_fontmgr)
SK_API sk_sp<SkFontMgr> SkFontMgr::Factory() {
return g_default_fontmgr ? sk_ref_sp(g_default_fontmgr)
: SkFontMgr_New_Android(nullptr);
}
......@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h"
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_
......@@ -13,13 +13,14 @@ namespace {
SkFontMgr* g_default_fontmgr;
} // namespace
void SetDefaultSkiaFactory(SkFontMgr* fontmgr) {
g_default_fontmgr = fontmgr;
void SetDefaultSkiaFactory(sk_sp<SkFontMgr> 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) {
return SkRef(g_default_fontmgr);
return sk_ref_sp(g_default_fontmgr);
}
sk_sp<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
return fci ? SkFontMgr_New_FCI(std::move(fci)) : nullptr;
......
......@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h"
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_
......@@ -9,19 +9,21 @@
namespace {
// This is a leaky bare owning pointer.
SkFontMgr* g_default_fontmgr;
} // namespace
void SetDefaultSkiaFactory(SkFontMgr* fontmgr) {
g_default_fontmgr = fontmgr;
void SetDefaultSkiaFactory(sk_sp<SkFontMgr> 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
// created with the pre-sandbox warmed up one. Otherwise, we fallback to a
// GDI SkFontMgr which is used in the browser.
if (g_default_fontmgr)
return SkRef(g_default_fontmgr);
return sk_ref_sp(g_default_fontmgr);
return SkFontMgr_New_GDI();
}
......@@ -8,7 +8,8 @@
#include "third_party/skia/include/core/SkTypes.h"
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_
......@@ -233,12 +233,9 @@ FontVerticalDataCache& fontVerticalDataCacheInstance() {
return fontVerticalDataCache;
}
void FontCache::setFontManager(const sk_sp<SkFontMgr>& fontManager) {
void FontCache::setFontManager(sk_sp<SkFontMgr> fontManager) {
DCHECK(!s_staticFontManager);
s_staticFontManager = fontManager.get();
// Explicitly AddRef since we're going to hold on to the object for the life
// of the program.
s_staticFontManager->ref();
s_staticFontManager = fontManager.release();
}
PassRefPtr<OpenTypeVerticalData> FontCache::getVerticalData(
......
......@@ -114,7 +114,7 @@ class PLATFORM_EXPORT FontCache {
void invalidate();
SkFontMgr* fontManager() { return m_fontManager.get(); }
static void setFontManager(const sk_sp<SkFontMgr>&);
static void setFontManager(sk_sp<SkFontMgr>);
#if !OS(MACOSX)
static const AtomicString& systemFontFamily();
......@@ -246,6 +246,7 @@ class PLATFORM_EXPORT FontCache {
sk_sp<SkFontMgr> m_fontManager;
// A leaky owning bare pointer.
static SkFontMgr* s_staticFontManager;
#if OS(WIN)
......
......@@ -34,14 +34,8 @@
namespace blink {
FontCache::FontCache() : m_purgePreventCount(0) {
if (s_staticFontManager) {
adopted(s_staticFontManager);
m_fontManager = sk_ref_sp(s_staticFontManager);
} else {
m_fontManager = nullptr;
}
}
FontCache::FontCache()
: m_purgePreventCount(0), m_fontManager(sk_ref_sp(s_staticFontManager)) {}
static AtomicString& mutableSystemFontFamily() {
DEFINE_STATIC_LOCAL(AtomicString, systemFontFamily, ());
......
......@@ -104,7 +104,7 @@ void FontCache::setStatusFontMetrics(const wchar_t* familyName,
FontCache::FontCache() : m_purgePreventCount(0) {
m_fontManager = sk_ref_sp(s_staticFontManager);
if (!m_fontManager)
m_fontManager.reset(SkFontMgr_New_DirectWrite());
m_fontManager = SkFontMgr_New_DirectWrite();
ASSERT(m_fontManager.get());
}
......
......@@ -41,9 +41,8 @@ using blink::FontPlatformData;
namespace blink {
// static
void WebFontRendering::setSkiaFontManager(SkFontMgr* fontMgr) {
WTF::adopted(fontMgr);
FontCache::setFontManager(sk_ref_sp(fontMgr));
void WebFontRendering::setSkiaFontManager(sk_sp<SkFontMgr> fontMgr) {
FontCache::setFontManager(std::move(fontMgr));
}
// static
......
......@@ -9,9 +9,8 @@
namespace blink {
// static
void WebFontRendering::setSkiaFontManager(SkFontMgr* fontMgr) {
WTF::adopted(fontMgr);
FontCache::setFontManager(sk_ref_sp(fontMgr));
void WebFontRendering::setSkiaFontManager(sk_sp<SkFontMgr> fontMgr) {
FontCache::setFontManager(std::move(fontMgr));
}
// static
......
......@@ -42,7 +42,7 @@ class WebFontRendering {
public:
// 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 setAutoHint(bool);
BLINK_EXPORT static void setUseBitmaps(bool);
......
......@@ -6,6 +6,7 @@
#define WebFontRendering_h
#include "public/platform/WebCommon.h"
#include "third_party/skia/include/core/SkRefCnt.h"
class SkFontMgr;
class SkTypeface;
......@@ -14,7 +15,7 @@ namespace blink {
class WebFontRendering {
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 addSideloadedFontForTesting(SkTypeface*);
BLINK_EXPORT static void setMenuFontMetrics(const wchar_t* familyName,
......
......@@ -10,6 +10,7 @@
#include "base/win/scoped_comptr.h"
#include "base/win/windows_version.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 "ui/gfx/platform_font_win.h"
#include "ui/gfx/switches.h"
......@@ -52,10 +53,11 @@ void MaybeInitializeDirectWrite() {
// factory. The GetSystemFontCollection method in the IDWriteFactory
// interface fails with E_INVALIDARG on certain Windows 7 gold versions
// (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)
return;
SetDefaultSkiaFactory(direct_write_font_mgr);
SetDefaultSkiaFactory(std::move(direct_write_font_mgr));
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