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

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

Issue 738363002: Enable subpixel positioning for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 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') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | 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"
13 #include "base/win/scoped_comptr.h"
11 #include "base/win/windows_version.h" 14 #include "base/win/windows_version.h"
15 #include "skia/ext/fontmgr_default_win.h"
16 #include "third_party/skia/include/ports/SkTypeface_win.h"
17 #include "ui/gfx/platform_font_win.h"
12 #include "ui/gfx/switches.h" 18 #include "ui/gfx/switches.h"
13 #include "ui/gfx/win/dpi.h" 19 #include "ui/gfx/win/dpi.h"
14 20
15 namespace gfx { 21 namespace gfx {
16 namespace win { 22 namespace win {
17 23
18 bool ShouldUseDirectWrite() { 24 bool ShouldUseDirectWrite() {
19 // If the flag is currently on, and we're on Win7 or above, we enable 25 // 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 26 // DirectWrite. Skia does not require the additions to DirectWrite in QFE
21 // 2670838, but a simple 'better than XP' check is not enough. 27 // 2670838, but a simple 'better than XP' check is not enough.
(...skipping 30 matching lines...) Expand all
52 const DWORD kMaxAllowedFontsBeforeFallbackToGDI = 1750; 58 const DWORD kMaxAllowedFontsBeforeFallbackToGDI = 1750;
53 if (reg_iterator.ValueCount() >= kMaxAllowedFontsBeforeFallbackToGDI) 59 if (reg_iterator.ValueCount() >= kMaxAllowedFontsBeforeFallbackToGDI)
54 return false; 60 return false;
55 61
56 // Otherwise, check the field trial. 62 // Otherwise, check the field trial.
57 const std::string group_name = 63 const std::string group_name =
58 base::FieldTrialList::FindFullName("DirectWrite"); 64 base::FieldTrialList::FindFullName("DirectWrite");
59 return group_name != "Disabled"; 65 return group_name != "Disabled";
60 } 66 }
61 67
68 void MaybeInitializeDirectWrite() {
sky 2014/12/01 15:57:22 What happens if this is invoked multiple times?
ckocagil 2014/12/01 19:31:53 We likely leak some objects (DWrite or SkFontMgr)
69 if (!ShouldUseDirectWrite() ||
70 CommandLine::ForCurrentProcess()->HasSwitch(
71 switches::kDisableDirectWriteForUI) ||
72 CommandLine::ForCurrentProcess()->HasSwitch(
73 switches::kDisableHarfBuzzRenderText)) {
74 return;
75 }
76
77 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
sky 2014/12/01 15:57:22 Use using for improved clarity.
ckocagil 2014/12/01 19:31:52 Done.
78 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
79 if (!dwrite_dll)
80 return;
81
82 DWriteCreateFactoryProc dwrite_create_factory_proc =
83 reinterpret_cast<DWriteCreateFactoryProc>(
84 GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
85 // Not finding the DWriteCreateFactory function indicates a corrupt dll.
86 CHECK(dwrite_create_factory_proc);
87
88 base::win::ScopedComPtr<IDWriteFactory> factory;
89
90 CHECK(SUCCEEDED(
91 dwrite_create_factory_proc(
92 DWRITE_FACTORY_TYPE_SHARED,
93 __uuidof(IDWriteFactory),
94 reinterpret_cast<IUnknown**>(factory.Receive()))));
95 // The skia call to create a new DirectWrite font manager instance can fail
96 // if we are unable to get the system font collection from the DirectWrite
97 // factory. The GetSystemFontCollection method in the IDWriteFactory
98 // interface fails with E_INVALIDARG on certain Windows 7 gold versions
99 // (6.1.7600.*). We should just use GDI in these cases.
100 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get());
101 if (direct_write_font_mgr) {
102 SetDefaultSkiaFactory(direct_write_font_mgr);
103 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get());
104 }
105 }
106
62 } // namespace win 107 } // namespace win
63 } // namespace gfx 108 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/win/direct_write.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698