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

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

Issue 1691073002: Add plumbing in blink to allow overriding the skia font manager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge to head 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
« no previous file with comments | « no previous file | content/child/font_warmup_win.cc » ('j') | skia/config/sk_ref_cnt_ext_release.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/child/font_warmup_win.h" 15 #include "content/child/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"
19 #include "third_party/skia/include/ports/SkFontMgr.h"
18 #include "third_party/skia/include/ports/SkTypeface_win.h" 20 #include "third_party/skia/include/ports/SkTypeface_win.h"
19 21
20 namespace mswr = Microsoft::WRL; 22 namespace mswr = Microsoft::WRL;
21 23
22 namespace content { 24 namespace content {
23 25
24 namespace { 26 namespace {
25 27
26 mswr::ComPtr<DWriteFontCollectionProxy> g_font_collection; 28 mswr::ComPtr<DWriteFontCollectionProxy> g_font_collection;
27 IPC::Sender* g_sender_override = nullptr; 29 IPC::Sender* g_sender_override = nullptr;
(...skipping 23 matching lines...) Expand all
51 DWORD get_proc_address_get_last_error = GetLastError(); 53 DWORD get_proc_address_get_last_error = GetLastError();
52 base::debug::Alias(&dwrite_create_factory_proc); 54 base::debug::Alias(&dwrite_create_factory_proc);
53 base::debug::Alias(&get_proc_address_get_last_error); 55 base::debug::Alias(&get_proc_address_get_last_error);
54 CHECK(false); 56 CHECK(false);
55 } 57 }
56 CHECK(SUCCEEDED(dwrite_create_factory_proc( 58 CHECK(SUCCEEDED(dwrite_create_factory_proc(
57 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), 59 DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
58 reinterpret_cast<IUnknown**>(factory)))); 60 reinterpret_cast<IUnknown**>(factory))));
59 } 61 }
60 62
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() 63 // Needed as a function for Bind()
80 IPC::Sender* GetSenderOverride() { 64 IPC::Sender* GetSenderOverride() {
81 return g_sender_override; 65 return g_sender_override;
82 } 66 }
83 67
84 } // namespace 68 } // namespace
85 69
86 void InitializeDWriteFontProxy( 70 void InitializeDWriteFontProxy(
87 const base::Callback<IPC::Sender*(void)>& sender) { 71 const base::Callback<IPC::Sender*(void)>& sender) {
88 mswr::ComPtr<IDWriteFactory> factory; 72 mswr::ComPtr<IDWriteFactory> factory;
89 73
90 CreateDirectWriteFactory(&factory); 74 CreateDirectWriteFactory(&factory);
91 75
92 if (!g_font_collection) { 76 if (!g_font_collection) {
93 if (g_sender_override) { 77 if (g_sender_override) {
94 mswr::MakeAndInitialize<DWriteFontCollectionProxy>( 78 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
95 &g_font_collection, factory.Get(), base::Bind(&GetSenderOverride)); 79 &g_font_collection, factory.Get(), base::Bind(&GetSenderOverride));
96 } else { 80 } else {
97 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(&g_font_collection, 81 mswr::MakeAndInitialize<DWriteFontCollectionProxy>(&g_font_collection,
98 factory.Get(), sender); 82 factory.Get(), sender);
99 } 83 }
100 } 84 }
101 85
102 PatchDWriteFactory(factory.Get()); 86 skia::RefPtr<SkFontMgr> skia_font_manager = skia::AdoptRef(
87 SkFontMgr_New_DirectWrite(factory.Get(), g_font_collection.Get()));
88 blink::WebFontRendering::setSkiaFontManager(skia_font_manager.get());
103 89
104 blink::WebFontRendering::setDirectWriteFactory(factory.Get()); 90 // Add an extra ref for SetDefaultSkiaFactory, which keeps a ref but doesn't
105 SkFontMgr* skia_font_manager = SkFontMgr_New_DirectWrite(factory.Get()); 91 // addref.
106 SetDefaultSkiaFactory(skia_font_manager); 92 skia_font_manager->ref();
93 SetDefaultSkiaFactory(skia_font_manager.get());
107 } 94 }
108 95
109 void UninitializeDWriteFontProxy() { 96 void UninitializeDWriteFontProxy() {
110 if (g_font_collection) 97 if (g_font_collection)
111 g_font_collection->Unregister(); 98 g_font_collection->Unregister();
112 } 99 }
113 100
114 void SetDWriteFontProxySenderForTesting(IPC::Sender* sender) { 101 void SetDWriteFontProxySenderForTesting(IPC::Sender* sender) {
115 g_sender_override = sender; 102 g_sender_override = sender;
116 } 103 }
117 104
118 } // namespace content 105 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/font_warmup_win.cc » ('j') | skia/config/sk_ref_cnt_ext_release.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698