Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ui/gfx/win/direct_write.cc

Issue 1839213002: Move check for --disable-directwrite-for-ui switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "base/win/scoped_comptr.h" 10 #include "base/win/scoped_comptr.h"
(...skipping 26 matching lines...) Expand all
37 if (os_version.build < 7600) 37 if (os_version.build < 7600)
38 return false; 38 return false;
39 } 39 }
40 // If forced off, don't use it. 40 // If forced off, don't use it.
41 const base::CommandLine& command_line = 41 const base::CommandLine& command_line =
42 *base::CommandLine::ForCurrentProcess(); 42 *base::CommandLine::ForCurrentProcess();
43 return !command_line.HasSwitch(switches::kDisableDirectWrite); 43 return !command_line.HasSwitch(switches::kDisableDirectWrite);
44 } 44 }
45 45
46 void CreateDWriteFactory(IDWriteFactory** factory) { 46 void CreateDWriteFactory(IDWriteFactory** factory) {
47 if (!ShouldUseDirectWrite() || 47 if (!ShouldUseDirectWrite())
48 base::CommandLine::ForCurrentProcess()->HasSwitch(
49 switches::kDisableDirectWriteForUI)) {
50 return; 48 return;
51 }
52 49
53 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; 50 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
54 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); 51 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
55 if (!dwrite_dll) 52 if (!dwrite_dll)
56 return; 53 return;
57 54
58 DWriteCreateFactoryProc dwrite_create_factory_proc = 55 DWriteCreateFactoryProc dwrite_create_factory_proc =
59 reinterpret_cast<DWriteCreateFactoryProc>( 56 reinterpret_cast<DWriteCreateFactoryProc>(
60 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); 57 GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
61 // Not finding the DWriteCreateFactory function indicates a corrupt dll. 58 // Not finding the DWriteCreateFactory function indicates a corrupt dll.
62 if (!dwrite_create_factory_proc) 59 if (!dwrite_create_factory_proc)
63 return; 60 return;
64 61
65 // Failure to create the DirectWrite factory indicates a corrupt dll. 62 // Failure to create the DirectWrite factory indicates a corrupt dll.
66 base::win::ScopedComPtr<IUnknown> factory_unknown; 63 base::win::ScopedComPtr<IUnknown> factory_unknown;
67 if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, 64 if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
68 __uuidof(IDWriteFactory), 65 __uuidof(IDWriteFactory),
69 factory_unknown.Receive()))) { 66 factory_unknown.Receive()))) {
70 return; 67 return;
71 } 68 }
72 factory_unknown.QueryInterface<IDWriteFactory>(factory); 69 factory_unknown.QueryInterface<IDWriteFactory>(factory);
73 } 70 }
74 71
75 void MaybeInitializeDirectWrite() { 72 void MaybeInitializeDirectWrite() {
76 static bool tried_dwrite_initialize = false; 73 static bool tried_dwrite_initialize = false;
77 if (tried_dwrite_initialize) 74 if (tried_dwrite_initialize)
78 return; 75 return;
79 tried_dwrite_initialize = true; 76 tried_dwrite_initialize = true;
80 77
78 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
79 switches::kDisableDirectWriteForUI)) {
80 return;
81 }
82
81 base::win::ScopedComPtr<IDWriteFactory> factory; 83 base::win::ScopedComPtr<IDWriteFactory> factory;
82 CreateDWriteFactory(factory.Receive()); 84 CreateDWriteFactory(factory.Receive());
83 85
84 if (factory == nullptr) 86 if (factory == nullptr)
85 return; 87 return;
86 88
87 // The skia call to create a new DirectWrite font manager instance can fail 89 // The skia call to create a new DirectWrite font manager instance can fail
88 // if we are unable to get the system font collection from the DirectWrite 90 // if we are unable to get the system font collection from the DirectWrite
89 // factory. The GetSystemFontCollection method in the IDWriteFactory 91 // factory. The GetSystemFontCollection method in the IDWriteFactory
90 // interface fails with E_INVALIDARG on certain Windows 7 gold versions 92 // interface fails with E_INVALIDARG on certain Windows 7 gold versions
91 // (6.1.7600.*). We should just use GDI in these cases. 93 // (6.1.7600.*). We should just use GDI in these cases.
92 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); 94 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get());
93 if (!direct_write_font_mgr) 95 if (!direct_write_font_mgr)
94 return; 96 return;
95 dwrite_enabled = true; 97 dwrite_enabled = true;
96 SetDefaultSkiaFactory(direct_write_font_mgr); 98 SetDefaultSkiaFactory(direct_write_font_mgr);
97 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); 99 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get());
98 } 100 }
99 101
100 bool IsDirectWriteEnabled() { 102 bool IsDirectWriteEnabled() {
101 return dwrite_enabled; 103 return dwrite_enabled;
102 } 104 }
103 105
104 } // namespace win 106 } // namespace win
105 } // namespace gfx 107 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698