[vlc-devel] [PATCH v2] freetype: link directly to dwrite in win32

Steve Lhomme robux4 at ycbcr.xyz
Wed Jun 10 14:20:51 CEST 2020


On 2020-06-10 14:12, Jean-Baptiste Kempf wrote:
> OK.
> 
> remember that DWrite2 is 8.1+

The only "hard" call is DWriteCreateFactory() to create a 
IDWriteFactory2. On Win7/Win8 it will fail and we will not use this part 
of the code. This doesn't change whether we call DWriteCreateFactory 
directly or via GetProcAddress.

> Best,
> 
> On Wed, Jun 10, 2020, at 14:01, Steve Lhomme wrote:
>> Since we target Windows 7 we know the DLL is always there.
>>
>> That's how the Winstore mode was already working.
>> ---
>>   modules/text_renderer/Makefile.am             |  5 +--
>>   .../text_renderer/freetype/fonts/dwrite.cpp   | 41 +------------------
>>   2 files changed, 4 insertions(+), 42 deletions(-)
>>
>> diff --git a/modules/text_renderer/Makefile.am
>> b/modules/text_renderer/Makefile.am
>> index d3cdf754aaaa..56cc82a1ab05 100644
>> --- a/modules/text_renderer/Makefile.am
>> +++ b/modules/text_renderer/Makefile.am
>> @@ -14,12 +14,11 @@ libfreetype_plugin_la_LDFLAGS = $(FREETYPE_LDFLAGS)
>> -rpath '$(textdir)'
>>   
>>   if HAVE_WIN32
>>   libfreetype_plugin_la_SOURCES +=
>> text_renderer/freetype/fonts/dwrite.cpp
>> +libfreetype_plugin_la_LIBADD += -ldwrite -luuid
>>   libfreetype_plugin_la_LINK = $(CXXLINK)
>>   if HAVE_WIN32_DESKTOP
>>   libfreetype_plugin_la_SOURCES += text_renderer/freetype/fonts/win32.c
>> -libfreetype_plugin_la_LIBADD += -liconv -lz -lusp10 -lgdi32 -luuid
>> -else
>> -libfreetype_plugin_la_LIBADD += -ldwrite -luuid
>> +libfreetype_plugin_la_LIBADD += -liconv -lz -lusp10 -lgdi32
>>   endif
>>   else
>>   libfreetype_plugin_la_LINK = $(LINK)
>> diff --git a/modules/text_renderer/freetype/fonts/dwrite.cpp
>> b/modules/text_renderer/freetype/fonts/dwrite.cpp
>> index 943c60f3a257..8a5f8392674e 100644
>> --- a/modules/text_renderer/freetype/fonts/dwrite.cpp
>> +++ b/modules/text_renderer/freetype/fonts/dwrite.cpp
>> @@ -46,31 +46,18 @@ typedef HRESULT ( WINAPI *DWriteCreateFactoryProc )
>> (
>>   
>>   struct dw_sys_t
>>   {
>> -    HMODULE                                  p_dw_dll;
>>       ComPtr< IDWriteFactory2 >                p_dw_factory;
>>       ComPtr< IDWriteFontCollection >          p_dw_system_fonts;
>>       ComPtr< IDWriteNumberSubstitution >      p_dw_substitution;
>>       ComPtr< IDWriteFontFallback >            p_dw_fallbacks;
>>       vector< FT_Stream >                      streams;
>>   
>> -    dw_sys_t( HMODULE p_dw_dll ) : p_dw_dll( p_dw_dll )
>> +    dw_sys_t( )
>>       {
>>           /* This will fail on versions of Windows prior to 8.1 */
>> -#if VLC_WINSTORE_APP
>>           if( DWriteCreateFactory( DWRITE_FACTORY_TYPE_SHARED, __uuidof(
>> IDWriteFactory2 ),
>>                   reinterpret_cast<IUnknown **>(
>> p_dw_factory.GetAddressOf() ) ) )
>>               throw runtime_error( "failed to create DWrite factory" );
>> -#else
>> -        DWriteCreateFactoryProc pf =
>> -                ( DWriteCreateFactoryProc ) GetProcAddress( p_dw_dll,
>> "DWriteCreateFactory" );
>> -
>> -        if( pf == NULL )
>> -            throw runtime_error( "GetProcAddress() failed" );
>> -
>> -        if( pf( DWRITE_FACTORY_TYPE_SHARED, __uuidof( IDWriteFactory2
>> ),
>> -                reinterpret_cast<IUnknown **>(
>> p_dw_factory.GetAddressOf() ) ) )
>> -            throw runtime_error( "failed to create DWrite factory" );
>> -#endif
>>   
>>           if( p_dw_factory->GetSystemFontCollection(
>> p_dw_system_fonts.GetAddressOf() ) )
>>               throw runtime_error( "GetSystemFontCollection() failed" );
>> @@ -106,29 +93,14 @@ static inline void AppendFamily( vlc_family_t
>> **pp_list, vlc_family_t *p_family
>>   extern "C" int InitDWrite( filter_t *p_filter )
>>   {
>>       dw_sys_t *p_dw_sys;
>> -    HMODULE p_dw_dll = NULL;
>>   
>>       try
>>       {
>> -#if VLC_WINSTORE_APP
>> -        p_dw_sys = new dw_sys_t( p_dw_dll );
>> -#else
>> -        p_dw_dll = LoadLibrary( TEXT( "Dwrite.dll" ) );
>> -        if( p_dw_dll == NULL )
>> -            return VLC_EGENERIC;
>> -
>> -        p_dw_sys = new dw_sys_t( p_dw_dll );
>> -#endif
>> +        p_dw_sys = new dw_sys_t( );
>>       }
>>       catch( const exception &e )
>>       {
>> -#if !VLC_WINSTORE_APP
>> -        FreeLibrary( p_dw_dll );
>> -        (void)e;
>> -#else
>>           msg_Err( p_filter, "InitDWrite(): %s", e.what() );
>> -#endif
>> -
>>           return VLC_EGENERIC;
>>       }
>>   
>> @@ -143,16 +115,7 @@ extern "C" int ReleaseDWrite( filter_t *p_filter )
>>       filter_sys_t *p_sys = reinterpret_cast<filter_sys_t *>( p_filter->p_sys );
>>       dw_sys_t *p_dw_sys = ( dw_sys_t * ) p_sys->p_dw_sys;
>>   
>> -#if VLC_WINSTORE_APP
>>       delete p_dw_sys;
>> -#else
>> -    HMODULE p_dw_dll = NULL;
>> -    if( p_dw_sys && p_dw_sys->p_dw_dll )
>> -        p_dw_dll = p_dw_sys->p_dw_dll;
>> -
>> -    delete p_dw_sys;
>> -    if( p_dw_dll ) FreeLibrary( p_dw_dll );
>> -#endif
>>   
>>       return VLC_SUCCESS;
>>   }
>> -- 
>> 2.26.2
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
> 
> -- 
> Jean-Baptiste Kempf -  President
> +33 672 704 734
> 


More information about the vlc-devel mailing list