Make sure webrtc::VideoSourceInterface is released on the main render thread.
[chromium-blink-merge.git] / content / public / renderer / render_font_warmup_win.cc
blob924547fb979312475e843bbf9125c6339055b991
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"
7 #include <dwrite.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"
15 namespace content {
17 namespace {
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);
29 CHECK(SUCCEEDED(
30 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_ISOLATED,
31 __uuidof(IDWriteFactory),
32 reinterpret_cast<IUnknown**>(factory))));
35 } // namespace
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);
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