summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/font/font_dwrite.cpp
diff options
context:
space:
mode:
author Brad Hughes <bradhugh@outlook.com>2016-11-18 14:38:35 -0500
committer Brad Hughes <bradhugh@outlook.com>2016-11-20 13:41:45 -0500
commit78a30a25b076c43a0ed855d55e67eb806dcb64ed (patch)
treed4be2e640ec96600153e27ee360083aa7ff70e33 /src/osd/modules/font/font_dwrite.cpp
parent17c9b0b7847e71ac49b756e6a0cfc0841ce52ac0 (diff)
Update DirectWrite font provider to use DYNAMIC_API (nw)
Diffstat (limited to 'src/osd/modules/font/font_dwrite.cpp')
-rw-r--r--src/osd/modules/font/font_dwrite.cpp50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/osd/modules/font/font_dwrite.cpp b/src/osd/modules/font/font_dwrite.cpp
index 884f2bed5f3..d028c345392 100644
--- a/src/osd/modules/font/font_dwrite.cpp
+++ b/src/osd/modules/font/font_dwrite.cpp
@@ -66,10 +66,18 @@ static const float POINTS_PER_DIP = (3.0f / 4.0f);
#define HR_RET0( CALL ) HR_RET(CALL, 0)
#define HR_RET1( CALL ) HR_RET(CALL, 1)
-// Typedefs for dynamically loaded functions
-typedef HRESULT (WINAPI *d2d_create_factory_fn)(D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS *, void **);
-typedef HRESULT (WINAPI *dwrite_create_factory_fn)(DWRITE_FACTORY_TYPE, REFIID, IUnknown **);
-typedef int (WINAPI *get_user_default_locale_name)(LPWSTR, int);
+// Dynamic APIs
+DYNAMIC_API_BEGIN(d2d1, "d2d1.dll")
+ DYNAMIC_API_FN(HRESULT, WINAPI, D2D1CreateFactory, D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS *, void **)
+DYNAMIC_API_END()
+
+DYNAMIC_API_BEGIN(dwrite, "dwrite.dll")
+ DYNAMIC_API_FN(HRESULT, WINAPI, DWriteCreateFactory, DWRITE_FACTORY_TYPE, REFIID, IUnknown **)
+DYNAMIC_API_END()
+
+DYNAMIC_API_BEGIN(locale, "kernel32.dll")
+ DYNAMIC_API_FN(int, WINAPI, GetUserDefaultLocaleName, LPWSTR, int)
+DYNAMIC_API_END()
// Debugging functions
#ifdef DWRITE_DEBUGGING
@@ -653,12 +661,6 @@ private:
class font_dwrite : public osd_module, public font_module
{
private:
- osd::dynamic_module::ptr m_d2d1_dll;
- osd::dynamic_module::ptr m_dwrite_dll;
- osd::dynamic_module::ptr m_kernel32_dll;
- d2d_create_factory_fn m_pfnD2D1CreateFactory;
- dwrite_create_factory_fn m_pfnDWriteCreateFactory;
- get_user_default_locale_name m_pfnGetUserDefaultLocaleName;
ComPtr<ID2D1Factory> m_d2dfactory;
ComPtr<IDWriteFactory> m_dwriteFactory;
ComPtr<IWICImagingFactory> m_wicFactory;
@@ -667,9 +669,6 @@ public:
font_dwrite() :
osd_module(OSD_FONT_PROVIDER, "dwrite"),
font_module(),
- m_pfnD2D1CreateFactory(nullptr),
- m_pfnDWriteCreateFactory(nullptr),
- m_pfnGetUserDefaultLocaleName(nullptr),
m_d2dfactory(nullptr),
m_dwriteFactory(nullptr),
m_wicFactory(nullptr)
@@ -678,14 +677,8 @@ public:
virtual bool probe() override
{
- m_d2d1_dll = osd::dynamic_module::open({ "d2d1.dll" });
- m_dwrite_dll = osd::dynamic_module::open({ "dwrite.dll" });
-
- m_pfnD2D1CreateFactory = m_d2d1_dll->bind<d2d_create_factory_fn>("D2D1CreateFactory");
- m_pfnDWriteCreateFactory = m_dwrite_dll->bind<dwrite_create_factory_fn>("DWriteCreateFactory");
-
// This module is available if it can load the expected API Functions
- if (!m_pfnD2D1CreateFactory || !m_pfnDWriteCreateFactory)
+ if (!DYNAMIC_API_TEST(d2d1, D2D1CreateFactory) || !DYNAMIC_API_TEST(dwrite, DWriteCreateFactory))
return false;
return true;
@@ -698,21 +691,16 @@ public:
osd_printf_verbose("FontProvider: Initializing DirectWrite\n");
// Make sure we can initialize our api functions
- if (!m_pfnD2D1CreateFactory || !m_pfnDWriteCreateFactory)
+ if (!DYNAMIC_API_TEST(d2d1, D2D1CreateFactory) || !DYNAMIC_API_TEST(dwrite, DWriteCreateFactory))
{
osd_printf_error("ERROR: FontProvider: Failed to load DirectWrite functions.\n");
return -1;
}
- // Init our kernel32 dynamic functions
- m_kernel32_dll = osd::dynamic_module::open({ "Kernel32.dll" });
- assert(m_kernel32_dll != nullptr);
-
- // Attempt to map this function. It only exists on Vista+, so we don't fail if it can't be mapped
- m_pfnGetUserDefaultLocaleName = m_kernel32_dll->bind<get_user_default_locale_name>("GetUserDefaultLocaleName");
+ assert(DYNAMIC_API_TEST(locale, GetUserDefaultLocaleName));
// Create a Direct2D factory.
- HR_RET1((*m_pfnD2D1CreateFactory)(
+ HR_RET1(DYNAMIC_CALL(d2d1, D2D1CreateFactory,
D2D1_FACTORY_TYPE_SINGLE_THREADED,
__uuidof(ID2D1Factory),
nullptr,
@@ -722,7 +710,7 @@ public:
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
// Create a DirectWrite factory.
- HR_RET1((*m_pfnDWriteCreateFactory)(
+ HR_RET1(DYNAMIC_CALL(dwrite, DWriteCreateFactory,
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown **>(m_dwriteFactory.GetAddressOf())));
@@ -811,10 +799,10 @@ private:
// Get the default locale for this user if possible.
// GetUserDefaultLocaleName doesn't exist on XP, so don't assume.
- if (m_pfnGetUserDefaultLocaleName)
+ if (DYNAMIC_API_TEST(locale, GetUserDefaultLocaleName))
{
wchar_t name_buffer[LOCALE_NAME_MAX_LENGTH];
- int len = m_pfnGetUserDefaultLocaleName(name_buffer, LOCALE_NAME_MAX_LENGTH);
+ int len = DYNAMIC_CALL(locale, GetUserDefaultLocaleName, name_buffer, LOCALE_NAME_MAX_LENGTH);
if (len != 0)
locale_name = name_buffer;
}