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 "content/child/font_warmup_win.h" | 5 #include "content/child/font_warmup_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
| 8 #include <dwrite_2.h> |
8 #include <stdint.h> | 9 #include <stdint.h> |
9 #include <map> | 10 #include <map> |
10 | 11 |
11 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/numerics/safe_conversions.h" | 18 #include "base/numerics/safe_conversions.h" |
18 #include "base/numerics/safe_math.h" | 19 #include "base/numerics/safe_math.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/sys_byteorder.h" | 22 #include "base/sys_byteorder.h" |
22 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
23 #include "base/win/iat_patch_function.h" | 24 #include "base/win/iat_patch_function.h" |
| 25 #include "base/win/scoped_comptr.h" |
24 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
25 #include "content/public/common/dwrite_font_platform_win.h" | 27 #include "content/public/common/dwrite_font_platform_win.h" |
26 #include "ppapi/shared_impl/proxy_lock.h" | 28 #include "ppapi/shared_impl/proxy_lock.h" |
27 #include "skia/ext/fontmgr_default_win.h" | 29 #include "skia/ext/fontmgr_default_win.h" |
28 #include "skia/ext/refptr.h" | 30 #include "skia/ext/refptr.h" |
29 #include "third_party/WebKit/public/web/win/WebFontRendering.h" | 31 #include "third_party/WebKit/public/web/win/WebFontRendering.h" |
30 #include "third_party/skia/include/core/SkPaint.h" | 32 #include "third_party/skia/include/core/SkPaint.h" |
31 #include "third_party/skia/include/ports/SkFontMgr.h" | 33 #include "third_party/skia/include/ports/SkFontMgr.h" |
32 #include "third_party/skia/include/ports/SkTypeface_win.h" | 34 #include "third_party/skia/include/ports/SkTypeface_win.h" |
33 | 35 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 paint_warmup.setTypeface(typeface); | 453 paint_warmup.setTypeface(typeface); |
452 wchar_t glyph = L'S'; | 454 wchar_t glyph = L'S'; |
453 paint_warmup.measureText(&glyph, 2); | 455 paint_warmup.measureText(&glyph, 2); |
454 } | 456 } |
455 | 457 |
456 SkFontMgr* GetPreSandboxWarmupFontMgr() { | 458 SkFontMgr* GetPreSandboxWarmupFontMgr() { |
457 if (!g_warmup_fontmgr) { | 459 if (!g_warmup_fontmgr) { |
458 IDWriteFactory* factory; | 460 IDWriteFactory* factory; |
459 CreateDirectWriteFactory(&factory); | 461 CreateDirectWriteFactory(&factory); |
460 | 462 |
461 g_warmup_fontmgr = | 463 // DirectWrite font fallback does not work if it is initialized after the |
462 SkFontMgr_New_DirectWrite(factory, GetCustomFontCollection(factory)); | 464 // sandbox starts. |
| 465 base::win::ScopedComPtr<IDWriteFactory2> factory2; |
| 466 factory->QueryInterface<IDWriteFactory2>(factory2.Receive()); |
| 467 base::win::ScopedComPtr<IDWriteFontFallback> font_fallback; |
| 468 if (factory2.get()) |
| 469 factory2->GetSystemFontFallback(font_fallback.Receive()); |
| 470 |
| 471 g_warmup_fontmgr = SkFontMgr_New_DirectWrite( |
| 472 factory, GetCustomFontCollection(factory), font_fallback.get()); |
463 blink::WebFontRendering::setSkiaFontManager(g_warmup_fontmgr); | 473 blink::WebFontRendering::setSkiaFontManager(g_warmup_fontmgr); |
464 } | 474 } |
465 return g_warmup_fontmgr; | 475 return g_warmup_fontmgr; |
466 } | 476 } |
467 | 477 |
468 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { | 478 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { |
469 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) | 479 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) |
470 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); | 480 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); |
471 // If not using the font proxy, we assume |g_warmup_fontmgr| is already | 481 // If not using the font proxy, we assume |g_warmup_fontmgr| is already |
472 // initialized before this function is called. | 482 // initialized before this function is called. |
(...skipping 22 matching lines...) Expand all Loading... |
495 | 505 |
496 // We need to warm up *some* font for DirectWrite. Note that we don't use | 506 // We need to warm up *some* font for DirectWrite. Note that we don't use |
497 // a monospace as would be nice in an attempt to avoid a small startup time | 507 // a monospace as would be nice in an attempt to avoid a small startup time |
498 // regression, see http://crbug.com/463613. | 508 // regression, see http://crbug.com/463613. |
499 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( | 509 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( |
500 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); | 510 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); |
501 DoPreSandboxWarmupForTypeface(hud_typeface.get()); | 511 DoPreSandboxWarmupForTypeface(hud_typeface.get()); |
502 } | 512 } |
503 | 513 |
504 } // namespace content | 514 } // namespace content |
OLD | NEW |