OLD | NEW |
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" |
11 #include "base/win/windows_version.h" | 11 #include "base/win/windows_version.h" |
12 #include "skia/ext/fontmgr_default_win.h" | 12 #include "skia/ext/fontmgr_default_win.h" |
13 #include "third_party/skia/include/ports/SkTypeface_win.h" | 13 #include "third_party/skia/include/ports/SkTypeface_win.h" |
14 #include "ui/gfx/platform_font_win.h" | 14 #include "ui/gfx/platform_font_win.h" |
15 #include "ui/gfx/switches.h" | 15 #include "ui/gfx/switches.h" |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 namespace win { | 18 namespace win { |
19 | 19 |
20 void CreateDWriteFactory(IDWriteFactory** factory) { | 20 void CreateDWriteFactory(IDWriteFactory** factory) { |
| 21 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*; |
| 22 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll"); |
| 23 if (!dwrite_dll) |
| 24 return; |
| 25 |
| 26 DWriteCreateFactoryProc dwrite_create_factory_proc = |
| 27 reinterpret_cast<DWriteCreateFactoryProc>( |
| 28 GetProcAddress(dwrite_dll, "DWriteCreateFactory")); |
| 29 // Not finding the DWriteCreateFactory function indicates a corrupt dll. |
| 30 if (!dwrite_create_factory_proc) |
| 31 return; |
| 32 |
| 33 // Failure to create the DirectWrite factory indicates a corrupt dll. |
21 base::win::ScopedComPtr<IUnknown> factory_unknown; | 34 base::win::ScopedComPtr<IUnknown> factory_unknown; |
22 HRESULT hr = | 35 if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, |
23 DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), | 36 __uuidof(IDWriteFactory), |
24 factory_unknown.Receive()); | 37 factory_unknown.Receive()))) { |
25 if (FAILED(hr)) { | |
26 base::debug::Alias(&hr); | |
27 CHECK(false); | |
28 return; | 38 return; |
29 } | 39 } |
30 factory_unknown.QueryInterface<IDWriteFactory>(factory); | 40 factory_unknown.QueryInterface<IDWriteFactory>(factory); |
31 } | 41 } |
32 | 42 |
33 void MaybeInitializeDirectWrite() { | 43 void MaybeInitializeDirectWrite() { |
34 static bool tried_dwrite_initialize = false; | 44 static bool tried_dwrite_initialize = false; |
35 if (tried_dwrite_initialize) | 45 if (tried_dwrite_initialize) |
36 return; | 46 return; |
37 tried_dwrite_initialize = true; | 47 tried_dwrite_initialize = true; |
(...skipping 16 matching lines...) Expand all Loading... |
54 // (6.1.7600.*). We should just use GDI in these cases. | 64 // (6.1.7600.*). We should just use GDI in these cases. |
55 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); | 65 SkFontMgr* direct_write_font_mgr = SkFontMgr_New_DirectWrite(factory.get()); |
56 if (!direct_write_font_mgr) | 66 if (!direct_write_font_mgr) |
57 return; | 67 return; |
58 SetDefaultSkiaFactory(direct_write_font_mgr); | 68 SetDefaultSkiaFactory(direct_write_font_mgr); |
59 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); | 69 gfx::PlatformFontWin::SetDirectWriteFactory(factory.get()); |
60 } | 70 } |
61 | 71 |
62 } // namespace win | 72 } // namespace win |
63 } // namespace gfx | 73 } // namespace gfx |
OLD | NEW |