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

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

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