diff options
author | Giuseppe Gorgoglione <gorgogsp@gmail.com> | 2016-05-28 04:14:15 +0200 |
---|---|---|
committer | Giuseppe Gorgoglione <gorgogsp@gmail.com> | 2016-06-11 20:14:09 +0200 |
commit | 58dc78b6eba373d88fe7ef68f9ce3c2c43e635d6 (patch) | |
tree | 90af8c2c2323070c2c336153de8376d83a3f1f44 /src/osd/modules/font/font_dwrite.cpp | |
parent | ea1b66f146e4c6663e06b124f8665f878c43ce0c (diff) |
Introduce dynamic_module
This is a central cross-platform facility to dynamically bind functions from shared libraries.
Updated all OSD modules to use it.
Diffstat (limited to 'src/osd/modules/font/font_dwrite.cpp')
-rw-r--r-- | src/osd/modules/font/font_dwrite.cpp | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/src/osd/modules/font/font_dwrite.cpp b/src/osd/modules/font/font_dwrite.cpp index f119be4523d..e816f296294 100644 --- a/src/osd/modules/font/font_dwrite.cpp +++ b/src/osd/modules/font/font_dwrite.cpp @@ -7,6 +7,7 @@ #include "font_module.h" #include "modules/osdmodule.h" +#include "modules/lib/osdlib.h" // We take dependencies on WRL client headers and // we can only build with a high enough version @@ -78,8 +79,8 @@ struct osd_deleter typedef std::unique_ptr<char, osd_deleter> osd_utf8_ptr; // Typedefs for dynamically loaded functions -typedef lazy_loaded_function_p4<HRESULT, D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS*, void**> d2d_create_factory_fn; -typedef lazy_loaded_function_p3<HRESULT, DWRITE_FACTORY_TYPE, REFIID, IUnknown**> dwrite_create_factory_fn; +typedef HRESULT WINAPI (*d2d_create_factory_fn)(D2D1_FACTORY_TYPE, REFIID, const D2D1_FACTORY_OPTIONS *, void **); +typedef HRESULT (*dwrite_create_factory_fn)(DWRITE_FACTORY_TYPE, REFIID, IUnknown **); // Debugging functions #ifdef DWRITE_DEBUGGING @@ -96,13 +97,17 @@ HRESULT SaveBitmap(IWICBitmap* bitmap, GUID pixelFormat, const WCHAR *filename) ComPtr<IDWriteFactory> dwriteFactory; ComPtr<IWICImagingFactory> wicFactory; - d2d_create_factory_fn pfn_D2D1CreateFactory("D2D1CreateFactory", L"D2d1.dll"); - dwrite_create_factory_fn pfn_DWriteCreateFactory("DWriteCreateFactory", L"Dwrite.dll"); - HR_RETHR(pfn_D2D1CreateFactory.initialize()); - HR_RETHR(pfn_DWriteCreateFactory.initialize()); + osd::dynamic_module::ptr d2d1_dll = osd::dynamic_module::open({ "d2d1.dll" }); + osd::dynamic_module::ptr dwrite_dll = osd::dynamic_module::open({ "dwrite.dll" }); + + d2d_create_factory_fn pfn_D2D1CreateFactory = d2d1_dll->bind<d2d_create_factory_fn>("D2D1CreateFactory"); + dwrite_create_factory_fn pfn_DWriteCreateFactory = dwrite_dll->bind<dwrite_create_factory_fn>("DWriteCreateFactory"); + + if (!pfn_D2D1CreateFactory || !pfn_DWriteCreateFactory) + return ERROR_DLL_NOT_FOUND; // Create a Direct2D factory - HR_RETHR(pfn_D2D1CreateFactory( + HR_RETHR((*pfn_D2D1CreateFactory)( D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory1), nullptr, @@ -112,7 +117,7 @@ HRESULT SaveBitmap(IWICBitmap* bitmap, GUID pixelFormat, const WCHAR *filename) CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); // Create a DirectWrite factory. - HR_RETHR(pfn_DWriteCreateFactory( + HR_RETHR((*pfn_DWriteCreateFactory)( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown **>(dwriteFactory.GetAddressOf()))); @@ -652,18 +657,18 @@ private: class font_dwrite : public osd_module, public font_module { private: - d2d_create_factory_fn m_pfnD2D1CreateFactory; - dwrite_create_factory_fn m_pfnDWriteCreateFactory; - ComPtr<ID2D1Factory> m_d2dfactory; - ComPtr<IDWriteFactory> m_dwriteFactory; - ComPtr<IWICImagingFactory> m_wicFactory; + osd::dynamic_module::ptr m_d2d1_dll; + osd::dynamic_module::ptr m_dwrite_dll; + d2d_create_factory_fn m_pfnD2D1CreateFactory; + dwrite_create_factory_fn m_pfnDWriteCreateFactory; + ComPtr<ID2D1Factory> m_d2dfactory; + ComPtr<IDWriteFactory> m_dwriteFactory; + ComPtr<IWICImagingFactory> m_wicFactory; public: font_dwrite() : osd_module(OSD_FONT_PROVIDER, "dwrite"), font_module(), - m_pfnD2D1CreateFactory("D2D1CreateFactory", L"D2d1.dll"), - m_pfnDWriteCreateFactory("DWriteCreateFactory", L"Dwrite.dll"), m_d2dfactory(nullptr), m_dwriteFactory(nullptr), m_wicFactory(nullptr) @@ -672,12 +677,15 @@ 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.initialize() != 0 - || m_pfnDWriteCreateFactory.initialize() != 0) - { + if (!m_pfnD2D1CreateFactory || !m_pfnDWriteCreateFactory) return false; - } return true; } @@ -689,15 +697,14 @@ public: osd_printf_verbose("FontProvider: Initializing DirectWrite\n"); // Make sure we can initialize our api functions - if (m_pfnD2D1CreateFactory.initialize() - || m_pfnDWriteCreateFactory.initialize()) + if (!m_pfnD2D1CreateFactory || !m_pfnDWriteCreateFactory) { osd_printf_error("ERROR: FontProvider: Failed to load DirectWrite functions.\n"); return -1; } // Create a Direct2D factory. - HR_RET1(m_pfnD2D1CreateFactory( + HR_RET1((*m_pfnD2D1CreateFactory)( D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), nullptr, @@ -707,7 +714,7 @@ public: CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); // Create a DirectWrite factory. - HR_RET1(m_pfnDWriteCreateFactory( + HR_RET1((*m_pfnDWriteCreateFactory)( DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory), reinterpret_cast<IUnknown **>(m_dwriteFactory.GetAddressOf()))); |