OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/gfx/win/direct_write.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/command_line.h" | |
9 #include "base/metrics/field_trial.h" | |
10 #include "base/win/registry.h" | |
11 #include "base/win/windows_version.h" | |
12 #include "ui/gfx/switches.h" | |
13 #include "ui/gfx/win/dpi.h" | |
14 | |
15 namespace gfx { | |
16 namespace win { | |
17 | |
18 bool ShouldUseDirectWrite() { | |
19 // 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 | |
21 // 2670838, but a simple 'better than XP' check is not enough. | |
22 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
23 return false; | |
24 | |
25 base::win::OSInfo::VersionNumber os_version = | |
26 base::win::OSInfo::GetInstance()->version_number(); | |
27 if ((os_version.major == 6) && (os_version.minor == 1)) { | |
28 // We can't use DirectWrite for pre-release versions of Windows 7. | |
29 if (os_version.build < 7600) | |
30 return false; | |
31 } | |
32 // If forced off, don't use it. | |
33 const base::CommandLine& command_line = | |
34 *base::CommandLine::ForCurrentProcess(); | |
35 if (command_line.HasSwitch(switches::kDisableDirectWrite)) | |
36 return false; | |
37 | |
38 // Can't use GDI on HiDPI. | |
39 if (gfx::GetDPIScale() > 1.0f) | |
40 return true; | |
41 | |
42 // We have logic in renderer_font_platform_win.cc for falling back to safe | |
43 // font list if machine has more than 1750 fonts installed. Users have | |
44 // complained about this as safe font list is usually not sufficient. | |
45 // We now disable direct write (gdi) if we encounter more number | |
46 // of fonts than a threshold (currently 1750). | |
47 // Refer: crbug.com/421305 | |
48 const wchar_t kWindowsFontsRegistryKey[] = | |
49 L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; | |
50 base::win::RegistryValueIterator reg_iterator(HKEY_LOCAL_MACHINE, | |
51 kWindowsFontsRegistryKey); | |
52 const DWORD kMaxAllowedFontsBeforeFallbackToGDI = 1750; | |
53 if (reg_iterator.ValueCount() >= kMaxAllowedFontsBeforeFallbackToGDI) | |
54 return false; | |
55 | |
56 // Otherwise, check the field trial. | |
57 const std::string group_name = | |
58 base::FieldTrialList::FindFullName("DirectWrite"); | |
59 return group_name != "Disabled"; | |
60 } | |
61 | |
62 } // namespace win | |
63 } // namespace gfx | |
OLD | NEW |