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 |
36 namespace { | 37 namespace { |
37 | 38 |
39 // The Skia font manager, used for the life of the process (leaked at the end). | |
38 SkFontMgr* g_warmup_fontmgr = nullptr; | 40 SkFontMgr* g_warmup_fontmgr = nullptr; |
39 | 41 |
40 base::win::IATPatchFunction g_iat_patch_open_sc_manager; | 42 base::win::IATPatchFunction g_iat_patch_open_sc_manager; |
41 base::win::IATPatchFunction g_iat_patch_close_service_handle; | 43 base::win::IATPatchFunction g_iat_patch_close_service_handle; |
42 base::win::IATPatchFunction g_iat_patch_open_service; | 44 base::win::IATPatchFunction g_iat_patch_open_service; |
43 base::win::IATPatchFunction g_iat_patch_start_service; | 45 base::win::IATPatchFunction g_iat_patch_start_service; |
44 base::win::IATPatchFunction g_iat_patch_nt_connect_port; | 46 base::win::IATPatchFunction g_iat_patch_nt_connect_port; |
45 | 47 |
46 // These are from ntddk.h | 48 // These are from ntddk.h |
47 #if !defined(STATUS_ACCESS_DENIED) | 49 #if !defined(STATUS_ACCESS_DENIED) |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 CHECK(g_warmup_fontmgr); | 250 CHECK(g_warmup_fontmgr); |
249 int weight = log_font->lfWeight; | 251 int weight = log_font->lfWeight; |
250 if (weight == FW_DONTCARE) | 252 if (weight == FW_DONTCARE) |
251 weight = SkFontStyle::kNormal_Weight; | 253 weight = SkFontStyle::kNormal_Weight; |
252 | 254 |
253 SkFontStyle style(weight, log_font->lfWidth, | 255 SkFontStyle style(weight, log_font->lfWidth, |
254 log_font->lfItalic ? SkFontStyle::kItalic_Slant | 256 log_font->lfItalic ? SkFontStyle::kItalic_Slant |
255 : SkFontStyle::kUpright_Slant); | 257 : SkFontStyle::kUpright_Slant); |
256 | 258 |
257 std::string family_name = base::WideToUTF8(log_font->lfFaceName); | 259 std::string family_name = base::WideToUTF8(log_font->lfFaceName); |
260 ppapi::ProxyAutoLock lock; // Needed for DirectWrite font proxy. | |
258 return skia::AdoptRef( | 261 return skia::AdoptRef( |
259 g_warmup_fontmgr->matchFamilyStyle(family_name.c_str(), style)); | 262 g_warmup_fontmgr->matchFamilyStyle(family_name.c_str(), style)); |
260 } | 263 } |
261 | 264 |
262 HDC WINAPI CreateCompatibleDCPatch(HDC dc_handle) { | 265 HDC WINAPI CreateCompatibleDCPatch(HDC dc_handle) { |
263 scoped_refptr<FakeGdiObject> ret = | 266 scoped_refptr<FakeGdiObject> ret = |
264 g_fake_gdi_object_factory.Get().Create(kFakeDCMagic); | 267 g_fake_gdi_object_factory.Get().Create(kFakeDCMagic); |
265 return static_cast<HDC>(ret->handle()); | 268 return static_cast<HDC>(ret->handle()); |
266 } | 269 } |
267 | 270 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 | 482 |
480 PatchDWriteFactory(factory); | 483 PatchDWriteFactory(factory); |
481 | 484 |
482 blink::WebFontRendering::setDirectWriteFactory(factory); | 485 blink::WebFontRendering::setDirectWriteFactory(factory); |
483 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory); | 486 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory); |
484 } | 487 } |
485 return g_warmup_fontmgr; | 488 return g_warmup_fontmgr; |
486 } | 489 } |
487 | 490 |
488 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { | 491 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { |
489 // We assume the fontmgr is already warmed up before calling this. | 492 if (content::ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) |
jam
2016/01/11 05:05:45
nit: no content::
Ilya Kulshin
2016/01/11 20:56:52
Done.
| |
493 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); | |
494 // If not using the font proxy, we assume |g_warmup_fontmgr| is already | |
495 // initialized before this function is called. | |
490 DCHECK(g_warmup_fontmgr); | 496 DCHECK(g_warmup_fontmgr); |
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(); |
(...skipping 14 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 |