Index: ui/gfx/win/direct_write.cc |
diff --git a/ui/gfx/win/direct_write.cc b/ui/gfx/win/direct_write.cc |
index 058f4be01deeaf50d02e11e2682cc4882c6f6b36..d3a1383138551e8905f1d4c434e2622cfd003481 100644 |
--- a/ui/gfx/win/direct_write.cc |
+++ b/ui/gfx/win/direct_write.cc |
@@ -4,11 +4,17 @@ |
#include "ui/gfx/win/direct_write.h" |
+#include <dwrite.h> |
+ |
#include "base/basictypes.h" |
#include "base/command_line.h" |
#include "base/metrics/field_trial.h" |
#include "base/win/registry.h" |
+#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/SkTypeface_win.h" |
+#include "ui/gfx/platform_font_win.h" |
#include "ui/gfx/switches.h" |
#include "ui/gfx/win/dpi.h" |
@@ -59,5 +65,44 @@ bool ShouldUseDirectWrite() { |
return group_name != "Disabled"; |
} |
+void MaybeInitializeDirectWrite() { |
sky
2014/12/01 15:57:22
What happens if this is invoked multiple times?
ckocagil
2014/12/01 19:31:53
We likely leak some objects (DWrite or SkFontMgr)
|
+ if (!ShouldUseDirectWrite() || |
+ CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kDisableDirectWriteForUI) || |
+ CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kDisableHarfBuzzRenderText)) { |
+ return; |
+ } |
+ |
+ typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; |
sky
2014/12/01 15:57:22
Use using for improved clarity.
ckocagil
2014/12/01 19:31:52
Done.
|
+ HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); |
+ if (!dwrite_dll) |
+ return; |
+ |
+ DWriteCreateFactoryProc dwrite_create_factory_proc = |
+ reinterpret_cast<DWriteCreateFactoryProc>( |
+ GetProcAddress(dwrite_dll, "DWriteCreateFactory")); |
+ // Not finding the DWriteCreateFactory function indicates a corrupt dll. |
+ CHECK(dwrite_create_factory_proc); |
+ |
+ base::win::ScopedComPtr<IDWriteFactory> factory; |
+ |
+ CHECK(SUCCEEDED( |
+ dwrite_create_factory_proc( |
+ DWRITE_FACTORY_TYPE_SHARED, |
+ __uuidof(IDWriteFactory), |
+ reinterpret_cast<IUnknown**>(factory.Receive())))); |
+ // The skia call to create a new DirectWrite font manager instance can fail |
+ // if we are unable to get the system font collection from the DirectWrite |
+ // 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()); |
+ if (direct_write_font_mgr) { |
+ SetDefaultSkiaFactory(direct_write_font_mgr); |
+ gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); |
+ } |
+} |
+ |
} // namespace win |
} // namespace gfx |