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

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: Created 5 years, 1 month 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
« ui/gfx/win/direct_write.h ('K') | « 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> 7 #include <dwrite.h>
scottmg 2015/11/13 00:51:46 You can remove this, now that it's in the header.
Ilya Kulshin 2015/11/14 00:25:34 Done.
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/win/registry.h" 12 #include "base/win/registry.h"
13 #include "base/win/scoped_comptr.h" 13 #include "base/win/scoped_comptr.h"
14 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 #include "skia/ext/fontmgr_default_win.h" 15 #include "skia/ext/fontmgr_default_win.h"
16 #include "third_party/skia/include/ports/SkTypeface_win.h" 16 #include "third_party/skia/include/ports/SkTypeface_win.h"
17 #include "ui/gfx/platform_font_win.h" 17 #include "ui/gfx/platform_font_win.h"
18 #include "ui/gfx/switches.h" 18 #include "ui/gfx/switches.h"
19 #include "ui/gfx/win/dpi.h" 19 #include "ui/gfx/win/dpi.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 namespace win { 22 namespace win {
23 23
24 namespace { 24 namespace {
25 25
26 static bool dwrite_enabled = false; 26 static bool dwrite_enabled = false;
27 27 base::win::ScopedComPtr<IDWriteFactory> factory_;
scottmg 2015/11/13 00:51:46 Normally g_factory, instead of factory_.
Ilya Kulshin 2015/11/14 00:25:34 Done.
28 } 28 }
scottmg 2015/11/13 00:51:46 Add newline before }.
Ilya Kulshin 2015/11/14 00:25:34 "git cl format" insists on deleting that newline.
29 29
30 bool ShouldUseDirectWrite() { 30 bool ShouldUseDirectWrite() {
31 // If the flag is currently on, and we're on Win7 or above, we enable 31 // If the flag is currently on, and we're on Win7 or above, we enable
32 // DirectWrite. Skia does not require the additions to DirectWrite in QFE 32 // DirectWrite. Skia does not require the additions to DirectWrite in QFE
33 // 2670838, but a simple 'better than XP' check is not enough. 33 // 2670838, but a simple 'better than XP' check is not enough.
34 if (base::win::GetVersion() < base::win::VERSION_WIN7) 34 if (base::win::GetVersion() < base::win::VERSION_WIN7)
35 return false; 35 return false;
36 36
37 base::win::OSInfo::VersionNumber os_version = 37 base::win::OSInfo::VersionNumber os_version =
38 base::win::OSInfo::GetInstance()->version_number(); 38 base::win::OSInfo::GetInstance()->version_number();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!dwrite_dll) 74 if (!dwrite_dll)
75 return; 75 return;
76 76
77 DWriteCreateFactoryProc dwrite_create_factory_proc = 77 DWriteCreateFactoryProc dwrite_create_factory_proc =
78 reinterpret_cast<DWriteCreateFactoryProc>( 78 reinterpret_cast<DWriteCreateFactoryProc>(
79 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); 79 GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
80 // Not finding the DWriteCreateFactory function indicates a corrupt dll. 80 // Not finding the DWriteCreateFactory function indicates a corrupt dll.
81 if (!dwrite_create_factory_proc) 81 if (!dwrite_create_factory_proc)
82 return; 82 return;
83 83
84 base::win::ScopedComPtr<IDWriteFactory> factory;
85
86 // Failure to create the DirectWrite factory indicates a corrupt dll. 84 // Failure to create the DirectWrite factory indicates a corrupt dll.
87 if (FAILED(dwrite_create_factory_proc( 85 if (FAILED(dwrite_create_factory_proc(
88 DWRITE_FACTORY_TYPE_SHARED, 86 DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
89 __uuidof(IDWriteFactory), 87 reinterpret_cast<IUnknown**>(factory_.Receive()))))
90 reinterpret_cast<IUnknown**>(factory.Receive()))))
91 return; 88 return;
92 89
93 // The skia call to create a new DirectWrite font manager instance can fail 90 // 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 91 // if we are unable to get the system font collection from the DirectWrite
95 // factory. The GetSystemFontCollection method in the IDWriteFactory 92 // factory. The GetSystemFontCollection method in the IDWriteFactory
96 // interface fails with E_INVALIDARG on certain Windows 7 gold versions 93 // interface fails with E_INVALIDARG on certain Windows 7 gold versions
97 // (6.1.7600.*). We should just use GDI in these cases. 94 // (6.1.7600.*). We should just use GDI in these cases.
98 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); 95 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory_.get());
99 if (!direct_write_font_mgr) 96 if (!direct_write_font_mgr)
100 return; 97 return;
101 dwrite_enabled = true; 98 dwrite_enabled = true;
102 SetDefaultSkiaFactory(direct_write_font_mgr); 99 SetDefaultSkiaFactory(direct_write_font_mgr);
103 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); 100 gfx::PlatformFontWin::SetDirectWriteFactory(factory_.get());
104 } 101 }
105 102
106 bool IsDirectWriteEnabled() { 103 bool IsDirectWriteEnabled() {
107 return dwrite_enabled; 104 return dwrite_enabled;
108 } 105 }
109 106
107 void GetDWriteFactory(IDWriteFactory** factory) {
108 MaybeInitializeDirectWrite();
109 base::win::ScopedComPtr<IDWriteFactory> factory_ref = factory_;
scottmg 2015/11/13 00:51:46 It seems like factory_->AddRef(); *factory =
Ilya Kulshin 2015/11/14 00:25:34 Unfortunately, ScopedComPtr explicitly blocks AddR
110 *factory = factory_ref.Detach();
111 }
112
110 } // namespace win 113 } // namespace win
111 } // namespace gfx 114 } // namespace gfx
OLDNEW
« ui/gfx/win/direct_write.h ('K') | « ui/gfx/win/direct_write.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698