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

Side by Side Diff: content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.cc

Issue 1591883002: Add plumbing in blink to allow overriding the default font collection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up extra headers and declarations Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/dwrite_font_proxy/dwrite_font_proxy_init_win.h" 5 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_init_win.h"
6 6
7 #include <dwrite.h> 7 #include <dwrite.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
12 #include "base/win/iat_patch_function.h" 12 #include "base/win/iat_patch_function.h"
13 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" 14 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h"
15 #include "content/common/font_warmup_win.h" 15 #include "content/common/font_warmup_win.h"
16 #include "skia/ext/fontmgr_default_win.h" 16 #include "skia/ext/fontmgr_default_win.h"
17 #include "skia/ext/refptr.h"
17 #include "third_party/WebKit/public/web/win/WebFontRendering.h" 18 #include "third_party/WebKit/public/web/win/WebFontRendering.h"
18 #include "third_party/skia/include/ports/SkTypeface_win.h" 19 #include "third_party/skia/include/ports/SkTypeface_win.h"
19 20
20 namespace mswr = Microsoft::WRL; 21 namespace mswr = Microsoft::WRL;
21 22
22 namespace content { 23 namespace content {
23 24
24 namespace { 25 namespace {
25 26
26 mswr::ComPtr<DWriteFontCollectionProxy> g_font_collection; 27 mswr::ComPtr<DWriteFontCollectionProxy> g_font_collection;
(...skipping 24 matching lines...) Expand all
51 DWORD get_proc_address_get_last_error = GetLastError(); 52 DWORD get_proc_address_get_last_error = GetLastError();
52 base::debug::Alias(&dwrite_create_factory_proc); 53 base::debug::Alias(&dwrite_create_factory_proc);
53 base::debug::Alias(&get_proc_address_get_last_error); 54 base::debug::Alias(&get_proc_address_get_last_error);
54 CHECK(false); 55 CHECK(false);
55 } 56 }
56 CHECK(SUCCEEDED(dwrite_create_factory_proc( 57 CHECK(SUCCEEDED(dwrite_create_factory_proc(
57 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), 58 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
58 reinterpret_cast<IUnknown**>(factory)))); 59 reinterpret_cast<IUnknown**>(factory))));
59 } 60 }
60 61
61 HRESULT STDMETHODCALLTYPE StubFontCollection(IDWriteFactory* factory,
62 IDWriteFontCollection** col,
63 BOOL checkUpdates) {
64 DCHECK(g_font_collection);
65 g_font_collection.CopyTo(col);
66 return S_OK;
67 }
68
69 // Copied from content/common/font_warmup_win.cc
70 void PatchDWriteFactory(IDWriteFactory* factory) {
71 const unsigned int kGetSystemFontCollectionVTableIndex = 3;
72
73 PROC* vtable = *reinterpret_cast<PROC**>(factory);
74 PROC* function_ptr = &vtable[kGetSystemFontCollectionVTableIndex];
75 void* stub_function = &StubFontCollection;
76 base::win::ModifyCode(function_ptr, &stub_function, sizeof(PROC));
77 }
78
79 // Needed as a function for Bind() 62 // Needed as a function for Bind()
80 IPC::Sender* GetSenderOverride() { 63 IPC::Sender* GetSenderOverride() {
81 return g_sender_override; 64 return g_sender_override;
82 } 65 }
83 66
84 } // namespace 67 } // namespace
85 68
86 void InitializeDWriteFontProxy( 69 void InitializeDWriteFontProxy(
87 const base::Callback<IPC::Sender*(void)>& sender) { 70 const base::Callback<IPC::Sender*(void)>& sender) {
88 mswr::ComPtr<IDWriteFactory> factory; 71 mswr::ComPtr<IDWriteFactory> factory;
89 72
90 CreateDirectWriteFactory(&factory); 73 CreateDirectWriteFactory(&factory);
91 74
92 if (!g_font_collection) { 75 if (!g_font_collection) {
93 if (g_sender_override) { 76 if (g_sender_override) {
94 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( 77 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
95 &g_font_collection, factory.Get(), base::Bind(&GetSenderOverride)); 78 &g_font_collection, factory.Get(), base::Bind(&GetSenderOverride));
96 } else { 79 } else {
97 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(&g_font_collection, 80 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(&g_font_collection,
98 factory.Get(), sender); 81 factory.Get(), sender);
99 } 82 }
100 } 83 }
101 84
102 PatchDWriteFactory(factory.Get()); 85 skia::RefPtr<SkFontMgr> skia_font_manager = skia::AdoptRef(
86 SkFontMgr_New_DirectWrite(factory.Get(), g_font_collection.Get()));
87 blink::WebFontRendering::setSkiaFontManager(skia_font_manager);
103 88
104 blink::WebFontRendering::setDirectWriteFactory(factory.Get()); 89 // Add an extra ref for SetDefaultSkiaFactory, which keeps a ref but doesn't
105 SkFontMgr* skia_font_manager = SkFontMgr_New_DirectWrite(factory.Get()); 90 // addref.
106 SetDefaultSkiaFactory(skia_font_manager); 91 skia_font_manager->ref();
92 SetDefaultSkiaFactory(skia_font_manager.get());
107 } 93 }
108 94
109 void UninitializeDWriteFontProxy() { 95 void UninitializeDWriteFontProxy() {
110 if (g_font_collection) 96 if (g_font_collection)
111 g_font_collection->Unregister(); 97 g_font_collection->Unregister();
112 } 98 }
113 99
114 void SetDWriteFontProxySenderForTesting(IPC::Sender* sender) { 100 void SetDWriteFontProxySenderForTesting(IPC::Sender* sender) {
115 g_sender_override = sender; 101 g_sender_override = sender;
116 } 102 }
117 103
118 } // namespace content 104 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698