Code review feedback

This commit is contained in:
Chuck Walbourn 2016-09-01 16:54:42 -07:00
parent 25dbe0e547
commit 0bbee8c588
5 changed files with 67 additions and 106 deletions

View File

@ -229,31 +229,33 @@ REFGUID GetWICCodec( WICCodecs codec )
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
// Singleton function for WIC factory // Singleton function for WIC factory
//------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------
IWICImagingFactory* GetWICFactory(bool& iswic2) IWICImagingFactory* GetWICFactory( bool& iswic2 )
{ {
if (g_Factory) if ( g_Factory )
{ {
iswic2 = g_WIC2; iswic2 = g_WIC2;
return g_Factory; return g_Factory;
} }
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL [](PINIT_ONCE, PVOID, PVOID *factory) -> BOOL
{ {
#if(_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance( HRESULT hr = CoCreateInstance(
CLSID_WICImagingFactory2, CLSID_WICImagingFactory2,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2), __uuidof(IWICImagingFactory2),
(LPVOID*)&g_Factory factory
); );
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
// WIC2 is available on Windows 8 and Windows 7 SP1 with KB 2670838 installed // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true; g_WIC2 = true;
return TRUE;
} }
else else
{ {
@ -263,33 +265,22 @@ IWICImagingFactory* GetWICFactory(bool& iswic2)
CLSID_WICImagingFactory1, CLSID_WICImagingFactory1,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory) __uuidof(IWICImagingFactory),
); factory
);
if (FAILED(hr)) return SUCCEEDED(hr) ? TRUE : FALSE;
{
g_Factory = nullptr;
return FALSE;
}
} }
#else #else
HRESULT hr = CoCreateInstance( g_WIC2 = false;
return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory, CLSID_WICImagingFactory,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&g_Factory) __uuidof(IWICImagingFactory),
); factory) ) ? TRUE : FALSE;
#endif
g_WIC2 = false; }, nullptr, reinterpret_cast<LPVOID*>(&g_Factory) );
if (FAILED(hr))
{
g_Factory = nullptr;
return FALSE;
}
#endif
return TRUE;
}, nullptr, nullptr);
iswic2 = g_WIC2; iswic2 = g_WIC2;
return g_Factory; return g_Factory;

View File

@ -701,15 +701,15 @@ namespace
IWICImagingFactory* _GetWIC() IWICImagingFactory* _GetWIC()
{ {
static IWICImagingFactory* s_Factory = nullptr; static ComPtr<IWICImagingFactory> s_Factory;
if ( s_Factory ) if ( s_Factory )
return s_Factory; return s_Factory.Get();
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL [](PINIT_ONCE, PVOID, PVOID *factory) -> BOOL
{ {
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance( HRESULT hr = CoCreateInstance(
@ -717,13 +717,14 @@ namespace
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2), __uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory factory
); );
if ( SUCCEEDED(hr) ) if ( SUCCEEDED(hr) )
{ {
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true; g_WIC2 = true;
return TRUE;
} }
else else
{ {
@ -731,33 +732,22 @@ namespace
CLSID_WICImagingFactory1, CLSID_WICImagingFactory1,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory) __uuidof(IWICImagingFactory),
factory
); );
return SUCCEEDED(hr) ? TRUE : FALSE;
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
} }
#else #else
HRESULT hr = CoCreateInstance( return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory, CLSID_WICImagingFactory,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory) __uuidof(IWICImagingFactory),
); factory) ) ? TRUE : FALSE;
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
#endif #endif
return TRUE; }, nullptr, reinterpret_cast<LPVOID*>(s_Factory.GetAddressOf()));
}, nullptr, nullptr);
return s_Factory; return s_Factory.Get();
} }
} // anonymous namespace } // anonymous namespace

View File

