OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/win/direct_write.h" | 5 #include "ui/gfx/win/direct_write.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
13 #include "base/win/scoped_comptr.h" | 13 #include "base/win/scoped_comptr.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "skia/ext/fontmgr_default_win.h" | 15 #include "skia/ext/fontmgr_default_win.h" |
16 #include "third_party/skia/include/ports/SkTypeface_win.h" | 16 #include "third_party/skia/include/ports/SkTypeface_win.h" |
17 #include "ui/gfx/platform_font_win.h" | 17 #include "ui/gfx/platform_font_win.h" |
18 #include "ui/gfx/switches.h" | 18 #include "ui/gfx/switches.h" |
19 #include "ui/gfx/win/dpi.h" | 19 #include "ui/gfx/win/dpi.h" |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 namespace win { | 22 namespace win { |
23 | 23 |
| 24 base::win::ScopedComPtr<IDWriteFactory> factory_; |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 static bool dwrite_enabled = false; | 28 static bool dwrite_enabled = false; |
27 | 29 |
28 } | 30 } |
29 | 31 |
30 bool ShouldUseDirectWrite() { | 32 bool ShouldUseDirectWrite() { |
31 // If the flag is currently on, and we're on Win7 or above, we enable | 33 // If the flag is currently on, and we're on Win7 or above, we enable |
32 // DirectWrite. Skia does not require the additions to DirectWrite in QFE | 34 // DirectWrite. Skia does not require the additions to DirectWrite in QFE |
33 // 2670838, but a simple 'better than XP' check is not enough. | 35 // 2670838, but a simple 'better than XP' check is not enough. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (!dwrite_dll) | 76 if (!dwrite_dll) |
75 return; | 77 return; |
76 | 78 |
77 DWriteCreateFactoryProc dwrite_create_factory_proc = | 79 DWriteCreateFactoryProc dwrite_create_factory_proc = |
78 reinterpret_cast<DWriteCreateFactoryProc>( | 80 reinterpret_cast<DWriteCreateFactoryProc>( |
79 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); | 81 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); |
80 // Not finding the DWriteCreateFactory function indicates a corrupt dll. | 82 // Not finding the DWriteCreateFactory function indicates a corrupt dll. |
81 if (!dwrite_create_factory_proc) | 83 if (!dwrite_create_factory_proc) |
82 return; | 84 return; |
83 | 85 |
84 base::win::ScopedComPtr<IDWriteFactory> factory; | |
85 | |
86 // Failure to create the DirectWrite factory indicates a corrupt dll. | 86 // Failure to create the DirectWrite factory indicates a corrupt dll. |
87 if (FAILED(dwrite_create_factory_proc( | 87 if (FAILED(dwrite_create_factory_proc( |
88 DWRITE_FACTORY_TYPE_SHARED, | 88 DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), |
89 __uuidof(IDWriteFactory), | 89 reinterpret_cast<IUnknown**>(factory_.Receive())))) |
90 reinterpret_cast<IUnknown**>(factory.Receive())))) | |
91 return; | 90 return; |
92 | 91 |
93 // The skia call to create a new DirectWrite font manager instance can fail | 92 // The skia call to create a new DirectWrite font manager instance can fail |
94 // if we are unable to get the system font collection from the DirectWrite | 93 // if we are unable to get the system font collection from the DirectWrite |
95 // factory. The GetSystemFontCollection method in the IDWriteFactory | 94 // factory. The GetSystemFontCollection method in the IDWriteFactory |
96 // interface fails with E_INVALIDARG on certain Windows 7 gold versions | 95 // interface fails with E_INVALIDARG on certain Windows 7 gold versions |
97 // (6.1.7600.*). We should just use GDI in these cases. | 96 // (6.1.7600.*). We should just use GDI in these cases. |
98 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); | 97 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory_.get()); |
99 if (!direct_write_font_mgr) | 98 if (!direct_write_font_mgr) |
100 return; | 99 return; |
101 dwrite_enabled = true; | 100 dwrite_enabled = true; |
102 SetDefaultSkiaFactory(direct_write_font_mgr); | 101 SetDefaultSkiaFactory(direct_write_font_mgr); |
103 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); | 102 gfx::PlatformFontWin::SetDirectWriteFactory(factory_.get()); |
104 } | 103 } |
105 | 104 |
106 bool IsDirectWriteEnabled() { | 105 bool IsDirectWriteEnabled() { |
107 return dwrite_enabled; | 106 return dwrite_enabled; |
108 } | 107 } |
109 | 108 |
| 109 void GetDWriteFactory(IDWriteFactory** factory) { |
| 110 MaybeInitializeDirectWrite(); |
| 111 base::win::ScopedComPtr<IDWriteFactory> factory_ref = factory_; |
| 112 *factory = factory_ref.Detach(); |
| 113 } |
| 114 |
110 } // namespace win | 115 } // namespace win |
111 } // namespace gfx | 116 } // namespace gfx |
OLD | NEW |