OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "content/public/renderer/render_font_warmup_win.h" |
| 6 |
| 7 #include <dwrite.h> |
| 8 |
| 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" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 namespace { |
| 18 |
| 19 SkFontMgr* g_warmup_fontmgr = NULL; |
| 20 |
| 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); |
| 29 CHECK(SUCCEEDED( |
| 30 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_ISOLATED, |
| 31 __uuidof(IDWriteFactory), |
| 32 reinterpret_cast<IUnknown**>(factory)))); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 void DoPreSandboxWarmupForTypeface(SkTypeface* typeface) { |
| 38 SkPaint paint_warmup; |
| 39 paint_warmup.setTypeface(typeface); |
| 40 wchar_t glyph = L'S'; |
| 41 paint_warmup.measureText(&glyph, 2); |
| 42 } |
| 43 |
| 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); |
| 50 } |
| 51 return g_warmup_fontmgr; |
| 52 } |
| 53 |
| 54 } // namespace content |
OLD | NEW |