@ -781,30 +781,25 @@ namespace
IWICImagingFactory2* _GetWIC() IWICImagingFactory2* _GetWIC()
{ {
static IWICImagingFactory2* s_Factory = nullptr; static ComPtr<IWICImagingFactory2> s_Factory;
if (s_Factory) if ( s_Factory )
return s_Factory; return s_Factory.Get();
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, (void)InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL [](PINIT_ONCE, PVOID, PVOID *factory) -> BOOL
{ {
HRESULT hr = CoCreateInstance( return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory2, CLSID_WICImagingFactory2,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)); __uuidof(IWICImagingFactory2),
if (FAILED(hr)) factory) ) ? TRUE : FALSE;
{ }, nullptr, reinterpret_cast<LPVOID*>(s_Factory.GetAddressOf()));
s_Factory = nullptr;
return FALSE;
}
return TRUE;
}, nullptr, nullptr);
return s_Factory; return s_Factory.Get();
} }
} // anonymous namespace } // anonymous namespace

View File

@ -168,15 +168,15 @@ namespace
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
IWICImagingFactory* _GetWIC() IWICImagingFactory* _GetWIC()
{ {
static IWICImagingFactory* s_Factory = nullptr; static ComPtr<IWICImagingFactory> s_Factory;
if ( s_Factory ) if ( s_Factory )
return s_Factory; return s_Factory.Get();
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL [](PINIT_ONCE, PVOID, PVOID *factory) -> BOOL
{ {
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE) #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8) || defined(_WIN7_PLATFORM_UPDATE)
HRESULT hr = CoCreateInstance( HRESULT hr = CoCreateInstance(
@ -184,13 +184,14 @@ namespace
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
__uuidof(IWICImagingFactory2), __uuidof(IWICImagingFactory2),
(LPVOID*)&s_Factory factory
); );
if ( SUCCEEDED(hr) ) if ( SUCCEEDED(hr) )
{ {
// WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed // WIC2 is available on Windows 10, Windows 8.x, and Windows 7 SP1 with KB 2670838 installed
g_WIC2 = true; g_WIC2 = true;
return TRUE;
} }
else else
{ {
@ -198,33 +199,22 @@ namespace
CLSID_WICImagingFactory1, CLSID_WICImagingFactory1,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory) __uuidof(IWICImagingFactory),
factory
); );
return SUCCEEDED(hr) ? TRUE : FALSE;
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
} }
#else #else
HRESULT hr = CoCreateInstance( return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory, CLSID_WICImagingFactory,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory) __uuidof(IWICImagingFactory),
); factory) ) ? TRUE : FALSE;
if ( FAILED(hr) )
{
s_Factory = nullptr;
return FALSE;
}
#endif #endif
return TRUE; }, nullptr, reinterpret_cast<LPVOID*>(s_Factory.GetAddressOf()));
}, nullptr, nullptr);
return s_Factory; return s_Factory.Get();
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------

View File

@ -149,30 +149,25 @@ namespace
IWICImagingFactory2* _GetWIC() IWICImagingFactory2* _GetWIC()
{ {
static IWICImagingFactory2* s_Factory = nullptr; static ComPtr<IWICImagingFactory2> s_Factory;
if (s_Factory) if ( s_Factory )
return s_Factory; return s_Factory.Get();
static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT; static INIT_ONCE s_initOnce = INIT_ONCE_STATIC_INIT;
InitOnceExecuteOnce(&s_initOnce, (void)InitOnceExecuteOnce(&s_initOnce,
[](PINIT_ONCE, PVOID, PVOID *) -> BOOL [](PINIT_ONCE, PVOID, PVOID *factory) -> BOOL
{ {
HRESULT hr = CoCreateInstance( return SUCCEEDED( CoCreateInstance(
CLSID_WICImagingFactory2, CLSID_WICImagingFactory2,
nullptr, nullptr,
CLSCTX_INPROC_SERVER, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&s_Factory)); __uuidof(IWICImagingFactory2),
if (FAILED(hr)) factory) ) ? TRUE : FALSE;
{ }, nullptr, reinterpret_cast<LPVOID*>(s_Factory.GetAddressOf()));
s_Factory = nullptr;
return FALSE;
}
return TRUE;
}, nullptr, nullptr);
return s_Factory; return s_Factory.Get();
} }
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------