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/common/font_warmup_win.h" | 5 #include "content/common/font_warmup_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/numerics/safe_conversions.h" | 17 #include "base/numerics/safe_conversions.h" |
18 #include "base/numerics/safe_math.h" | 18 #include "base/numerics/safe_math.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/sys_byteorder.h" | 21 #include "base/sys_byteorder.h" |
22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
23 #include "base/win/iat_patch_function.h" | 23 #include "base/win/iat_patch_function.h" |
24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
25 #include "content/public/common/dwrite_font_platform_win.h" | 25 #include "content/public/common/dwrite_font_platform_win.h" |
26 #include "ppapi/shared_impl/proxy_lock.h" | |
26 #include "skia/ext/fontmgr_default_win.h" | 27 #include "skia/ext/fontmgr_default_win.h" |
27 #include "skia/ext/refptr.h" | 28 #include "skia/ext/refptr.h" |
28 #include "third_party/WebKit/public/web/win/WebFontRendering.h" | 29 #include "third_party/WebKit/public/web/win/WebFontRendering.h" |
29 #include "third_party/skia/include/core/SkPaint.h" | 30 #include "third_party/skia/include/core/SkPaint.h" |
30 #include "third_party/skia/include/ports/SkFontMgr.h" | 31 #include "third_party/skia/include/ports/SkFontMgr.h" |
31 #include "third_party/skia/include/ports/SkTypeface_win.h" | 32 #include "third_party/skia/include/ports/SkTypeface_win.h" |
32 #include "ui/gfx/hud_font.h" | 33 #include "ui/gfx/hud_font.h" |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 | 36 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 CHECK(g_warmup_fontmgr); | 249 CHECK(g_warmup_fontmgr); |
249 int weight = log_font->lfWeight; | 250 int weight = log_font->lfWeight; |
250 if (weight == FW_DONTCARE) | 251 if (weight == FW_DONTCARE) |
251 weight = SkFontStyle::kNormal_Weight; | 252 weight = SkFontStyle::kNormal_Weight; |
252 | 253 |
253 SkFontStyle style(weight, log_font->lfWidth, | 254 SkFontStyle style(weight, log_font->lfWidth, |
254 log_font->lfItalic ? SkFontStyle::kItalic_Slant | 255 log_font->lfItalic ? SkFontStyle::kItalic_Slant |
255 : SkFontStyle::kUpright_Slant); | 256 : SkFontStyle::kUpright_Slant); |
256 | 257 |
257 std::string family_name = base::WideToUTF8(log_font->lfFaceName); | 258 std::string family_name = base::WideToUTF8(log_font->lfFaceName); |
259 ppapi::ProxyAutoLock lock; // Needed for DirectWrite font proxy. | |
258 return skia::AdoptRef( | 260 return skia::AdoptRef( |
259 g_warmup_fontmgr->matchFamilyStyle(family_name.c_str(), style)); | 261 g_warmup_fontmgr->matchFamilyStyle(family_name.c_str(), style)); |
260 } | 262 } |
261 | 263 |
262 HDC WINAPI CreateCompatibleDCPatch(HDC dc_handle) { | 264 HDC WINAPI CreateCompatibleDCPatch(HDC dc_handle) { |
263 scoped_refptr<FakeGdiObject> ret = | 265 scoped_refptr<FakeGdiObject> ret = |
264 g_fake_gdi_object_factory.Get().Create(kFakeDCMagic); | 266 g_fake_gdi_object_factory.Get().Create(kFakeDCMagic); |
265 return static_cast<HDC>(ret->handle()); | 267 return static_cast<HDC>(ret->handle()); |
266 } | 268 } |
267 | 269 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 481 |
480 PatchDWriteFactory(factory); | 482 PatchDWriteFactory(factory); |
481 | 483 |
482 blink::WebFontRendering::setDirectWriteFactory(factory); | 484 blink::WebFontRendering::setDirectWriteFactory(factory); |
483 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory); | 485 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory); |
484 } | 486 } |
485 return g_warmup_fontmgr; | 487 return g_warmup_fontmgr; |
486 } | 488 } |
487 | 489 |
488 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { | 490 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { |
489 // We assume the fontmgr is already warmed up before calling this. | 491 if (content::ShouldUseDirectWriteFontProxyFieldTrial()) { |
fdoray
2015/12/30 01:15:08
// If the font cache is used, |g_warmup_fontmgr| i
Ilya Kulshin
2015/12/30 01:59:46
Good point about the leak. From tracing the code i
| |
490 DCHECK(g_warmup_fontmgr); | 492 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); |
493 } else { | |
494 // We assume the fontmgr is already warmed up before calling this. | |
495 DCHECK(g_warmup_fontmgr); | |
496 } | |
491 return new GdiFontPatchDataImpl(path); | 497 return new GdiFontPatchDataImpl(path); |
492 } | 498 } |
493 | 499 |
494 size_t GetEmulatedGdiHandleCountForTesting() { | 500 size_t GetEmulatedGdiHandleCountForTesting() { |
495 return g_fake_gdi_object_factory.Get().GetObjectCount(); | 501 return g_fake_gdi_object_factory.Get().GetObjectCount(); |
496 } | 502 } |
497 | 503 |
498 void ResetEmulatedGdiHandlesForTesting() { | 504 void ResetEmulatedGdiHandlesForTesting() { |
499 g_fake_gdi_object_factory.Get().ResetObjectHandles(); | 505 g_fake_gdi_object_factory.Get().ResetObjectHandles(); |
500 } | 506 } |
(...skipping 13 matching lines...) Expand all Loading... | |
514 // down for the CC HUD code, so use the same one here. Note that we don't use | 520 // down for the CC HUD code, so use the same one here. Note that we don't use |
515 // a monospace as would be nice in an attempt to avoid a small startup time | 521 // a monospace as would be nice in an attempt to avoid a small startup time |
516 // regression, see http://crbug.com/463613. | 522 // regression, see http://crbug.com/463613. |
517 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( | 523 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( |
518 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); | 524 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); |
519 DoPreSandboxWarmupForTypeface(hud_typeface.get()); | 525 DoPreSandboxWarmupForTypeface(hud_typeface.get()); |
520 gfx::SetHudTypeface(hud_typeface); | 526 gfx::SetHudTypeface(hud_typeface); |
521 } | 527 } |
522 | 528 |
523 } // namespace content | 529 } // namespace content |
OLD | NEW |