Chromium Code Reviews| 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 namespace { | |
| 25 | |
| 26 static bool dwrite_enabled = false; | |
| 27 | |
| 28 } | |
| 29 | |
| 24 bool ShouldUseDirectWrite() { | 30 bool ShouldUseDirectWrite() { |
| 25 // If the flag is currently on, and we're on Win7 or above, we enable | 31 // If the flag is currently on, and we're on Win7 or above, we enable |
| 26 // DirectWrite. Skia does not require the additions to DirectWrite in QFE | 32 // DirectWrite. Skia does not require the additions to DirectWrite in QFE |
| 27 // 2670838, but a simple 'better than XP' check is not enough. | 33 // 2670838, but a simple 'better than XP' check is not enough. |
| 28 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 34 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 29 return false; | 35 return false; |
| 30 | 36 |
| 31 base::win::OSInfo::VersionNumber os_version = | 37 base::win::OSInfo::VersionNumber os_version = |
| 32 base::win::OSInfo::GetInstance()->version_number(); | 38 base::win::OSInfo::GetInstance()->version_number(); |
| 33 if ((os_version.major == 6) && (os_version.minor == 1)) { | 39 if ((os_version.major == 6) && (os_version.minor == 1)) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 dwrite_create_factory_proc( | 102 dwrite_create_factory_proc( |
| 97 DWRITE_FACTORY_TYPE_SHARED, | 103 DWRITE_FACTORY_TYPE_SHARED, |
| 98 __uuidof(IDWriteFactory), | 104 __uuidof(IDWriteFactory), |
| 99 reinterpret_cast<IUnknown**>(factory.Receive())))); | 105 reinterpret_cast<IUnknown**>(factory.Receive())))); |
| 100 // The skia call to create a new DirectWrite font manager instance can fail | 106 // The skia call to create a new DirectWrite font manager instance can fail |
| 101 // if we are unable to get the system font collection from the DirectWrite | 107 // if we are unable to get the system font collection from the DirectWrite |
| 102 // factory. The GetSystemFontCollection method in the IDWriteFactory | 108 // factory. The GetSystemFontCollection method in the IDWriteFactory |
| 103 // interface fails with E_INVALIDARG on certain Windows 7 gold versions | 109 // interface fails with E_INVALIDARG on certain Windows 7 gold versions |
| 104 // (6.1.7600.*). We should just use GDI in these cases. | 110 // (6.1.7600.*). We should just use GDI in these cases. |
| 105 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); | 111 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); |
| 106 if (direct_write_font_mgr) { | 112 if (!direct_write_font_mgr) |
| 107 SetDefaultSkiaFactory(direct_write_font_mgr); | 113 return; |
| 108 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); | 114 dwrite_enabled = true; |
|
msw
2014/12/10 23:55:50
Why can't callers check ShouldUseDirectWrite?
ckocagil
2014/12/11 01:07:11
Because some processes can choose not to initializ
msw
2014/12/11 23:30:12
Okay, fair enough.
| |
| 109 } | 115 SetDefaultSkiaFactory(direct_write_font_mgr); |
| 116 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); | |
| 117 } | |
| 118 | |
| 119 bool IsDirectWriteEnabled() { | |
| 120 return dwrite_enabled; | |
| 110 } | 121 } |
| 111 | 122 |
| 112 } // namespace win | 123 } // namespace win |
| 113 } // namespace gfx | 124 } // namespace gfx |
| OLD | NEW |