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

Side by Side Diff: content/renderer/renderer_main_platform_delegate_win.cc

Issue 217813008: Use skia warmup for DirectWrite (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add new factory function to blink and use it Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/renderer_main_platform_delegate.h" 5 #include "content/renderer/renderer_main_platform_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/win/scoped_comptr.h" 11 #include "base/win/scoped_comptr.h"
12 #include "base/win/win_util.h" 12 #include "base/win/win_util.h"
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #include "content/common/sandbox_win.h" 14 #include "content/common/sandbox_win.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/common/injection_test_win.h" 16 #include "content/public/common/injection_test_win.h"
17 #include "content/public/renderer/render_thread.h" 17 #include "content/public/renderer/render_thread.h"
18 #include "content/renderer/render_thread_impl.h" 18 #include "content/renderer/render_thread_impl.h"
19 #include "sandbox/win/src/sandbox.h" 19 #include "sandbox/win/src/sandbox.h"
20 #include "skia/ext/vector_platform_device_emf_win.h" 20 #include "skia/ext/vector_platform_device_emf_win.h"
21 #include "third_party/WebKit/public/web/win/WebFontRendering.h" 21 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
22 #include "third_party/icu/source/i18n/unicode/timezone.h" 22 #include "third_party/icu/source/i18n/unicode/timezone.h"
23 #include "third_party/skia/include/ports/SkFontMgr.h"
23 #include "third_party/skia/include/ports/SkTypeface_win.h" 24 #include "third_party/skia/include/ports/SkTypeface_win.h"
24 25
25 #ifdef ENABLE_VTUNE_JIT_INTERFACE 26 #ifdef ENABLE_VTUNE_JIT_INTERFACE
26 #include "v8/src/third_party/vtune/v8-vtune.h" 27 #include "v8/src/third_party/vtune/v8-vtune.h"
27 #endif 28 #endif
28 29
29 #include <dwrite.h> 30 #include <dwrite.h>
30 31
31 namespace content { 32 namespace content {
32 namespace { 33 namespace {
(...skipping 13 matching lines...) Expand all
46 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current(); 47 RenderThreadImpl* render_thread_impl = RenderThreadImpl::current();
47 if (render_thread_impl) { 48 if (render_thread_impl) {
48 render_thread_impl->PreCacheFontCharacters( 49 render_thread_impl->PreCacheFontCharacters(
49 logfont, 50 logfont,
50 base::string16(text, text_length)); 51 base::string16(text, text_length));
51 } 52 }
52 } 53 }
53 54
54 // Windows-only DirectWrite support. These warm up the DirectWrite paths 55 // Windows-only DirectWrite support. These warm up the DirectWrite paths
55 // before sandbox lock down to allow Skia access to the Font Manager service. 56 // before sandbox lock down to allow Skia access to the Font Manager service.
56 bool CreateDirectWriteFactory(IDWriteFactory** factory) { 57 void CreateDirectWriteFactory(IDWriteFactory** factory) {
57 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc; 58 typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
58 DWriteCreateFactoryProc dwrite_create_factory_proc = 59 DWriteCreateFactoryProc dwrite_create_factory_proc =
59 reinterpret_cast<DWriteCreateFactoryProc>( 60 reinterpret_cast<DWriteCreateFactoryProc>(
60 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory")); 61 GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory"));
61 if (!dwrite_create_factory_proc) 62 CHECK(dwrite_create_factory_proc);
62 return false;
63 CHECK(SUCCEEDED( 63 CHECK(SUCCEEDED(
64 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, 64 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_ISOLATED,
65 __uuidof(IDWriteFactory), 65 __uuidof(IDWriteFactory),
66 reinterpret_cast<IUnknown**>(factory)))); 66 reinterpret_cast<IUnknown**>(factory))));
67 return true;
68 } 67 }
69 68
70 void WarmupDirectWrite() { 69 void WarmupDirectWrite() {
71 base::win::ScopedComPtr<IDWriteFactory> factory; 70 // The objects used here are intentionally not freed as we want the Skia
72 if (!CreateDirectWriteFactory(factory.Receive())) 71 // code to use these objects after warmup.
73 return; 72 IDWriteFactory* factory;
74 73 CreateDirectWriteFactory(&factory);
75 base::win::ScopedComPtr<IDWriteFontCollection> font_collection; 74 blink::WebFontRendering::setDirectWriteFactory(factory);
76 CHECK(SUCCEEDED( 75 SkFontMgr* fontmgr = SkFontMgr_New_DirectWrite(factory);
77 factory->GetSystemFontCollection(font_collection.Receive(), FALSE))); 76 SkTypeface* typeface = fontmgr->legacyCreateTypeface("Times New Roman", 0);
78 base::win::ScopedComPtr<IDWriteFontFamily> font_family; 77 SkPaint paint_warmup;
79 78 paint_warmup.setTypeface(typeface);
80 UINT32 index; 79 wchar_t glyph = L'S';
81 BOOL exists; 80 paint_warmup.measureText(&glyph, 2);
82 CHECK(SUCCEEDED(
83 font_collection->FindFamilyName(L"Times New Roman", &index, &exists)));
84 CHECK(exists);
85 CHECK(
86 SUCCEEDED(font_collection->GetFontFamily(index, font_family.Receive())));
87 base::win::ScopedComPtr<IDWriteFont> font;
88 base::win::ScopedComPtr<IDWriteFontFace> font_face;
89 CHECK(SUCCEEDED(font_family->GetFirstMatchingFont(DWRITE_FONT_WEIGHT_NORMAL,
90 DWRITE_FONT_STRETCH_NORMAL,
91 DWRITE_FONT_STYLE_NORMAL,
92 font.Receive())));
93 CHECK(SUCCEEDED(font->CreateFontFace(font_face.Receive())));
94 DWRITE_GLYPH_METRICS gm;
95 UINT16 glyph = L'S';
96 CHECK(SUCCEEDED(font_face->GetDesignGlyphMetrics(&glyph, 1, &gm)));
97 } 81 }
98 82
99 } // namespace 83 } // namespace
100 84
101 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 85 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
102 const MainFunctionParams& parameters) 86 const MainFunctionParams& parameters)
103 : parameters_(parameters), 87 : parameters_(parameters),
104 sandbox_test_module_(NULL) { 88 sandbox_test_module_(NULL) {
105 } 89 }
106 90
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (run_security_tests) { 177 if (run_security_tests) {
194 int test_count = 0; 178 int test_count = 0;
195 DVLOG(1) << "Running renderer security tests"; 179 DVLOG(1) << "Running renderer security tests";
196 BOOL result = run_security_tests(&test_count); 180 BOOL result = run_security_tests(&test_count);
197 CHECK(result) << "Test number " << test_count << " has failed."; 181 CHECK(result) << "Test number " << test_count << " has failed.";
198 } 182 }
199 } 183 }
200 } 184 }
201 185
202 } // namespace content 186 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698