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
3 // found in the LICENSE file.
5 #include "content/public/renderer/render_font_warmup_win.h"
9 #include "base/logging.h"
10 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
11 #include "third_party/skia/include/core/SkPaint.h"
12 #include "third_party/skia/include/ports/SkFontMgr.h"
13 #include "third_party/skia/include/ports/SkTypeface_win.h"
19 SkFontMgr
* g_warmup_fontmgr
= NULL
;
21 // Windows-only DirectWrite support. These warm up the DirectWrite paths
22 // before sandbox lock down to allow Skia access to the Font Manager service.
23 void CreateDirectWriteFactory(IDWriteFactory
** factory
) {
24 typedef decltype(DWriteCreateFactory
)* DWriteCreateFactoryProc
;
25 DWriteCreateFactoryProc dwrite_create_factory_proc
=
26 reinterpret_cast<DWriteCreateFactoryProc
>(
27 GetProcAddress(LoadLibraryW(L
"dwrite.dll"), "DWriteCreateFactory"));
28 CHECK(dwrite_create_factory_proc
);
30 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_ISOLATED
,
31 __uuidof(IDWriteFactory
),
32 reinterpret_cast<IUnknown
**>(factory
))));
37 void DoPreSandboxWarmupForTypeface(SkTypeface
* typeface
) {
39 paint_warmup
.setTypeface(typeface
);
41 paint_warmup
.measureText(&glyph
, 2);
44 SkFontMgr
* GetPreSandboxWarmupFontMgr() {
45 if (!g_warmup_fontmgr
) {
46 IDWriteFactory
* factory
;
47 CreateDirectWriteFactory(&factory
);
48 blink::WebFontRendering::setDirectWriteFactory(factory
);
49 g_warmup_fontmgr
= SkFontMgr_New_DirectWrite(factory
);
51 return g_warmup_fontmgr
;
54 } // namespace content