diff --git a/Src/PlatformHelpers.h b/Src/PlatformHelpers.h index d1163578e..cecda37f0 100644 --- a/Src/PlatformHelpers.h +++ b/Src/PlatformHelpers.h @@ -68,8 +68,6 @@ namespace DirectX typedef public std::unique_ptr ScopedHandle; inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; } - - template class ScopedObject : public Microsoft::WRL::ComPtr {}; } diff --git a/Src/ScreenGrab.cpp b/Src/ScreenGrab.cpp index d7da64a8e..33636de16 100644 --- a/Src/ScreenGrab.cpp +++ b/Src/ScreenGrab.cpp @@ -40,6 +40,7 @@ #include "dds.h" #include "PlatformHelpers.h" +using Microsoft::WRL::ComPtr; using namespace DirectX; //-------------------------------------------------------------------------------------- @@ -340,7 +341,7 @@ static DXGI_FORMAT EnsureNotTypeless( DXGI_FORMAT fmt ) static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Inout_ D3D11_TEXTURE2D_DESC& desc, - _Inout_ ScopedObject& pStaging ) + _Inout_ ComPtr& pStaging ) { if ( !pContext || !pSource ) return E_INVALIDARG; @@ -351,7 +352,7 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, if ( resType != D3D11_RESOURCE_DIMENSION_TEXTURE2D ) return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED ); - ScopedObject pTexture; + ComPtr pTexture; HRESULT hr = pSource->QueryInterface( __uuidof(ID3D11Texture2D), reinterpret_cast( pTexture.GetAddressOf() ) ); if ( FAILED(hr) ) return hr; @@ -360,8 +361,8 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, pTexture->GetDesc( &desc ); - ScopedObject d3dDevice; - pContext->GetDevice( &d3dDevice ); + ComPtr d3dDevice; + pContext->GetDevice( d3dDevice.GetAddressOf() ); if ( desc.SampleDesc.Count > 1 ) { @@ -369,8 +370,8 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; - ScopedObject pTemp; - hr = d3dDevice->CreateTexture2D( &desc, 0, &pTemp ); + ComPtr pTemp; + hr = d3dDevice->CreateTexture2D( &desc, 0, pTemp.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -400,7 +401,7 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = d3dDevice->CreateTexture2D( &desc, 0, &pStaging ); + hr = d3dDevice->CreateTexture2D( &desc, 0, pStaging.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -421,7 +422,7 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext, desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; desc.Usage = D3D11_USAGE_STAGING; - hr = d3dDevice->CreateTexture2D( &desc, 0, &pStaging ); + hr = d3dDevice->CreateTexture2D( &desc, 0, pStaging.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -443,7 +444,7 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext, return E_INVALIDARG; D3D11_TEXTURE2D_DESC desc = { 0 }; - ScopedObject pStaging; + ComPtr pStaging; HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging ); if ( FAILED(hr) ) return hr; @@ -600,7 +601,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, return E_INVALIDARG; D3D11_TEXTURE2D_DESC desc = { 0 }; - ScopedObject pStaging; + ComPtr pStaging; HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging ); if ( FAILED(hr) ) return hr; @@ -658,8 +659,8 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( !pWIC ) return E_NOINTERFACE; - ScopedObject stream; - hr = pWIC->CreateStream( &stream ); + ComPtr stream; + hr = pWIC->CreateStream( stream.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -667,8 +668,8 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( FAILED(hr) ) return hr; - ScopedObject encoder; - hr = pWIC->CreateEncoder( guidContainerFormat, 0, &encoder ); + ComPtr encoder; + hr = pWIC->CreateEncoder( guidContainerFormat, 0, encoder.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -676,9 +677,9 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( FAILED(hr) ) return hr; - ScopedObject frame; - ScopedObject props; - hr = encoder->CreateNewFrame( &frame, &props ); + ComPtr frame; + ComPtr props; + hr = encoder->CreateNewFrame( frame.GetAddressOf(), props.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -765,8 +766,8 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, } // Encode WIC metadata - ScopedObject metawriter; - if ( SUCCEEDED( frame->GetMetadataQueryWriter( &metawriter ) ) ) + ComPtr metawriter; + if ( SUCCEEDED( frame->GetMetadataQueryWriter( metawriter.GetAddressOf() ) ) ) { PROPVARIANT value; PropVariantInit( &value ); @@ -810,18 +811,18 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext, if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 ) { // Conversion required to write - ScopedObject source; + ComPtr source; hr = pWIC->CreateBitmapFromMemory( desc.Width, desc.Height, pfGuid, mapped.RowPitch, mapped.RowPitch * desc.Height, - reinterpret_cast( mapped.pData ), &source ); + reinterpret_cast( mapped.pData ), source.GetAddressOf() ); if ( FAILED(hr) ) { pContext->Unmap( pStaging.Get(), 0 ); return hr; } - ScopedObject FC; - hr = pWIC->CreateFormatConverter( &FC ); + ComPtr FC; + hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); if ( FAILED(hr) ) { pContext->Unmap( pStaging.Get(), 0 ); diff --git a/Src/WICTextureLoader.cpp b/Src/WICTextureLoader.cpp index a9ed0a9fd..1684543b5 100644 --- a/Src/WICTextureLoader.cpp +++ b/Src/WICTextureLoader.cpp @@ -39,6 +39,7 @@ #include "PlatformHelpers.h" +using Microsoft::WRL::ComPtr; using namespace DirectX; //------------------------------------------------------------------------------------- @@ -242,8 +243,8 @@ static size_t _WICBitsPerPixel( REFGUID targetGuid ) if ( !pWIC ) return 0; - ScopedObject cinfo; - if ( FAILED( pWIC->CreateComponentInfo( targetGuid, &cinfo ) ) ) + ComPtr cinfo; + if ( FAILED( pWIC->CreateComponentInfo( targetGuid, cinfo.GetAddressOf() ) ) ) return 0; WICComponentType type; @@ -253,7 +254,7 @@ static size_t _WICBitsPerPixel( REFGUID targetGuid ) if ( type != WICPixelFormat ) return 0; - ScopedObject pfinfo; + ComPtr pfinfo; if ( FAILED( cinfo.As( &pfinfo ) ) ) return 0; @@ -448,8 +449,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, } else { - ScopedObject metareader; - if ( SUCCEEDED( frame->GetMetadataQueryReader( &metareader ) ) ) + ComPtr metareader; + if ( SUCCEEDED( frame->GetMetadataQueryReader( metareader.GetAddressOf() ) ) ) { GUID containerFormat; if ( SUCCEEDED( metareader->GetContainerFormat( &containerFormat ) ) ) @@ -518,8 +519,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, if ( !pWIC ) return E_NOINTERFACE; - ScopedObject scaler; - hr = pWIC->CreateBitmapScaler( &scaler ); + ComPtr scaler; + hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -541,8 +542,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, } else { - ScopedObject FC; - hr = pWIC->CreateFormatConverter( &FC ); + ComPtr FC; + hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -562,8 +563,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, if ( !pWIC ) return E_NOINTERFACE; - ScopedObject FC; - hr = pWIC->CreateFormatConverter( &FC ); + ComPtr FC; + hr = pWIC->CreateFormatConverter( FC.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -712,8 +713,8 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice, return E_NOINTERFACE; // Create input stream for memory - ScopedObject stream; - HRESULT hr = pWIC->CreateStream( &stream ); + ComPtr stream; + HRESULT hr = pWIC->CreateStream( stream.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -722,13 +723,13 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice, return hr; // Initialize WIC - ScopedObject decoder; - hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, &decoder ); + ComPtr decoder; + hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf() ); if ( FAILED(hr) ) return hr; - ScopedObject frame; - hr = decoder->GetFrame( 0, &frame ); + ComPtr frame; + hr = decoder->GetFrame( 0, frame.GetAddressOf() ); if ( FAILED(hr) ) return hr; @@ -795,13 +796,13 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice, return E_NOINTERFACE; // Initialize WIC - ScopedObject decoder; - HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder ); + ComPtr decoder; + HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf() ); if ( FAILED(hr) ) return hr; - ScopedObject frame; - hr = decoder->GetFrame( 0, &frame ); + ComPtr frame; + hr = decoder->GetFrame( 0, frame.GetAddressOf() ); if ( FAILED(hr) ) return hr;