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

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

Issue 1514183002: Revert "Create direct write font proxy classes and unit tests." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 | « ui/gfx/win/direct_write.h ('k') | 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 <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/scoped_comptr.h" 13 #include "base/win/scoped_comptr.h"
12 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
13 #include "skia/ext/fontmgr_default_win.h" 15 #include "skia/ext/fontmgr_default_win.h"
14 #include "third_party/skia/include/ports/SkTypeface_win.h" 16 #include "third_party/skia/include/ports/SkTypeface_win.h"
15 #include "ui/gfx/platform_font_win.h" 17 #include "ui/gfx/platform_font_win.h"
16 #include "ui/gfx/switches.h" 18 #include "ui/gfx/switches.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // Can't use GDI on HiDPI. 50 // Can't use GDI on HiDPI.
49 if (gfx::GetDPIScale() > 1.0f) 51 if (gfx::GetDPIScale() > 1.0f)
50 return true; 52 return true;
51 53
52 // Otherwise, check the field trial. 54 // Otherwise, check the field trial.
53 const std::string group_name = 55 const std::string group_name =
54 base::FieldTrialList::FindFullName("DirectWrite"); 56 base::FieldTrialList::FindFullName("DirectWrite");
55 return group_name != "Disabled"; 57 return group_name != "Disabled";
56 } 58 }
57 59
58 void CreateDWriteFactory(IDWriteFactory** factory) { 60 void MaybeInitializeDirectWrite() {
61 static bool tried_dwrite_initialize = false;
62 if (tried_dwrite_initialize)
63 return;
64 tried_dwrite_initialize = true;
65
59 if (!ShouldUseDirectWrite() || 66 if (!ShouldUseDirectWrite() ||
60 base::CommandLine::ForCurrentProcess()->HasSwitch( 67 base::CommandLine::ForCurrentProcess()->HasSwitch(
61 switches::kDisableDirectWriteForUI)) { 68 switches::kDisableDirectWriteForUI)) {
62 return; 69 return;
63 } 70 }
64 71
65 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; 72 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
66 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); 73 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
67 if (!dwrite_dll) 74 if (!dwrite_dll)
68 return; 75 return;
69 76
70 DWriteCreateFactoryProc dwrite_create_factory_proc = 77 DWriteCreateFactoryProc dwrite_create_factory_proc =
71 reinterpret_cast<DWriteCreateFactoryProc>( 78 reinterpret_cast<DWriteCreateFactoryProc>(
72 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); 79 GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
73 // Not finding the DWriteCreateFactory function indicates a corrupt dll. 80 // Not finding the DWriteCreateFactory function indicates a corrupt dll.
74 if (!dwrite_create_factory_proc) 81 if (!dwrite_create_factory_proc)
75 return; 82 return;
76 83
84 base::win::ScopedComPtr<IDWriteFactory> factory;
85
77 // Failure to create the DirectWrite factory indicates a corrupt dll. 86 // Failure to create the DirectWrite factory indicates a corrupt dll.
78 base::win::ScopedComPtr<IUnknown> factory_unknown; 87 if (FAILED(dwrite_create_factory_proc(
79 if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, 88 DWRITE_FACTORY_TYPE_SHARED,
80 __uuidof(IDWriteFactory), 89 __uuidof(IDWriteFactory),
81 factory_unknown.Receive()))) { 90 reinterpret_cast<IUnknown**>(factory.Receive()))))
82 return;
83 }
84 factory_unknown.QueryInterface<IDWriteFactory>(factory);
85 }
86
87 void MaybeInitializeDirectWrite() {
88 static bool tried_dwrite_initialize = false;
89 if (tried_dwrite_initialize)
90 return;
91 tried_dwrite_initialize = true;
92
93 base::win::ScopedComPtr<IDWriteFactory> factory;
94 CreateDWriteFactory(factory.Receive());
95
96 if (factory == nullptr)
97 return; 91 return;
98 92
99 // The skia call to create a new DirectWrite font manager instance can fail 93 // The skia call to create a new DirectWrite font manager instance can fail
100 // if we are unable to get the system font collection from the DirectWrite 94 // if we are unable to get the system font collection from the DirectWrite
101 // factory. The GetSystemFontCollection method in the IDWriteFactory 95 // factory. The GetSystemFontCollection method in the IDWriteFactory
102 // interface fails with E_INVALIDARG on certain Windows 7 gold versions 96 // interface fails with E_INVALIDARG on certain Windows 7 gold versions
103 // (6.1.7600.*). We should just use GDI in these cases. 97 // (6.1.7600.*). We should just use GDI in these cases.
104 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); 98 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get());
105 if (!direct_write_font_mgr) 99 if (!direct_write_font_mgr)
106 return; 100 return;
107 dwrite_enabled = true; 101 dwrite_enabled = true;
108 SetDefaultSkiaFactory(direct_write_font_mgr); 102 SetDefaultSkiaFactory(direct_write_font_mgr);
109 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); 103 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get());
110 } 104 }
111 105
112 bool IsDirectWriteEnabled() { 106 bool IsDirectWriteEnabled() {
113 return dwrite_enabled; 107 return dwrite_enabled;
114 } 108 }
115 109
116 } // namespace win 110 } // namespace win
117 } // namespace gfx 111 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/win/direct_write.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698