OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/child/font_warmup_win.h" | 5 #include "content/child/font_warmup_win.h" |
6 | 6 |
7 #include <dwrite.h> | 7 #include <dwrite.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 DWORD get_proc_address_get_last_error = GetLastError(); | 123 DWORD get_proc_address_get_last_error = GetLastError(); |
124 base::debug::Alias(&dwrite_create_factory_proc); | 124 base::debug::Alias(&dwrite_create_factory_proc); |
125 base::debug::Alias(&get_proc_address_get_last_error); | 125 base::debug::Alias(&get_proc_address_get_last_error); |
126 CHECK(false); | 126 CHECK(false); |
127 } | 127 } |
128 CHECK(SUCCEEDED(dwrite_create_factory_proc( | 128 CHECK(SUCCEEDED(dwrite_create_factory_proc( |
129 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), | 129 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), |
130 reinterpret_cast<IUnknown**>(factory)))); | 130 reinterpret_cast<IUnknown**>(factory)))); |
131 } | 131 } |
132 | 132 |
133 HRESULT STDMETHODCALLTYPE StubFontCollection(IDWriteFactory* factory, | |
134 IDWriteFontCollection** col, | |
135 BOOL checkUpdates) { | |
136 // We always return pre-created font collection from here. | |
137 IDWriteFontCollection* custom_collection = GetCustomFontCollection(factory); | |
138 DCHECK(custom_collection != nullptr); | |
139 *col = custom_collection; | |
140 return S_OK; | |
141 } | |
142 | |
143 void PatchDWriteFactory(IDWriteFactory* factory) { | |
144 const unsigned int kGetSystemFontCollectionVTableIndex = 3; | |
145 | |
146 PROC* vtable = *reinterpret_cast<PROC**>(factory); | |
147 PROC* function_ptr = &vtable[kGetSystemFontCollectionVTableIndex]; | |
148 void* stub_function = &StubFontCollection; | |
149 base::win::ModifyCode(function_ptr, &stub_function, sizeof(PROC)); | |
150 } | |
151 | |
152 // Class to fake out a DC or a Font object. Maintains a reference to a | 133 // Class to fake out a DC or a Font object. Maintains a reference to a |
153 // SkTypeFace to emulate the simple operation of a DC and Font. | 134 // SkTypeFace to emulate the simple operation of a DC and Font. |
154 class FakeGdiObject : public base::RefCountedThreadSafe<FakeGdiObject> { | 135 class FakeGdiObject : public base::RefCountedThreadSafe<FakeGdiObject> { |
155 public: | 136 public: |
156 FakeGdiObject(uint32_t magic, void* handle) | 137 FakeGdiObject(uint32_t magic, void* handle) |
157 : handle_(handle), magic_(magic) {} | 138 : handle_(handle), magic_(magic) {} |
158 | 139 |
159 void set_typeface(const skia::RefPtr<SkTypeface>& typeface) { | 140 void set_typeface(const skia::RefPtr<SkTypeface>& typeface) { |
160 typeface_ = typeface; | 141 typeface_ = typeface; |
161 } | 142 } |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 paint_warmup.setTypeface(typeface); | 452 paint_warmup.setTypeface(typeface); |
472 wchar_t glyph = L'S'; | 453 wchar_t glyph = L'S'; |
473 paint_warmup.measureText(&glyph, 2); | 454 paint_warmup.measureText(&glyph, 2); |
474 } | 455 } |
475 | 456 |
476 SkFontMgr* GetPreSandboxWarmupFontMgr() { | 457 SkFontMgr* GetPreSandboxWarmupFontMgr() { |
477 if (!g_warmup_fontmgr) { | 458 if (!g_warmup_fontmgr) { |
478 IDWriteFactory* factory; | 459 IDWriteFactory* factory; |
479 CreateDirectWriteFactory(&factory); | 460 CreateDirectWriteFactory(&factory); |
480 | 461 |
481 GetCustomFontCollection(factory); | 462 g_warmup_fontmgr = |
482 | 463 SkFontMgr_New_DirectWrite(factory, GetCustomFontCollection(factory)); |
483 PatchDWriteFactory(factory); | 464 blink::WebFontRendering::setSkiaFontManager(g_warmup_fontmgr); |
484 | |
485 blink::WebFontRendering::setDirectWriteFactory(factory); | |
486 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory); | |
487 } | 465 } |
488 return g_warmup_fontmgr; | 466 return g_warmup_fontmgr; |
489 } | 467 } |
490 | 468 |
491 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { | 469 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { |
492 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) | 470 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) |
493 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); | 471 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); |
494 // If not using the font proxy, we assume |g_warmup_fontmgr| is already | 472 // If not using the font proxy, we assume |g_warmup_fontmgr| is already |
495 // initialized before this function is called. | 473 // initialized before this function is called. |
496 DCHECK(g_warmup_fontmgr); | 474 DCHECK(g_warmup_fontmgr); |
(...skipping 23 matching lines...) Expand all Loading... |
520 // down for the CC HUD code, so use the same one here. Note that we don't use | 498 // down for the CC HUD code, so use the same one here. Note that we don't use |
521 // a monospace as would be nice in an attempt to avoid a small startup time | 499 // a monospace as would be nice in an attempt to avoid a small startup time |
522 // regression, see http://crbug.com/463613. | 500 // regression, see http://crbug.com/463613. |
523 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( | 501 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( |
524 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); | 502 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); |
525 DoPreSandboxWarmupForTypeface(hud_typeface.get()); | 503 DoPreSandboxWarmupForTypeface(hud_typeface.get()); |
526 gfx::SetHudTypeface(hud_typeface); | 504 gfx::SetHudTypeface(hud_typeface); |
527 } | 505 } |
528 | 506 |
529 } // namespace content | 507 } // namespace content |
OLD | NEW |