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> | |
8 | |
7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
10 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
11 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #include "skia/ext/fontmgr_default_win.h" | |
15 #include "third_party/skia/include/ports/SkTypeface_win.h" | |
16 #include "ui/gfx/platform_font_win.h" | |
12 #include "ui/gfx/switches.h" | 17 #include "ui/gfx/switches.h" |
13 #include "ui/gfx/win/dpi.h" | 18 #include "ui/gfx/win/dpi.h" |
14 | 19 |
15 namespace gfx { | 20 namespace gfx { |
16 namespace win { | 21 namespace win { |
17 | 22 |
18 bool ShouldUseDirectWrite() { | 23 bool ShouldUseDirectWrite() { |
19 // If the flag is currently on, and we're on Win7 or above, we enable | 24 // If the flag is currently on, and we're on Win7 or above, we enable |
20 // DirectWrite. Skia does not require the additions to DirectWrite in QFE | 25 // DirectWrite. Skia does not require the additions to DirectWrite in QFE |
21 // 2670838, but a simple 'better than XP' check is not enough. | 26 // 2670838, but a simple 'better than XP' check is not enough. |
(...skipping 30 matching lines...) Expand all Loading... | |
52 const DWORD kMaxAllowedFontsBeforeFallbackToGDI = 1750; | 57 const DWORD kMaxAllowedFontsBeforeFallbackToGDI = 1750; |
53 if (reg_iterator.ValueCount() >= kMaxAllowedFontsBeforeFallbackToGDI) | 58 if (reg_iterator.ValueCount() >= kMaxAllowedFontsBeforeFallbackToGDI) |
54 return false; | 59 return false; |
55 | 60 |
56 // Otherwise, check the field trial. | 61 // Otherwise, check the field trial. |
57 const std::string group_name = | 62 const std::string group_name = |
58 base::FieldTrialList::FindFullName("DirectWrite"); | 63 base::FieldTrialList::FindFullName("DirectWrite"); |
59 return group_name != "Disabled"; | 64 return group_name != "Disabled"; |
60 } | 65 } |
61 | 66 |
67 void MaybeInitializeDirectWrite() { | |
68 if (!ShouldUseDirectWrite() || | |
69 CommandLine::ForCurrentProcess()->HasSwitch( | |
70 switches::kDisableDirectWriteForUI) && | |
msw
2014/11/24 21:51:00
Should this be || to preserve the old logic?
ckocagil
2014/11/25 01:39:47
Good catch! Done.
| |
71 CommandLine::ForCurrentProcess()->HasSwitch( | |
72 switches::kDisableHarfBuzzRenderText)) { | |
73 return; | |
74 } | |
75 | |
76 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; | |
77 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); | |
78 if (!dwrite_dll) | |
79 return; | |
80 | |
81 DWriteCreateFactoryProc dwrite_create_factory_proc = | |
82 reinterpret_cast<DWriteCreateFactoryProc>( | |
83 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); | |
84 // Not finding the DWriteCreateFactory function indicates a corrupt dll. | |
85 CHECK(dwrite_create_factory_proc); | |
86 | |
87 IDWriteFactory* factory = NULL; | |
88 | |
89 CHECK(SUCCEEDED( | |
90 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, | |
91 __uuidof(IDWriteFactory), | |
92 reinterpret_cast<IUnknown**>(&factory)))); | |
93 SetDefaultSkiaFactory(SkFontMgr_New_DirectWrite(factory)); | |
94 PlatformFontWin::SetDirectWriteFactory(factory); | |
95 } | |
96 | |
62 } // namespace win | 97 } // namespace win |
63 } // namespace gfx | 98 } // namespace gfx |
OLD | NEW |