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

Unified Diff: content/child/font_warmup_win.cc

Issue 1845063002: Revert of Remove font cache code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/child/font_warmup_win.h ('k') | content/common/dwrite_font_platform_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/font_warmup_win.cc
diff --git a/content/child/font_warmup_win.cc b/content/child/font_warmup_win.cc
index e3c07115ff09b669a0a3fd07e27a72823efea13c..33d18075f642e518a148ade4e5808f83d791a259 100644
--- a/content/child/font_warmup_win.cc
+++ b/content/child/font_warmup_win.cc
@@ -22,9 +22,12 @@
#include "base/trace_event/trace_event.h"
#include "base/win/iat_patch_function.h"
#include "base/win/windows_version.h"
+#include "content/public/common/dwrite_font_platform_win.h"
#include "ppapi/shared_impl/proxy_lock.h"
#include "skia/ext/fontmgr_default_win.h"
#include "skia/ext/refptr.h"
+#include "third_party/WebKit/public/web/win/WebFontRendering.h"
+#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkTypeface_win.h"
@@ -94,6 +97,36 @@
void* in_message_attributes,
void* time_out) {
return STATUS_ACCESS_DENIED;
+}
+
+// Windows-only DirectWrite support. These warm up the DirectWrite paths
+// before sandbox lock down to allow Skia access to the Font Manager service.
+void CreateDirectWriteFactory(IDWriteFactory** factory) {
+ typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
+ HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
+ // TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
+ if (!dwrite_dll) {
+ DWORD load_library_get_last_error = GetLastError();
+ base::debug::Alias(&dwrite_dll);
+ base::debug::Alias(&load_library_get_last_error);
+ CHECK(false);
+ }
+
+ PatchServiceManagerCalls();
+
+ DWriteCreateFactoryProc dwrite_create_factory_proc =
+ reinterpret_cast<DWriteCreateFactoryProc>(
+ GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
+ // TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
+ if (!dwrite_create_factory_proc) {
+ DWORD get_proc_address_get_last_error = GetLastError();
+ base::debug::Alias(&dwrite_create_factory_proc);
+ base::debug::Alias(&get_proc_address_get_last_error);
+ CHECK(false);
+ }
+ CHECK(SUCCEEDED(dwrite_create_factory_proc(
+ DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
+ reinterpret_cast<IUnknown**>(factory))));
}
// Class to fake out a DC or a Font object. Maintains a reference to a
@@ -413,9 +446,30 @@
DCHECK(patched == 0);
}
+void DoPreSandboxWarmupForTypeface(SkTypeface* typeface) {
+ SkPaint paint_warmup;
+ paint_warmup.setTypeface(typeface);
+ wchar_t glyph = L'S';
+ paint_warmup.measureText(&glyph, 2);
+}
+
+SkFontMgr* GetPreSandboxWarmupFontMgr() {
+ if (!g_warmup_fontmgr) {
+ IDWriteFactory* factory;
+ CreateDirectWriteFactory(&factory);
+
+ g_warmup_fontmgr =
+ SkFontMgr_New_DirectWrite(factory, GetCustomFontCollection(factory));
+ blink::WebFontRendering::setSkiaFontManager(g_warmup_fontmgr);
+ }
+ return g_warmup_fontmgr;
+}
+
GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) {
- if (!g_warmup_fontmgr)
+ if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr)
g_warmup_fontmgr = SkFontMgr_New_DirectWrite();
+ // If not using the font proxy, we assume |g_warmup_fontmgr| is already
+ // initialized before this function is called.
DCHECK(g_warmup_fontmgr);
return new GdiFontPatchDataImpl(path);
}
@@ -432,4 +486,19 @@
g_warmup_fontmgr = fontmgr;
}
+void WarmupDirectWrite() {
+ TRACE_EVENT0("startup", "content::WarmupDirectWrite");
+
+ // The objects used here are intentionally not freed as we want the Skia
+ // code to use these objects after warmup.
+ SetDefaultSkiaFactory(GetPreSandboxWarmupFontMgr());
+
+ // We need to warm up *some* font for DirectWrite. Note that we don't use
+ // a monospace as would be nice in an attempt to avoid a small startup time
+ // regression, see http://crbug.com/463613.
+ skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef(
+ GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0));
+ DoPreSandboxWarmupForTypeface(hud_typeface.get());
+}
+
} // namespace content
« no previous file with comments | « content/child/font_warmup_win.h ('k') | content/common/dwrite_font_platform_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698