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

Side by Side Diff: content/common/font_warmup_win.cc

Issue 1557513002: Add logic to switch to DirectWrite font proxy via field trial. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make sure g_warmup_fontmgr is not leaked, and other misc fixes. Created 4 years, 11 months 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
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 "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
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
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() && !g_warmup_fontmgr)
492 g_warmup_fontmgr = SkFontMgr_New_DirectWrite();
fdoray 2015/12/31 03:18:16 Is this object leaked during shutdown? If we want
Ilya Kulshin 2016/01/08 00:44:23 The previous code was leaking it, I guess I hadn't
493 // If not using the font proxy, we assume |g_warmup_fontmgr| is already
494 // initialized before this function is called.
490 DCHECK(g_warmup_fontmgr); 495 DCHECK(g_warmup_fontmgr);
491 return new GdiFontPatchDataImpl(path); 496 return new GdiFontPatchDataImpl(path);
492 } 497 }
493 498
494 size_t GetEmulatedGdiHandleCountForTesting() { 499 size_t GetEmulatedGdiHandleCountForTesting() {
495 return g_fake_gdi_object_factory.Get().GetObjectCount(); 500 return g_fake_gdi_object_factory.Get().GetObjectCount();
496 } 501 }
497 502
498 void ResetEmulatedGdiHandlesForTesting() { 503 void ResetEmulatedGdiHandlesForTesting() {
499 g_fake_gdi_object_factory.Get().ResetObjectHandles(); 504 g_fake_gdi_object_factory.Get().ResetObjectHandles();
(...skipping 14 matching lines...) Expand all
514 // down for the CC HUD code, so use the same one here. Note that we don't use 519 // 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 520 // a monospace as would be nice in an attempt to avoid a small startup time
516 // regression, see http://crbug.com/463613. 521 // regression, see http://crbug.com/463613.
517 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( 522 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef(
518 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); 523 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0));
519 DoPreSandboxWarmupForTypeface(hud_typeface.get()); 524 DoPreSandboxWarmupForTypeface(hud_typeface.get());
520 gfx::SetHudTypeface(hud_typeface); 525 gfx::SetHudTypeface(hud_typeface);
521 } 526 }
522 527
523 } // namespace content 528 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698