Skip to content

Commit

Permalink
Eliminate ScopedObject in favor of standard Microsoft::WRL::ComPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn_cp authored and walbourn_cp committed Jan 16, 2014
1 parent 376c8d2 commit 8a4d273
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
2 changes: 0 additions & 2 deletions Src/PlatformHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ namespace DirectX
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;

inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }

template<class T> class ScopedObject : public Microsoft::WRL::ComPtr<T> {};
}


Expand Down
47 changes: 24 additions & 23 deletions Src/ScreenGrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "dds.h"
#include "PlatformHelpers.h"

using Microsoft::WRL::ComPtr;
using namespace DirectX;

//--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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<ID3D11Texture2D>& pStaging )
_Inout_ ComPtr<ID3D11Texture2D>& pStaging )
{
if ( !pContext || !pSource )
return E_INVALIDARG;
Expand All @@ -351,7 +352,7 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext,
if ( resType != D3D11_RESOURCE_DIMENSION_TEXTURE2D )
return HRESULT_FROM_WIN32( ERROR_NOT_SUPPORTED );

ScopedObject<ID3D11Texture2D> pTexture;
ComPtr<ID3D11Texture2D> pTexture;
HRESULT hr = pSource->QueryInterface( __uuidof(ID3D11Texture2D), reinterpret_cast<void**>( pTexture.GetAddressOf() ) );
if ( FAILED(hr) )
return hr;
Expand All @@ -360,17 +361,17 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext,

pTexture->GetDesc( &desc );

ScopedObject<ID3D11Device> d3dDevice;
pContext->GetDevice( &d3dDevice );
ComPtr<ID3D11Device> d3dDevice;
pContext->GetDevice( d3dDevice.GetAddressOf() );

if ( desc.SampleDesc.Count > 1 )
{
// MSAA content must be resolved before being copied to a staging texture
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;

ScopedObject<ID3D11Texture2D> pTemp;
hr = d3dDevice->CreateTexture2D( &desc, 0, &pTemp );
ComPtr<ID3D11Texture2D> pTemp;
hr = d3dDevice->CreateTexture2D( &desc, 0, pTemp.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -443,7 +444,7 @@ HRESULT DirectX::SaveDDSTextureToFile( _In_ ID3D11DeviceContext* pContext,
return E_INVALIDARG;

D3D11_TEXTURE2D_DESC desc = { 0 };
ScopedObject<ID3D11Texture2D> pStaging;
ComPtr<ID3D11Texture2D> pStaging;
HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging );
if ( FAILED(hr) )
return hr;
Expand Down Expand Up @@ -600,7 +601,7 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
return E_INVALIDARG;

D3D11_TEXTURE2D_DESC desc = { 0 };
ScopedObject<ID3D11Texture2D> pStaging;
ComPtr<ID3D11Texture2D> pStaging;
HRESULT hr = CaptureTexture( pContext, pSource, desc, pStaging );
if ( FAILED(hr) )
return hr;
Expand Down Expand Up @@ -658,27 +659,27 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
if ( !pWIC )
return E_NOINTERFACE;

ScopedObject<IWICStream> stream;
hr = pWIC->CreateStream( &stream );
ComPtr<IWICStream> stream;
hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;

hr = stream->InitializeFromFilename( fileName, GENERIC_WRITE );
if ( FAILED(hr) )
return hr;

ScopedObject<IWICBitmapEncoder> encoder;
hr = pWIC->CreateEncoder( guidContainerFormat, 0, &encoder );
ComPtr<IWICBitmapEncoder> encoder;
hr = pWIC->CreateEncoder( guidContainerFormat, 0, encoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;

hr = encoder->Initialize( stream.Get(), WICBitmapEncoderNoCache );
if ( FAILED(hr) )
return hr;

ScopedObject<IWICBitmapFrameEncode> frame;
ScopedObject<IPropertyBag2> props;
hr = encoder->CreateNewFrame( &frame, &props );
ComPtr<IWICBitmapFrameEncode> frame;
ComPtr<IPropertyBag2> props;
hr = encoder->CreateNewFrame( frame.GetAddressOf(), props.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand Down Expand Up @@ -765,8 +766,8 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
}

// Encode WIC metadata
ScopedObject<IWICMetadataQueryWriter> metawriter;
if ( SUCCEEDED( frame->GetMetadataQueryWriter( &metawriter ) ) )
ComPtr<IWICMetadataQueryWriter> metawriter;
if ( SUCCEEDED( frame->GetMetadataQueryWriter( metawriter.GetAddressOf() ) ) )
{
PROPVARIANT value;
PropVariantInit( &value );
Expand Down Expand Up @@ -810,18 +811,18 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
if ( memcmp( &targetGuid, &pfGuid, sizeof(WICPixelFormatGUID) ) != 0 )
{
// Conversion required to write
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( desc.Width, desc.Height, pfGuid,
mapped.RowPitch, mapped.RowPitch * desc.Height,
reinterpret_cast<BYTE*>( mapped.pData ), &source );
reinterpret_cast<BYTE*>( mapped.pData ), source.GetAddressOf() );
if ( FAILED(hr) )
{
pContext->Unmap( pStaging.Get(), 0 );
return hr;
}

ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
{
pContext->Unmap( pStaging.Get(), 0 );
Expand Down
43 changes: 22 additions & 21 deletions Src/WICTextureLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "PlatformHelpers.h"

using Microsoft::WRL::ComPtr;
using namespace DirectX;

//-------------------------------------------------------------------------------------
Expand Down Expand Up @@ -242,8 +243,8 @@ static size_t _WICBitsPerPixel( REFGUID targetGuid )
if ( !pWIC )
return 0;

ScopedObject<IWICComponentInfo> cinfo;
if ( FAILED( pWIC->CreateComponentInfo( targetGuid, &cinfo ) ) )
ComPtr<IWICComponentInfo> cinfo;
if ( FAILED( pWIC->CreateComponentInfo( targetGuid, cinfo.GetAddressOf() ) ) )
return 0;

WICComponentType type;
Expand All @@ -253,7 +254,7 @@ static size_t _WICBitsPerPixel( REFGUID targetGuid )
if ( type != WICPixelFormat )
return 0;

ScopedObject<IWICPixelFormatInfo> pfinfo;
ComPtr<IWICPixelFormatInfo> pfinfo;
if ( FAILED( cinfo.As( &pfinfo ) ) )
return 0;

Expand Down Expand Up @@ -448,8 +449,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
}
else
{
ScopedObject<IWICMetadataQueryReader> metareader;
if ( SUCCEEDED( frame->GetMetadataQueryReader( &metareader ) ) )
ComPtr<IWICMetadataQueryReader> metareader;
if ( SUCCEEDED( frame->GetMetadataQueryReader( metareader.GetAddressOf() ) ) )
{
GUID containerFormat;
if ( SUCCEEDED( metareader->GetContainerFormat( &containerFormat ) ) )
Expand Down Expand Up @@ -518,8 +519,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
if ( !pWIC )
return E_NOINTERFACE;

ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand All @@ -541,8 +542,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
}
else
{
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand All @@ -562,8 +563,8 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
if ( !pWIC )
return E_NOINTERFACE;

ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand Down Expand Up @@ -712,8 +713,8 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
return E_NOINTERFACE;

// Create input stream for memory
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
ComPtr<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand All @@ -722,13 +723,13 @@ HRESULT DirectX::CreateWICTextureFromMemoryEx( ID3D11Device* d3dDevice,
return hr;

// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, &decoder );
ComPtr<IWICBitmapDecoder> decoder;
hr = pWIC->CreateDecoderFromStream( stream.Get(), 0, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;

ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
ComPtr<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, frame.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand Down Expand Up @@ -795,13 +796,13 @@ HRESULT DirectX::CreateWICTextureFromFileEx( ID3D11Device* d3dDevice,
return E_NOINTERFACE;

// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
ComPtr<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( fileName, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, decoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;

ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, &frame );
ComPtr<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( 0, frame.GetAddressOf() );
if ( FAILED(hr) )
return hr;

Expand Down

0 comments on commit 8a4d273

Please sign in to comment.