1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-12-27 11:50:13 +00:00

Eliminate ScopedObject in favor of standard Microsoft::WRL::ComPtr

This commit is contained in:
walbourn_cp 2014-01-15 17:08:08 -08:00
parent ef53c0d8a3
commit b4b63a3557
12 changed files with 215 additions and 364 deletions

View File

@ -19,6 +19,8 @@
#pragma comment(lib,"dxguid.lib")
#endif
using Microsoft::WRL::ComPtr;
namespace
{
#include "Shaders\Compiled\BC7Encode_EncodeBlockCS.inc"
@ -359,7 +361,7 @@ HRESULT GPUCompressBC::Compress( const Image& srcImage, const Image& destImage )
// We need to avoid the hardware doing additional colorspace conversion
DXGI_FORMAT inputFormat = ( m_srcformat == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB ) ? DXGI_FORMAT_R8G8B8A8_UNORM : m_srcformat;
ScopedObject<ID3D11Texture2D> sourceTex;
ComPtr<ID3D11Texture2D> sourceTex;
{
D3D11_TEXTURE2D_DESC desc;
memset( &desc, 0, sizeof(desc) );
@ -384,7 +386,7 @@ HRESULT GPUCompressBC::Compress( const Image& srcImage, const Image& destImage )
}
}
ScopedObject<ID3D11ShaderResourceView> sourceSRV;
ComPtr<ID3D11ShaderResourceView> sourceSRV;
{
D3D11_SHADER_RESOURCE_VIEW_DESC desc;
memset( &desc, 0, sizeof(desc) );
@ -392,7 +394,7 @@ HRESULT GPUCompressBC::Compress( const Image& srcImage, const Image& destImage )
desc.Format = inputFormat;
desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
HRESULT hr = pDevice->CreateShaderResourceView( sourceTex.Get(), &desc, sourceSRV.ReleaseAndGetAddressOf() );
HRESULT hr = pDevice->CreateShaderResourceView( sourceTex.Get(), &desc, sourceSRV.GetAddressOf() );
if ( FAILED(hr) )
{
return hr;

View File

@ -15,8 +15,6 @@
#pragma once
#endif
#include "scoped.h"
namespace DirectX
{
@ -40,31 +38,31 @@ private:
size_t m_width;
size_t m_height;
ScopedObject<ID3D11Device> m_device;
ScopedObject<ID3D11DeviceContext> m_context;
Microsoft::WRL::ComPtr<ID3D11Device> m_device;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_context;
ScopedObject<ID3D11Buffer> m_err1;
ScopedObject<ID3D11UnorderedAccessView> m_err1UAV;
ScopedObject<ID3D11ShaderResourceView> m_err1SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err1;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err1UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err1SRV;
ScopedObject<ID3D11Buffer> m_err2;
ScopedObject<ID3D11UnorderedAccessView> m_err2UAV;
ScopedObject<ID3D11ShaderResourceView> m_err2SRV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_err2;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_err2UAV;
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> m_err2SRV;
ScopedObject<ID3D11Buffer> m_output;
ScopedObject<ID3D11Buffer> m_outputCPU;
ScopedObject<ID3D11UnorderedAccessView> m_outputUAV;
ScopedObject<ID3D11Buffer> m_constBuffer;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_output;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_outputCPU;
Microsoft::WRL::ComPtr<ID3D11UnorderedAccessView> m_outputUAV;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constBuffer;
// Compute shader library
ScopedObject<ID3D11ComputeShader> m_BC6H_tryModeG10CS;
ScopedObject<ID3D11ComputeShader> m_BC6H_tryModeLE10CS;
ScopedObject<ID3D11ComputeShader> m_BC6H_encodeBlockCS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeG10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_tryModeLE10CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC6H_encodeBlockCS;
ScopedObject<ID3D11ComputeShader> m_BC7_tryMode456CS;
ScopedObject<ID3D11ComputeShader> m_BC7_tryMode137CS;
ScopedObject<ID3D11ComputeShader> m_BC7_tryMode02CS;
ScopedObject<ID3D11ComputeShader> m_BC7_encodeBlockCS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode456CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode137CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_tryMode02CS;
Microsoft::WRL::ComPtr<ID3D11ComputeShader> m_BC7_encodeBlockCS;
};
}; // namespace

View File

@ -16,6 +16,7 @@
#include "directxtexp.h"
using namespace DirectX::PackedVector;
using Microsoft::WRL::ComPtr;
#if DIRECTX_MATH_VERSION < 306
namespace
@ -3158,8 +3159,8 @@ static HRESULT _ConvertUsingWIC( _In_ const Image& srcImage, _In_ const WICPixel
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICFormatConverter> FC;
HRESULT hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
HRESULT hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -3174,10 +3175,10 @@ static HRESULT _ConvertUsingWIC( _In_ const Image& srcImage, _In_ const WICPixel
return E_UNEXPECTED;
}
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
srcImage.pixels, source.GetAddressOf() );
if ( FAILED(hr) )
return hr;

View File

@ -19,6 +19,8 @@
#include <d3d10.h>
#endif
using Microsoft::WRL::ComPtr;
namespace DirectX
{
@ -562,10 +564,10 @@ HRESULT CreateShaderResourceViewEx( ID3D11Device* pDevice, const Image* srcImage
*ppSRV = nullptr;
ScopedObject<ID3D11Resource> resource;
ComPtr<ID3D11Resource> resource;
HRESULT hr = CreateTextureEx( pDevice, srcImages, nimages, metadata,
usage, bindFlags, cpuAccessFlags, miscFlags, forceSRGB,
&resource );
resource.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -661,7 +663,7 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
{
case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
{
ScopedObject<ID3D11Texture1D> pTexture;
ComPtr<ID3D11Texture1D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture1D), reinterpret_cast<void**>( pTexture.GetAddressOf() ) );
if ( FAILED(hr) )
break;
@ -676,8 +678,8 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
ScopedObject<ID3D11Texture1D> pStaging;
hr = pDevice->CreateTexture1D( &desc, 0, &pStaging );
ComPtr<ID3D11Texture1D> pStaging;
hr = pDevice->CreateTexture1D( &desc, 0, pStaging.GetAddressOf() );
if ( FAILED(hr) )
break;
@ -705,7 +707,7 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
{
ScopedObject<ID3D11Texture2D> pTexture;
ComPtr<ID3D11Texture2D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture2D), reinterpret_cast<void**>( pTexture.GetAddressOf() ) );
if ( FAILED(hr) )
break;
@ -715,14 +717,14 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
D3D11_TEXTURE2D_DESC desc;
pTexture->GetDesc( &desc );
ScopedObject<ID3D11Texture2D> pStaging;
ComPtr<ID3D11Texture2D> pStaging;
if ( desc.SampleDesc.Count > 1 )
{
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
ScopedObject<ID3D11Texture2D> pTemp;
hr = pDevice->CreateTexture2D( &desc, 0, &pTemp );
ComPtr<ID3D11Texture2D> pTemp;
hr = pDevice->CreateTexture2D( &desc, 0, pTemp.GetAddressOf() );
if ( FAILED(hr) )
break;
@ -761,7 +763,7 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
hr = pDevice->CreateTexture2D( &desc, 0, &pStaging );
hr = pDevice->CreateTexture2D( &desc, 0, pStaging.GetAddressOf() );
if ( FAILED(hr) )
break;
@ -806,7 +808,7 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
{
ScopedObject<ID3D11Texture3D> pTexture;
ComPtr<ID3D11Texture3D> pTexture;
hr = pSource->QueryInterface( __uuidof(ID3D11Texture3D), reinterpret_cast<void**>( pTexture.GetAddressOf() ) );
if ( FAILED(hr) )
break;
@ -821,8 +823,8 @@ HRESULT CaptureTexture( ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.Usage = D3D11_USAGE_STAGING;
ScopedObject<ID3D11Texture3D> pStaging;
hr = pDevice->CreateTexture3D( &desc, 0, &pStaging );
ComPtr<ID3D11Texture3D> pStaging;
hr = pDevice->CreateTexture3D( &desc, 0, pStaging.GetAddressOf() );
if ( FAILED(hr) )
break;

View File

@ -15,6 +15,8 @@
#include "directxtexp.h"
using Microsoft::WRL::ComPtr;
namespace DirectX
{
@ -33,15 +35,15 @@ static HRESULT _PerformFlipRotateUsingWIC( _In_ const Image& srcImage, _In_ DWOR
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
HRESULT hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
srcImage.pixels, source.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapFlipRotator> FR;
hr = pWIC->CreateBitmapFlipRotator( &FR );
ComPtr<IWICBitmapFlipRotator> FR;
hr = pWIC->CreateBitmapFlipRotator( FR.GetAddressOf() );
if ( FAILED(hr) )
return hr;

View File

@ -17,6 +17,8 @@
#include "filters.h"
using Microsoft::WRL::ComPtr;
namespace DirectX
{
@ -134,8 +136,8 @@ static HRESULT _EnsureWicBitmapPixelFormat( _In_ IWICImagingFactory* pWIC, _In_
}
else
{
ScopedObject<IWICFormatConverter> converter;
hr = pWIC->CreateFormatConverter( &converter );
ComPtr<IWICFormatConverter> converter;
hr = pWIC->CreateFormatConverter( converter.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = converter->Initialize( src, desiredPixelFormat, _GetWICDither(filter), 0, 0, WICBitmapPaletteTypeCustom );
@ -172,10 +174,10 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICComponentInfo> componentInfo;
hr = pWIC->CreateComponentInfo( desiredPixelFormat, &componentInfo );
ComPtr<IWICComponentInfo> componentInfo;
hr = pWIC->CreateComponentInfo( desiredPixelFormat, componentInfo.GetAddressOf() );
ScopedObject<IWICPixelFormatInfo> pixelFormatInfo;
ComPtr<IWICPixelFormatInfo> pixelFormatInfo;
if ( SUCCEEDED(hr) )
{
hr = componentInfo.As( &pixelFormatInfo );
@ -220,17 +222,15 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
}
// Resize color only image (no alpha channel)
ScopedObject<IWICBitmap> resizedColor;
ComPtr<IWICBitmap> resizedColor;
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmapScaler> colorScaler;
hr = pWIC->CreateBitmapScaler(&colorScaler);
ComPtr<IWICBitmapScaler> colorScaler;
hr = pWIC->CreateBitmapScaler( colorScaler.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmap> converted;
hr = _EnsureWicBitmapPixelFormat( pWIC, original, filter, colorPixelFormat, &converted );
ComPtr<IWICBitmap> converted;
hr = _EnsureWicBitmapPixelFormat( pWIC, original, filter, colorPixelFormat, converted.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = colorScaler->Initialize( converted.Get(), static_cast<UINT>(newWidth), static_cast<UINT>(newHeight), interpolationMode );
@ -239,28 +239,25 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmap> resized;
hr = pWIC->CreateBitmapFromSource( colorScaler.Get(), WICBitmapCacheOnDemand, &resized );
ComPtr<IWICBitmap> resized;
hr = pWIC->CreateBitmapFromSource( colorScaler.Get(), WICBitmapCacheOnDemand, resized.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = _EnsureWicBitmapPixelFormat( pWIC, resized.Get(), filter, colorPixelFormat, &resizedColor );
hr = _EnsureWicBitmapPixelFormat( pWIC, resized.Get(), filter, colorPixelFormat, resizedColor.GetAddressOf() );
}
}
}
// Resize color+alpha image
ScopedObject<IWICBitmap> resizedColorWithAlpha;
ComPtr<IWICBitmap> resizedColorWithAlpha;
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmapScaler> colorWithAlphaScaler;
hr = pWIC->CreateBitmapScaler( &colorWithAlphaScaler );
ComPtr<IWICBitmapScaler> colorWithAlphaScaler;
hr = pWIC->CreateBitmapScaler( colorWithAlphaScaler.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmap> converted;
hr = _EnsureWicBitmapPixelFormat( pWIC, original, filter, colorWithAlphaPixelFormat, &converted );
ComPtr<IWICBitmap> converted;
hr = _EnsureWicBitmapPixelFormat( pWIC, original, filter, colorWithAlphaPixelFormat, converted.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = colorWithAlphaScaler->Initialize( converted.Get(), static_cast<UINT>(newWidth), static_cast<UINT>(newHeight), interpolationMode );
@ -269,12 +266,11 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmap> resized;
hr = pWIC->CreateBitmapFromSource( colorWithAlphaScaler.Get(), WICBitmapCacheOnDemand, &resized );
ComPtr<IWICBitmap> resized;
hr = pWIC->CreateBitmapFromSource( colorWithAlphaScaler.Get(), WICBitmapCacheOnDemand, resized.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = _EnsureWicBitmapPixelFormat( pWIC, resized.Get(), filter, colorWithAlphaPixelFormat, &resizedColorWithAlpha );
hr = _EnsureWicBitmapPixelFormat( pWIC, resized.Get(), filter, colorWithAlphaPixelFormat, resizedColorWithAlpha.GetAddressOf() );
}
}
}
@ -282,13 +278,12 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
// Merge pixels (copying color channels from color only image to color+alpha image)
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmapLock> colorLock;
ScopedObject<IWICBitmapLock> colorWithAlphaLock;
hr = resizedColor->Lock( nullptr, WICBitmapLockRead, &colorLock );
ComPtr<IWICBitmapLock> colorLock;
ComPtr<IWICBitmapLock> colorWithAlphaLock;
hr = resizedColor->Lock( nullptr, WICBitmapLockRead, colorLock.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = resizedColorWithAlpha->Lock( nullptr, WICBitmapLockWrite, &colorWithAlphaLock );
hr = resizedColorWithAlpha->Lock( nullptr, WICBitmapLockWrite, colorWithAlphaLock.GetAddressOf() );
}
if ( SUCCEEDED(hr) )
@ -353,8 +348,8 @@ HRESULT _ResizeSeparateColorAndAlpha( _In_ IWICImagingFactory* pWIC, _In_ IWICBi
if ( SUCCEEDED(hr) )
{
ScopedObject<IWICBitmap> wicBitmap;
hr = _EnsureWicBitmapPixelFormat( pWIC, resizedColorWithAlpha.Get(), filter, desiredPixelFormat, &wicBitmap );
ComPtr<IWICBitmap> wicBitmap;
hr = _EnsureWicBitmapPixelFormat( pWIC, resizedColorWithAlpha.Get(), filter, desiredPixelFormat, wicBitmap.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
hr = wicBitmap->CopyPixels( nullptr, static_cast<UINT>(img->rowPitch), static_cast<UINT>(img->slicePitch), img->pixels );
@ -443,10 +438,10 @@ static HRESULT _GenerateMipMapsUsingWIC( _In_ const Image& baseImage, _In_ DWORD
size_t width = baseImage.width;
size_t height = baseImage.height;
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
HRESULT hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( width ), static_cast<UINT>( height ), pfGUID,
static_cast<UINT>( baseImage.rowPitch ), static_cast<UINT>( baseImage.slicePitch ),
baseImage.pixels, &source );
baseImage.pixels, source.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -468,12 +463,12 @@ static HRESULT _GenerateMipMapsUsingWIC( _In_ const Image& baseImage, _In_ DWORD
pDest += img0->rowPitch;
}
ScopedObject<IWICComponentInfo> componentInfo;
hr = pWIC->CreateComponentInfo( pfGUID, &componentInfo );
ComPtr<IWICComponentInfo> componentInfo;
hr = pWIC->CreateComponentInfo( pfGUID, componentInfo.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICPixelFormatInfo2> pixelFormatInfo;
ComPtr<IWICPixelFormatInfo2> pixelFormatInfo;
hr = componentInfo.As( &pixelFormatInfo );
if ( FAILED(hr) )
return hr;
@ -506,8 +501,8 @@ static HRESULT _GenerateMipMapsUsingWIC( _In_ const Image& baseImage, _In_ DWORD
}
else
{
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -530,8 +525,8 @@ static HRESULT _GenerateMipMapsUsingWIC( _In_ const Image& baseImage, _In_ DWORD
{
// The WIC bitmap scaler is free to return a different pixel format than the source image, so here we
// convert it back
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;

View File

@ -38,6 +38,7 @@
#pragma warning(push)
#pragma warning(disable : 4005)
#include <wincodec.h>
#include <wrl.h>
#pragma warning(pop)
#include "scoped.h"

View File

@ -17,6 +17,8 @@
#include "filters.h"
using Microsoft::WRL::ComPtr;
namespace DirectX
{
@ -40,12 +42,12 @@ static HRESULT _PerformResizeUsingWIC( _In_ const Image& srcImage, _In_ DWORD fi
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICComponentInfo> componentInfo;
HRESULT hr = pWIC->CreateComponentInfo( pfGUID, &componentInfo );
ComPtr<IWICComponentInfo> componentInfo;
HRESULT hr = pWIC->CreateComponentInfo( pfGUID, componentInfo.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICPixelFormatInfo2> pixelFormatInfo;
ComPtr<IWICPixelFormatInfo2> pixelFormatInfo;
hr = componentInfo.As( &pixelFormatInfo );
if ( FAILED(hr) )
return hr;
@ -55,10 +57,10 @@ static HRESULT _PerformResizeUsingWIC( _In_ const Image& srcImage, _In_ DWORD fi
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( srcImage.width ), static_cast<UINT>( srcImage.height ), pfGUID,
static_cast<UINT>( srcImage.rowPitch ), static_cast<UINT>( srcImage.slicePitch ),
srcImage.pixels, &source );
srcImage.pixels, source.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -70,8 +72,8 @@ static HRESULT _PerformResizeUsingWIC( _In_ const Image& srcImage, _In_ DWORD fi
}
else
{
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -94,8 +96,8 @@ static HRESULT _PerformResizeUsingWIC( _In_ const Image& srcImage, _In_ DWORD fi
{
// The WIC bitmap scaler is free to return a different pixel format than the source image, so here we
// convert it back
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;

View File

@ -15,6 +15,8 @@
#include "directxtexp.h"
using Microsoft::WRL::ComPtr;
//-------------------------------------------------------------------------------------
// IStream support for WIC Memory routines
//-------------------------------------------------------------------------------------
@ -43,7 +45,7 @@
Microsoft::WRL::ComPtr<ABI::Windows::Storage::Streams::IRandomAccessStream> abiStream;
HRESULT hr = Windows::Foundation::ActivateInstance(
Microsoft::WRL::Wrappers::HStringReference( RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream ).Get(),
&abiStream);
abiStream.GetAddressOf() );
if (SUCCEEDED(hr))
{
@ -279,8 +281,8 @@ static HRESULT _DecodeMetadata( _In_ DWORD flags,
if ( FAILED(hr) )
return hr;
ScopedObject<IWICMetadataQueryReader> metareader;
hr = frame->GetMetadataQueryReader( &metareader );
ComPtr<IWICMetadataQueryReader> metareader;
hr = frame->GetMetadataQueryReader( metareader.GetAddressOf() );
if ( SUCCEEDED(hr) )
{
// Check for sRGB colorspace metadata
@ -347,8 +349,8 @@ static HRESULT _DecodeSingleFrame( _In_ DWORD flags, _In_ const TexMetadata& met
}
else
{
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -392,8 +394,8 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta
if ( !img )
return E_POINTER;
ScopedObject<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( static_cast<UINT>( index ), &frame );
ComPtr<IWICBitmapFrameDecode> frame;
hr = decoder->GetFrame( static_cast<UINT>( index ), frame.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -419,8 +421,8 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta
else
{
// This frame needs resizing, but not format converted
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -436,8 +438,8 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta
else
{
// This frame required format conversion
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -455,8 +457,8 @@ static HRESULT _DecodeMultiframe( _In_ DWORD flags, _In_ const TexMetadata& meta
else
{
// This frame needs resizing and format converted
ScopedObject<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( &scaler );
ComPtr<IWICBitmapScaler> scaler;
hr = pWIC->CreateBitmapScaler( scaler.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -483,8 +485,8 @@ static HRESULT _EncodeMetadata( _In_ IWICBitmapFrameEncode* frame, _In_ const GU
if ( !frame )
return E_POINTER;
ScopedObject<IWICMetadataQueryWriter> metawriter;
HRESULT hr = frame->GetMetadataQueryWriter( &metawriter );
ComPtr<IWICMetadataQueryWriter> metawriter;
HRESULT hr = frame->GetMetadataQueryWriter( metawriter.GetAddressOf() );
if ( SUCCEEDED( hr ) )
{
PROPVARIANT value;
@ -587,15 +589,15 @@ static HRESULT _EncodeImage( _In_ const Image& image, _In_ DWORD flags, _In_ REF
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmap> source;
ComPtr<IWICBitmap> source;
hr = pWIC->CreateBitmapFromMemory( static_cast<UINT>( image.width ), static_cast<UINT>( image.height ), pfGuid,
static_cast<UINT>( image.rowPitch ), static_cast<UINT>( image.slicePitch ),
image.pixels, &source );
image.pixels, source.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( &FC );
ComPtr<IWICFormatConverter> FC;
hr = pWIC->CreateFormatConverter( FC.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -636,8 +638,8 @@ static HRESULT _EncodeSingleFrame( _In_ const Image& image, _In_ DWORD flags,
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( containerFormat, 0, &encoder );
ComPtr<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( containerFormat, 0, encoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -645,9 +647,9 @@ static HRESULT _EncodeSingleFrame( _In_ const Image& image, _In_ DWORD flags,
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;
@ -698,13 +700,13 @@ static HRESULT _EncodeMultiframe( _In_reads_(nimages) const Image* images, _In_
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( containerFormat, 0, &encoder );
ComPtr<IWICBitmapEncoder> encoder;
HRESULT hr = pWIC->CreateEncoder( containerFormat, 0, encoder.GetAddressOf() );
if ( FAILED(hr) )
return hr;
ScopedObject<IWICBitmapEncoderInfo> einfo;
hr = encoder->GetEncoderInfo( &einfo );
ComPtr<IWICBitmapEncoderInfo> einfo;
hr = encoder->GetEncoderInfo( einfo.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -722,9 +724,9 @@ static HRESULT _EncodeMultiframe( _In_reads_(nimages) const Image* images, _In_
for( size_t index=0; index < nimages; ++index )
{
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;
@ -769,8 +771,8 @@ HRESULT GetMetadataFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, Tex
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;
@ -780,13 +782,13 @@ HRESULT GetMetadataFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, Tex
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;
@ -813,13 +815,13 @@ HRESULT GetMetadataFromWICFile( LPCWSTR szFile, DWORD flags, TexMetadata& metada
return E_NOINTERFACE;
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
ComPtr<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 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;
@ -853,8 +855,8 @@ HRESULT LoadFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, TexMetadat
image.Release();
// 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;
@ -863,13 +865,13 @@ HRESULT LoadFromWICMemory( LPCVOID pSource, size_t size, DWORD flags, TexMetadat
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;
@ -918,13 +920,13 @@ HRESULT LoadFromWICFile( LPCWSTR szFile, DWORD flags, TexMetadata* metadata, Scr
image.Release();
// Initialize WIC
ScopedObject<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 0, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder );
ComPtr<IWICBitmapDecoder> decoder;
HRESULT hr = pWIC->CreateDecoderFromFilename( szFile, 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;
@ -969,8 +971,8 @@ HRESULT SaveToWICMemory( const Image& image, DWORD flags, REFGUID containerForma
blob.Release();
ScopedObject<IStream> stream;
HRESULT hr = CreateMemoryStream( &stream );
ComPtr<IStream> stream;
HRESULT hr = CreateMemoryStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -1016,8 +1018,8 @@ HRESULT SaveToWICMemory( const Image* images, size_t nimages, DWORD flags, REFGU
blob.Release();
ScopedObject<IStream> stream;
HRESULT hr = CreateMemoryStream( &stream );
ComPtr<IStream> stream;
HRESULT hr = CreateMemoryStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -1076,8 +1078,8 @@ HRESULT SaveToWICFile( const Image& image, DWORD flags, REFGUID containerFormat,
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
ComPtr<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;
@ -1103,8 +1105,8 @@ HRESULT SaveToWICFile( const Image* images, size_t nimages, DWORD flags, REFGUID
if ( !pWIC )
return E_NOINTERFACE;
ScopedObject<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( &stream );
ComPtr<IWICStream> stream;
HRESULT hr = pWIC->CreateStream( stream.GetAddressOf() );
if ( FAILED(hr) )
return hr;

View File

@ -32,15 +32,3 @@ struct handle_closer { void operator()(HANDLE h) { assert(h != INVALID_HANDLE_VA
typedef public std::unique_ptr<void, handle_closer> ScopedHandle;
inline HANDLE safe_handle( HANDLE h ) { return (h == INVALID_HANDLE_VALUE) ? 0 : h; }
//---------------------------------------------------------------------------------
#include <wrl.h>
template<class T> class ScopedObject : public Microsoft::WRL::ComPtr<T>
{
public:
ScopedObject() : Microsoft::WRL::ComPtr<T>() {}
ScopedObject( T *p ) : Microsoft::WRL::ComPtr<T>(p) {}
ScopedObject( const ScopedObject& other ) : Microsoft::WRL::ComPtr( other ) {}
};

View File

@ -32,6 +32,7 @@
#pragma warning(push)
#pragma warning(disable : 4005)
#include <wincodec.h>
#include <wrl.h>
#pragma warning(pop)
#endif
@ -39,6 +40,8 @@
#include "ScreenGrab.h"
using Microsoft::WRL::ComPtr;
//--------------------------------------------------------------------------------------
// Macros
//--------------------------------------------------------------------------------------
@ -181,80 +184,6 @@ static const DDS_PIXELFORMAT DDSPF_A8 =
static const DDS_PIXELFORMAT DDSPF_DX10 =
{ sizeof(DDS_PIXELFORMAT), DDS_FOURCC, MAKEFOURCC('D','X','1','0'), 0, 0, 0, 0, 0 };
//---------------------------------------------------------------------------------
#if defined(_MSC_VER) && (_MSC_VER >= 1610)
#include <wrl.h>
template<class T> class ScopedObject : public Microsoft::WRL::ComPtr<T> {};
#else
template<class T> class ScopedObject
{
public:
ScopedObject() : _pointer(nullptr) {}
ScopedObject( T *p ) : _pointer(p) { if (_pointer) { _pointer->AddRef(); } }
ScopedObject( const ScopedObject& other ) : _pointer(other._pointer) { if (_pointer) { _pointer->AddRef(); } }
~ScopedObject()
{
if ( _pointer )
{
_pointer->Release();
_pointer = nullptr;
}
}
operator bool() const { return (_pointer != nullptr); }
T& operator= (_In_opt_ T* other)
{
if ( _pointer != other )
{
if ( _pointer) { _pointer->Release(); }
_pointer = other;
if ( other ) { other->AddRef() };
}
return *this;
}
ScopedObject& operator= (const ScopedObject& other)
{
if ( _pointer != other._pointer )
{
if ( _pointer) { _pointer->Release(); }
_pointer = other._pointer;
if ( other._pointer ) { other._pointer->AddRef(); }
}
return *this;
}
T& operator*() { return *_pointer; }
T* operator->() const { return _pointer; }
T** operator&() { return &_pointer; }
void Reset() { if ( _pointer ) { _pointer->Release(); _pointer = nullptr; } }
T* Get() const { return _pointer; }
T** GetAddressOf() { return &_pointer; }
T** ReleaseAndGetAddressOf() { if ( _pointer ) { _pointer->Release(); _pointer = nullptr; } return &_pointer; }
template<typename U>
HRESULT As(_Inout_ U* p) { return _pointer->QueryInterface( _uuidof(U), reinterpret_cast<void**>( p ) ); }
template<typename U>
HRESULT As(_Out_ ScopedObject<U>* p ) { return _pointer->QueryInterface( _uuidof(U), reinterpret_cast<void**>( p->ReleaseAndGetAddressOf() ) ); }
private:
T* _pointer;
};
#endif
//---------------------------------------------------------------------------------
struct handle_closer { void operator()(HANDLE h) { if (h) CloseHandle(h); } };
@ -561,7 +490,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;
@ -572,7 +501,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;
@ -581,8 +510,8 @@ 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 )
{
@ -590,8 +519,8 @@ static HRESULT CaptureTexture( _In_ ID3D11DeviceContext* pContext,
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;
@ -621,7 +550,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;
@ -642,7 +571,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;
@ -727,7 +656,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;
@ -878,7 +807,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;
@ -936,8 +865,8 @@ 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;
@ -945,8 +874,8 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
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;
@ -954,9 +883,9 @@ HRESULT DirectX::SaveWICTextureToFile( _In_ ID3D11DeviceContext* pContext,
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;
@ -1043,8 +972,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 );
@ -1088,18 +1017,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 );

View File

@ -34,6 +34,7 @@
#pragma warning(push)
#pragma warning(disable : 4005)
#include <wincodec.h>
#include <wrl.h>
#pragma warning(pop)
#include <memory>
@ -44,79 +45,7 @@
#pragma comment(lib,"dxguid.lib")
#endif
//---------------------------------------------------------------------------------
#if defined(_MSC_VER) && (_MSC_VER >= 1610)
#include <wrl.h>
template<class T> class ScopedObject : public Microsoft::WRL::ComPtr<T> {};
#else
template<class T> class ScopedObject
{
public:
ScopedObject() : _pointer(nullptr) {}
ScopedObject( T *p ) : _pointer(p) { if (_pointer) { _pointer->AddRef(); } }
ScopedObject( const ScopedObject& other ) : _pointer(other._pointer) { if (_pointer) { _pointer->AddRef(); } }
~ScopedObject()
{
if ( _pointer )
{
_pointer->Release();
_pointer = nullptr;
}
}
operator bool() const { return (_pointer != nullptr); }
T& operator= (_In_opt_ T* other)
{
if ( _pointer != other )
{
if ( _pointer) { _pointer->Release(); }
_pointer = other;
if ( other ) { other->AddRef() };
}
return *this;
}
ScopedObject& operator= (const ScopedObject& other)
{
if ( _pointer != other._pointer )
{
if ( _pointer) { _pointer->Release(); }
_pointer = other._pointer;
if ( other._pointer ) { other._pointer->AddRef(); }
}
return *this;
}
T& operator*() { return *_pointer; }
T* operator->() const { return _pointer; }
T** operator&() { return &_pointer; }
void Reset() { if ( _pointer ) { _pointer->Release(); _pointer = nullptr; } }
T* Get() const { return _pointer; }
T** GetAddressOf() { return &_pointer; }
T** ReleaseAndGetAddressOf() { if ( _pointer ) { _pointer->Release(); _pointer = nullptr; } return &_pointer; }
template<typename U>
HRESULT As(_Inout_ U* p) { return _pointer->QueryInterface( _uuidof(U), reinterpret_cast<void**>( p ) ); }
template<typename U>
HRESULT As(_Out_ ScopedObject<U>* p ) { return _pointer->QueryInterface( _uuidof(U), reinterpret_cast<void**>( p->ReleaseAndGetAddressOf() ) ); }
private:
T* _pointer;
};
#endif
using Microsoft::WRL::ComPtr;
//--------------------------------------------------------------------------------------
@ -321,8 +250,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;
@ -332,7 +261,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;
@ -527,8 +456,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 ) ) )
@ -597,8 +526,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;
@ -620,8 +549,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;
@ -641,8 +570,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;
@ -791,8 +720,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;
@ -801,13 +730,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;
@ -874,13 +803,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;