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") {
deps += [ "//third_party/android_tools:cpu_features" ]
}
if (is_win) {
libs = [ "dwrite.lib" ]
}
if (enable_plugins) {
deps += [
"//ppapi/proxy",
......
......@@ -31,31 +31,11 @@ IPC::Sender* g_sender_override = nullptr;
// Windows-only DirectWrite support. These warm up the DirectWrite paths
// before sandbox lock down to allow Skia access to the Font Manager service.
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
// content_browsertests, and possibly other high-stress cases.
PatchServiceManagerCalls();
DWriteCreateFactoryProc dwrite_create_factory_proc =
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(
CHECK(SUCCEEDED(DWriteCreateFactory(
DWRITE_FACTORY_TYPE_ISOLATED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(factory))));
}
......
......@@ -24,27 +24,9 @@ namespace content {
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 {
public:
DWriteFontProxyUnitTest() {
if (!factory)
return;
fake_collection_ = new FakeFontCollection();
SetupFonts(fake_collection_.get());
mswr::MakeAndInitialize<DWriteFontCollectionProxy>(
......@@ -71,7 +53,8 @@ class DWriteFontProxyUnitTest : public testing::Test {
}
static void SetUpTestCase() {
CreateDWriteFactory(&factory);
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
&factory);
std::vector<base::char16> font_path;
font_path.resize(MAX_PATH);
......@@ -96,9 +79,6 @@ std::vector<base::string16> DWriteFontProxyUnitTest::arial_font_files;
mswr::ComPtr<IDWriteFactory> DWriteFontProxyUnitTest::factory;
TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) {
if (!factory)
return;
UINT32 family_count = collection_->GetFontFamilyCount();
EXPECT_EQ(3u, family_count);
......@@ -114,8 +94,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontFamilyCount) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -133,8 +111,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldFindFamily) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -150,8 +126,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldReturnUINTMAXWhenNotFound) {
TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -167,8 +141,6 @@ TEST_F(DWriteFontProxyUnitTest, FindFamilyNameShouldNotSendDuplicateIPC) {
TEST_F(DWriteFontProxyUnitTest, GetFontFamilyShouldCreateFamily) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -214,8 +186,6 @@ void CheckLocale(const base::string16& locale_name,
TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -253,8 +223,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNames) {
TEST_F(DWriteFontProxyUnitTest, GetFontCollection) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -275,8 +243,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFontCollection) {
TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -295,8 +261,6 @@ TEST_F(DWriteFontProxyUnitTest, GetFamilyNamesShouldNotIPCAfterLoadingFamily) {
TEST_F(DWriteFontProxyUnitTest,
GetFontFamilyShouldNotCreateFamilyWhenIndexIsInvalid) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -312,8 +276,6 @@ TEST_F(DWriteFontProxyUnitTest,
TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......@@ -348,8 +310,6 @@ TEST_F(DWriteFontProxyUnitTest, LoadingFontFamily) {
TEST_F(DWriteFontProxyUnitTest, GetFontFromFontFaceShouldFindFont) {
HRESULT hr;
if (!factory)
return;
UINT32 index = UINT_MAX;
BOOL exists = FALSE;
......
......@@ -25,7 +25,8 @@ namespace {
class FontFallbackUnitTest : public testing::Test {
public:
FontFallbackUnitTest() {
CreateDWriteFactory(&factory_);
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory), &factory_);
factory_->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE,
L"en-us", true /* ignoreUserOverride */,
......@@ -47,22 +48,6 @@ class FontFallbackUnitTest : public testing::Test {
&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_;
mswr::ComPtr<IDWriteFactory> factory_;
mswr::ComPtr<DWriteFontCollectionProxy> collection_;
......
......@@ -254,6 +254,15 @@
'../build/android/ndk.gyp:cpu_features',
],
}],
['OS=="win"', {
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
]
}
}
}],
['enable_plugins==0', {
'sources!': [
'child/browser_font_resource_trusted.cc',
......
......@@ -1152,6 +1152,13 @@
'dependencies': [
'../third_party/iaccessible2/iaccessible2.gyp:iaccessible2',
],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
],
},
},
}],
['OS=="mac"', {
# These flags are needed to run the test on Mac.
......
......@@ -792,6 +792,7 @@ test("content_unittests") {
}
if (is_win) {
deps += [ "//third_party/iaccessible2" ]
libs = [ "dwrite.lib" ]
}
if (is_mac) {
# These flags are needed to run the test on Mac.
......
......@@ -350,7 +350,10 @@ component("gfx") {
cflags = [ "/wd4324" ] # Structure was padded due to __declspec(align()), which is
# uninteresting.
libs = [ "setupapi.lib" ]
libs = [
"setupapi.lib",
"dwrite.lib",
]
} else {
sources -= [
"gdi_util.cc",
......@@ -877,6 +880,7 @@ test("gfx_unittests") {
libs = [
"d2d1.lib",
"d3d10_1.lib",
"dwrite.lib",
"imm32.lib",
"oleacc.lib",
]
......
......@@ -29,8 +29,6 @@ namespace gfx {
namespace {
IDWriteFactory* g_factory = nullptr;
// Queries the registry to get a mapping from font filenames to font names.
void QueryFontsFromRegistry(std::map<std::string, std::string>* map) {
const wchar_t* kFonts =
......@@ -350,11 +348,10 @@ bool GetFallbackFont(const Font& font,
// renderer should instead use the font proxy.
DCHECK(base::MessageLoopForUI::IsCurrent());
if (g_factory == nullptr) {
gfx::win::CreateDWriteFactory(&g_factory);
}
base::win::ScopedComPtr<IDWriteFactory> factory;
gfx::win::CreateDWriteFactory(factory.Receive());
base::win::ScopedComPtr<IDWriteFactory2> factory2;
g_factory->QueryInterface(factory2.Receive());
factory.QueryInterface(factory2.Receive());
if (!factory2) {
// IDWriteFactory2 is not available before Win8.1
return GetUniscribeFallbackFont(font, text, text_length, result);
......
......@@ -416,6 +416,13 @@
# C4324 is structure was padded due to __declspec(align()), which is
# uninteresting.
'msvs_disabled_warnings': [ 4267, 4324 ],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalDependencies': [
'dwrite.lib',
]
}
}
}],
['OS=="mac"', {
'link_settings': {
......
......@@ -146,6 +146,7 @@
'AdditionalDependencies': [
'd2d1.lib',
'd3d10_1.lib',
'dwrite.lib',
],
},
},
......
......@@ -18,23 +18,13 @@ namespace gfx {
namespace win {
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;
if (FAILED(dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
factory_unknown.Receive()))) {
HRESULT hr =
DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
factory_unknown.Receive());
if (FAILED(hr)) {
base::debug::Alias(&hr);
CHECK(false);
return;
}
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