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

Side by Side Diff: content/child/font_warmup_win.cc

Issue 1682813004: Revert of Add plumbing in blink to allow overriding the default font collection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
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
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
133 // Class to fake out a DC or a Font object. Maintains a reference to a 152 // Class to fake out a DC or a Font object. Maintains a reference to a
134 // SkTypeFace to emulate the simple operation of a DC and Font. 153 // SkTypeFace to emulate the simple operation of a DC and Font.
135 class FakeGdiObject : public base::RefCountedThreadSafe<FakeGdiObject> { 154 class FakeGdiObject : public base::RefCountedThreadSafe<FakeGdiObject> {
136 public: 155 public:
137 FakeGdiObject(uint32_t magic, void* handle) 156 FakeGdiObject(uint32_t magic, void* handle)
138 : handle_(handle), magic_(magic) {} 157 : handle_(handle), magic_(magic) {}
139 158
140 void set_typeface(const skia::RefPtr<SkTypeface>& typeface) { 159 void set_typeface(const skia::RefPtr<SkTypeface>& typeface) {
141 typeface_ = typeface; 160 typeface_ = typeface;
142 } 161 }
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 paint_warmup.setTypeface(typeface); 471 paint_warmup.setTypeface(typeface);
453 wchar_t glyph = L'S'; 472 wchar_t glyph = L'S';
454 paint_warmup.measureText(&glyph, 2); 473 paint_warmup.measureText(&glyph, 2);
455 } 474 }
456 475
457 SkFontMgr* GetPreSandboxWarmupFontMgr() { 476 SkFontMgr* GetPreSandboxWarmupFontMgr() {
458 if (!g_warmup_fontmgr) { 477 if (!g_warmup_fontmgr) {
459 IDWriteFactory* factory; 478 IDWriteFactory* factory;
460 CreateDirectWriteFactory(&factory); 479 CreateDirectWriteFactory(&factory);
461 480
462 g_warmup_fontmgr = 481 GetCustomFontCollection(factory);
463 SkFontMgr_New_DirectWrite(factory, GetCustomFontCollection(factory)); 482
464 blink::WebFontRendering::setSkiaFontManager(g_warmup_fontmgr); 483 PatchDWriteFactory(factory);
484
485 blink::WebFontRendering::setDirectWriteFactory(factory);
486 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(factory);
465 } 487 }
466 return g_warmup_fontmgr; 488 return g_warmup_fontmgr;
467 } 489 }
468 490
469 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) { 491 GdiFontPatchData* PatchGdiFontEnumeration(const base::FilePath& path) {
470 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr) 492 if (ShouldUseDirectWriteFontProxyFieldTrial() && !g_warmup_fontmgr)
471 g_warmup_fontmgr = SkFontMgr_New_DirectWrite(); 493 g_warmup_fontmgr = SkFontMgr_New_DirectWrite();
472 // If not using the font proxy, we assume |g_warmup_fontmgr| is already 494 // If not using the font proxy, we assume |g_warmup_fontmgr| is already
473 // initialized before this function is called. 495 // initialized before this function is called.
474 DCHECK(g_warmup_fontmgr); 496 DCHECK(g_warmup_fontmgr);
(...skipping 23 matching lines...) Expand all
498 // down for the CC HUD code, so use the same one here. Note that we don't use 520 // down for the CC HUD code, so use the same one here. Note that we don't use
499 // a monospace as would be nice in an attempt to avoid a small startup time 521 // a monospace as would be nice in an attempt to avoid a small startup time
500 // regression, see http://crbug.com/463613. 522 // regression, see http://crbug.com/463613.
501 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef( 523 skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef(
502 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0)); 524 GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0));
503 DoPreSandboxWarmupForTypeface(hud_typeface.get()); 525 DoPreSandboxWarmupForTypeface(hud_typeface.get());
504 gfx::SetHudTypeface(hud_typeface); 526 gfx::SetHudTypeface(hud_typeface);
505 } 527 }
506 528
507 } // namespace content 529 } // namespace content
OLDNEW
« no previous file with comments | « content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.cc ('k') | third_party/WebKit/Source/platform/fonts/FontCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698