Commit 7561063a authored by kulshin's avatar kulshin Committed by Commit bot

Link to DirectWrite directly, instead of calling LoadLibrary

BUG=

Review-Url: https://codereview.chromium.org/2029343002
Cr-Commit-Position: refs/heads/master@{#403344}
parent 378c735d
...@@ -80,6 +80,10 @@ source_set("child") { ...@@ -80,6 +80,10 @@ source_set("child") {
deps += [ "//third_party/android_tools:cpu_features" ] deps += [ "//third_party/android_tools:cpu_features" ]
} }
if (is_win) {
libs = [ "dwrite.lib" ]
}
if (enable_plugins) { if (enable_plugins) {
deps += [ deps += [
"//ppapi/proxy", "//ppapi/proxy",
......
...@@ -31,31 +31,11 @@ IPC::Sender* g_sender_override = nullptr; ...@@ -31,31 +31,11 @@ IPC::Sender* g_sender_override = nullptr;
// Windows-only DirectWrite support. These warm up the DirectWrite paths // Windows-only DirectWrite support. These warm up the DirectWrite paths
// before sandbox lock down to allow Skia access to the Font Manager service. // before sandbox lock down to allow Skia access to the Font Manager service.
void CreateDirectWriteFactory(IDWriteFactory** factory) { void CreateDirectWriteFactory(IDWriteFactory** factory) {
typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
// TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
if (!dwrite_dll) {
DWORD load_library_get_last_error = GetLastError();
base::debug::Alias(&dwrite_dll);
base::debug::Alias(&load_library_get_last_error);
CHECK(false);
}
// This shouldn't be necessary, but not having this causes breakage in // This shouldn't be necessary, but not having this causes breakage in
// content_browsertests, and possibly other high-stress cases. // content_browsertests, and possibly other high-stress cases.
PatchServiceManagerCalls(); PatchServiceManagerCalls();
DWriteCreateFactoryProc dwrite_create_factory_proc = CHECK(SUCCEEDED(DWriteCreateFactory(
reinterpret_cast<DWriteCreateFactoryProc>(
GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
// TODO(scottmg): Temporary code to track crash in http://crbug.com/387867.
if (!dwrite_create_factory_proc) {
DWORD get_proc_address_get_last_error = GetLastError();
base::debug::Alias(&dwrite_create_factory_proc);
base::debug::Alias(&get_proc_address_get_last_error);
CHECK(false);
}
CHECK(SUCCEEDED(dwrite_create_factory_proc(
DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory), DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(factory)))); reinterpret_cast<IUnknown**>(factory))));
} }
......
...@@ -24,27 +24,9 @@ namespace content { ...@@ -24,27 +24,9 @@ namespace content {
namespace { namespace {
void CreateDWriteFactory(IUnknown** factory) {
using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
if (!dwrite_dll)
return;
DWriteCreateFactoryProc dwrite_create_factory_proc =
reinterpret_cast<DWriteCreateFactoryProc>(
GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
if (!dwrite_create_factory_proc)
return;
dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), factory);
}
class DWriteFontProxyUnitTest : public testing::Test { class DWriteFontProxyUnitTest : public testing::Test {
public: public:
DWriteFontProxyUnitTest() { DWriteFontProxyUnitTest() {
if (!factory)
return;
fake_collection_ = new FakeFontCollection(); fake_collection_ = new FakeFontCollection();
SetupFonts(fake_collection_.get()); SetupFonts(fake_collection_.get());
mswr::MakeAndInitialize<DWriteFontCollectionProxy>( mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
...@@ -71,7 +53,8 @@ class DWriteFontProxyUnitTest : public testing::Test { ...@@ -71,7 +53,8 @@ class DWriteFontProxyUnitTest : public testing::Test {
} }
static void SetUpTestCase() { static void SetUpTestCase() {
CreateDWriteFactory(&factory); DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
&factory);
std::vector<base::char16> font_path; std::vector<base::char16> font_path;
font_path.resize(MAX_PATH); font_path.resize(MAX_PATH);
...@@ -96,9 +79,6 @@ std::vector<base::string16> DWriteFontProxyUnitTest::arial_font_files; ...@@ -96,9 +79,6 @@ std::vector<base::string16> DWriteFontProxyUnitTest::arial_font_files;
mswr::ComPtr<IDWriteFactory> DWriteFontProxyUnitTest::factory; mswr::ComPtr<IDWriteFactory> DWriteFontProxyUnitTest::factory;
TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) { TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) {
if (!factory)
return;
UINT32 family_count = collection_->GetFontFamilyCount(); UINT32 family_count = collection_->GetFontFamilyCount();
EXPECT_EQ(3u, family_count); EXPECT_EQ(3u, family_count);
...@@ -114,8 +94,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) { ...@@ -114,8 +94,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) { TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -133,8 +111,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) { ...@@ -133,8 +111,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) { TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -150,8 +126,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) { ...@@ -150,8 +126,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) { TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -167,8 +141,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) { ...@@ -167,8 +141,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) {
TEST_F(DWriteFontProxyUnitTest, GetFontFamilyShouldCreateFamily) { TEST_F(DWriteFontProxyUnitTest, GetFontFamilyShouldCreateFamily) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -214,8 +186,6 @@ void CheckLocale(const base::string16& locale_name, ...@@ -214,8 +186,6 @@ void CheckLocale(const base::string16& locale_name,
TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) { TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -253,8 +223,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) { ...@@ -253,8 +223,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) {
TEST_F(DWriteFontProxyUnitTest, GetFontCollection) { TEST_F(DWriteFontProxyUnitTest, GetFontCollection) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -275,8 +243,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontCollection) { ...@@ -275,8 +243,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontCollection) {
TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) { TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -295,8 +261,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) { ...@@ -295,8 +261,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) {
TEST_F(DWriteFontProxyUnitTest, TEST_F(DWriteFontProxyUnitTest,
GetFontFamilyShouldNotCreateFamilyWhenIndexIsInvalid) { GetFontFamilyShouldNotCreateFamilyWhenIndexIsInvalid) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -312,8 +276,6 @@ TEST_F(DWriteFontProxyUnitTest, ...@@ -312,8 +276,6 @@ TEST_F(DWriteFontProxyUnitTest,
TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) { TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
...@@ -348,8 +310,6 @@ TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) { ...@@ -348,8 +310,6 @@ TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) {
TEST_F(DWriteFontProxyUnitTest, GetFontFromFontFaceShouldFindFont) { TEST_F(DWriteFontProxyUnitTest, GetFontFromFontFaceShouldFindFont) {
HRESULT hr; HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX; UINT32 index = UINT_MAX;
BOOL exists = FALSE; BOOL exists = FALSE;
......
...@@ -25,7 +25,8 @@ namespace { ...@@ -25,7 +25,8 @@ namespace {
class FontFallbackUnitTest : public testing::Test { class FontFallbackUnitTest : public testing::Test {
public: public:
FontFallbackUnitTest() { FontFallbackUnitTest() {
CreateDWriteFactory(&factory_); DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), &factory_);
factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE, factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE,
L"en-us", true /* ignoreUserOverride */, L"en-us", true /* ignoreUserOverride */,
...@@ -47,22 +48,6 @@ class FontFallbackUnitTest : public testing::Test { ...@@ -47,22 +48,6 @@ class FontFallbackUnitTest : public testing::Test {
&collection_, factory_.Get(), fake_collection_->GetSender()); &collection_, factory_.Get(), fake_collection_->GetSender());
} }
void CreateDWriteFactory(IUnknown** factory) {
using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
if (!dwrite_dll)
return;
DWriteCreateFactoryProc dwrite_create_factory_proc =
reinterpret_cast<DWriteCreateFactoryProc>(
GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
if (!dwrite_create_factory_proc)
return;
dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), factory);
}
scoped_refptr<FakeFontCollection> fake_collection_; scoped_refptr<FakeFontCollection> fake_collection_;
mswr::ComPtr<IDWriteFactory> factory_; mswr::ComPtr<IDWriteFactory> factory_;
mswr::ComPtr<DWriteFontCollectionProxy> collection_; mswr::ComPtr<DWriteFontCollectionProxy> collection_;
......
...@@ -254,6 +254,15 @@ ...@@ -254,6 +254,15 @@
'../build/android/ndk.gyp:cpu_features', '../build/android/ndk.gyp:cpu_features',
], ],
}], }],
['OS=="win"', {
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
]
}
}
}],
['enable_plugins==0', { ['enable_plugins==0', {
'sources!': [ 'sources!': [
'child/browser_font_resource_trusted.cc', 'child/browser_font_resource_trusted.cc',
......
...@@ -1152,6 +1152,13 @@ ...@@ -1152,6 +1152,13 @@
'dependencies': [ 'dependencies': [
'../third_party/iaccessible2/iaccessible2.gyp:iaccessible2', '../third_party/iaccessible2/iaccessible2.gyp:iaccessible2',
], ],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
],
},
},
}], }],
['OS=="mac"', { ['OS=="mac"', {
# These flags are needed to run the test on Mac. # These flags are needed to run the test on Mac.
......
...@@ -792,6 +792,7 @@ test("content_unittests") { ...@@ -792,6 +792,7 @@ test("content_unittests") {
} }
if (is_win) { if (is_win) {
deps += [ "//third_party/iaccessible2" ] deps += [ "//third_party/iaccessible2" ]
libs = [ "dwrite.lib" ]
} }
if (is_mac) { if (is_mac) {
# These flags are needed to run the test on Mac. # These flags are needed to run the test on Mac.
......
...@@ -350,7 +350,10 @@ component("gfx") { ...@@ -350,7 +350,10 @@ component("gfx") {
cflags = [ "/wd4324" ] # Structure was padded due to __declspec(align()), which is cflags = [ "/wd4324" ] # Structure was padded due to __declspec(align()), which is
# uninteresting. # uninteresting.
libs = [ "setupapi.lib" ] libs = [
"setupapi.lib",
"dwrite.lib",
]
} else { } else {
sources -= [ sources -= [
"gdi_util.cc", "gdi_util.cc",
...@@ -877,6 +880,7 @@ test("gfx_unittests") { ...@@ -877,6 +880,7 @@ test("gfx_unittests") {
libs = [ libs = [
"d2d1.lib", "d2d1.lib",
"d3d10_1.lib", "d3d10_1.lib",
"dwrite.lib",
"imm32.lib", "imm32.lib",
"oleacc.lib", "oleacc.lib",
] ]
......
...@@ -29,8 +29,6 @@ namespace gfx { ...@@ -29,8 +29,6 @@ namespace gfx {
namespace { namespace {
IDWriteFactory* g_factory = nullptr;
// Queries the registry to get a mapping from font filenames to font names. // Queries the registry to get a mapping from font filenames to font names.
void QueryFontsFromRegistry(std::map<std::string, std::string>* map) { void QueryFontsFromRegistry(std::map<std::string, std::string>* map) {
const wchar_t* kFonts = const wchar_t* kFonts =
...@@ -350,11 +348,10 @@ bool GetFallbackFont(const Font& font, ...@@ -350,11 +348,10 @@ bool GetFallbackFont(const Font& font,
// renderer should instead use the font proxy. // renderer should instead use the font proxy.
DCHECK(base::MessageLoopForUI::IsCurrent()); DCHECK(base::MessageLoopForUI::IsCurrent());
if (g_factory == nullptr) { base::win::ScopedComPtr<IDWriteFactory> factory;
gfx::win::CreateDWriteFactory(&g_factory); gfx::win::CreateDWriteFactory(factory.Receive());
}
base::win::ScopedComPtr<IDWriteFactory2> factory2; base::win::ScopedComPtr<IDWriteFactory2> factory2;
g_factory->QueryInterface(factory2.Receive()); factory.QueryInterface(factory2.Receive());
if (!factory2) { if (!factory2) {
// IDWriteFactory2 is not available before Win8.1 // IDWriteFactory2 is not available before Win8.1
return GetUniscribeFallbackFont(font, text, text_length, result); return GetUniscribeFallbackFont(font, text, text_length, result);
......
...@@ -416,6 +416,13 @@ ...@@ -416,6 +416,13 @@
# C4324 is structure was padded due to __declspec(align()), which is # C4324 is structure was padded due to __declspec(align()), which is
# uninteresting. # uninteresting.
'msvs_disabled_warnings': [ 4267, 4324 ], 'msvs_disabled_warnings': [ 4267, 4324 ],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
]
}
}
}], }],
['OS=="mac"', { ['OS=="mac"', {
'link_settings': { 'link_settings': {
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
'AdditionalDependencies': [ 'AdditionalDependencies': [
'd2d1.lib', 'd2d1.lib',
'd3d10_1.lib', 'd3d10_1.lib',
'dwrite.lib',
], ],
}, },
}, },
......
...@@ -18,23 +18,13 @@ namespace gfx { ...@@ -18,23 +18,13 @@ namespace gfx {
namespace win { namespace win {
void CreateDWriteFactory(IDWriteFactory** factory) { void CreateDWriteFactory(IDWriteFactory** factory) {
using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
if (!dwrite_dll)
return;
DWriteCreateFactoryProc dwrite_create_factory_proc =
reinterpret_cast<DWriteCreateFactoryProc>(
GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
// Not finding the DWriteCreateFactory function indicates a corrupt dll.
if (!dwrite_create_factory_proc)
return;
// Failure to create the DirectWrite factory indicates a corrupt dll.
base::win::ScopedComPtr<IUnknown> factory_unknown; base::win::ScopedComPtr<IUnknown> factory_unknown;
if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED, HRESULT hr =
__uuidof(IDWriteFactory), DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
factory_unknown.Receive()))) { factory_unknown.Receive());
if (FAILED(hr)) {
base::debug::Alias(&hr);
CHECK(false);
return; return;
} }
factory_unknown.QueryInterface<IDWriteFactory>(factory); factory_unknown.QueryInterface<IDWriteFactory>(factory);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment