mirror of
https://github.com/holub/mame
synced 2025-05-19 20:29:09 +03:00
Update DirectWrite font provider to use DYNAMIC_API (nw)
This commit is contained in:
parent
17c9b0b784
commit
78a30a25b0
@ -66,10 +66,18 @@ static const float POINTS_PER_DIP = (3.0f / 4.0f);
|
|||||||
#define HR_RET0( CALL ) HR_RET(CALL, 0)
|
#define HR_RET0( CALL ) HR_RET(CALL, 0)
|
||||||
#define HR_RET1( CALL ) HR_RET(CALL, 1)
|
#define HR_RET1( CALL ) HR_RET(CALL, 1)
|
||||||
|
|
||||||
// Typedefs for dynamically loaded functions
|
// Dynamic APIs
|
||||||
typedef HRESULT (WINAPI *d2d_create_factory_fn)(D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS *, void **);
|
DYNAMIC_API_BEGIN(d2d1, "d2d1.dll")
|
||||||
typedef HRESULT (WINAPI *dwrite_create_factory_fn)(DWRITE_FACTORY_TYPE, REFIID, IUnknown **);
|
DYNAMIC_API_FN(HRESULT, WINAPI, D2D1CreateFactory, D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS *, void **)
|
||||||
typedef int (WINAPI *get_user_default_locale_name)(LPWSTR, int);
|
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
|
// Debugging functions
|
||||||
#ifdef DWRITE_DEBUGGING
|
#ifdef DWRITE_DEBUGGING
|
||||||
@ -653,12 +661,6 @@ private:
|
|||||||
class font_dwrite : public osd_module, public font_module
|
class font_dwrite : public osd_module, public font_module
|
||||||
{
|
{
|
||||||
private:
|
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<ID2D1Factory> m_d2dfactory;
|
||||||
ComPtr<IDWriteFactory> m_dwriteFactory;
|
ComPtr<IDWriteFactory> m_dwriteFactory;
|
||||||
ComPtr<IWICImagingFactory> m_wicFactory;
|
ComPtr<IWICImagingFactory> m_wicFactory;
|
||||||
@ -667,9 +669,6 @@ public:
|
|||||||
font_dwrite() :
|
font_dwrite() :
|
||||||
osd_module(OSD_FONT_PROVIDER, "dwrite"),
|
osd_module(OSD_FONT_PROVIDER, "dwrite"),
|
||||||
font_module(),
|
font_module(),
|
||||||
m_pfnD2D1CreateFactory(nullptr),
|
|
||||||
m_pfnDWriteCreateFactory(nullptr),
|
|
||||||
m_pfnGetUserDefaultLocaleName(nullptr),
|
|
||||||
m_d2dfactory(nullptr),
|
m_d2dfactory(nullptr),
|
||||||
m_dwriteFactory(nullptr),
|
m_dwriteFactory(nullptr),
|
||||||
m_wicFactory(nullptr)
|
m_wicFactory(nullptr)
|
||||||
@ -678,14 +677,8 @@ public:
|
|||||||
|
|
||||||
virtual bool probe() override
|
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
|
// 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 false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -698,21 +691,16 @@ public:
|
|||||||
osd_printf_verbose("FontProvider: Initializing DirectWrite\n");
|
osd_printf_verbose("FontProvider: Initializing DirectWrite\n");
|
||||||
|
|
||||||
// Make sure we can initialize our api functions
|
// 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");
|
osd_printf_error("ERROR: FontProvider: Failed to load DirectWrite functions.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init our kernel32 dynamic functions
|
assert(DYNAMIC_API_TEST(locale, GetUserDefaultLocaleName));
|
||||||
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");
|
|
||||||
|
|
||||||
// Create a Direct2D factory.
|
// Create a Direct2D factory.
|
||||||
HR_RET1((*m_pfnD2D1CreateFactory)(
|
HR_RET1(DYNAMIC_CALL(d2d1, D2D1CreateFactory,
|
||||||
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
D2D1_FACTORY_TYPE_SINGLE_THREADED,
|
||||||
__uuidof(ID2D1Factory),
|
__uuidof(ID2D1Factory),
|
||||||
nullptr,
|
nullptr,
|
||||||
@ -722,7 +710,7 @@ public:
|
|||||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||||
|
|
||||||
// Create a DirectWrite factory.
|
// Create a DirectWrite factory.
|
||||||
HR_RET1((*m_pfnDWriteCreateFactory)(
|
HR_RET1(DYNAMIC_CALL(dwrite, DWriteCreateFactory,
|
||||||
DWRITE_FACTORY_TYPE_SHARED,
|
DWRITE_FACTORY_TYPE_SHARED,
|
||||||
__uuidof(IDWriteFactory),
|
__uuidof(IDWriteFactory),
|
||||||
reinterpret_cast<IUnknown **>(m_dwriteFactory.GetAddressOf())));
|
reinterpret_cast<IUnknown **>(m_dwriteFactory.GetAddressOf())));
|
||||||
@ -811,10 +799,10 @@ private:
|
|||||||
|
|
||||||
// Get the default locale for this user if possible.
|
// Get the default locale for this user if possible.
|
||||||
// GetUserDefaultLocaleName doesn't exist on XP, so don't assume.
|
// 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];
|
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)
|
if (len != 0)
|
||||||
locale_name = name_buffer;
|
locale_name = name_buffer;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user