Commit 47c0e048 by Jamie Madill Committed by Commit Bot

Use ComPtr references for D3D objects.

This is an work-in-progress CL to prototype using ComPtr. It also has a new design for internal errors that doesn't use FormatString, preferring a stream-based approach. One thing to be aware of is that the address operator does not behave as expected with ComPtr - we should use ::AddressOf. BUG=angleproject:530 BUG=angleproject:1644 Change-Id: If5643e9e5726fd9aa5cbd422fca12ae169eb5b1f Reviewed-on: https://chromium-review.googlesource.com/415027 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 08d4aa93
......@@ -23,6 +23,10 @@
namespace angle
{
#if defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
using Microsoft::WRL::ComPtr;
#endif // defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
class NonCopyable
{
public:
......
......@@ -65,6 +65,10 @@
# include <d3dcompiler.h>
# endif
#if defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
#include <wrl.h>
#endif
# if defined(ANGLE_ENABLE_WINDOWS_STORE)
# include <dxgi1_3.h>
# if defined(_DEBUG)
......
......@@ -16,6 +16,11 @@
namespace gl
{
Error::Error(GLenum errorCode, std::string &&message)
: mCode(errorCode), mID(errorCode), mMessage(new std::string(std::move(message)))
{
}
Error::Error(GLenum errorCode, const char *msg, ...) : mCode(errorCode), mID(errorCode)
{
va_list vararg;
......@@ -64,8 +69,27 @@ bool Error::operator!=(const Error &other) const
{
return !(*this == other);
}
namespace priv
{
template <GLenum EnumT>
ErrorStream<EnumT>::ErrorStream()
{
}
template <GLenum EnumT>
ErrorStream<EnumT>::operator gl::Error()
{
return Error(EnumT, mErrorStream.str().c_str());
}
template class ErrorStream<GL_OUT_OF_MEMORY>;
template class ErrorStream<GL_INVALID_OPERATION>;
} // namespace priv
} // namespace gl
namespace egl
{
......
......@@ -10,6 +10,7 @@
#define LIBANGLE_ERROR_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include <EGL/egl.h>
#include <string>
......@@ -18,10 +19,14 @@
namespace gl
{
template <typename T>
class ErrorOrResult;
class Error final
{
public:
explicit inline Error(GLenum errorCode);
Error(GLenum errorCode, std::string &&msg);
Error(GLenum errorCode, const char *msg, ...);
Error(GLenum errorCode, GLuint id, const char *msg, ...);
inline Error(const Error &other);
......@@ -48,6 +53,63 @@ class Error final
mutable std::unique_ptr<std::string> mMessage;
};
namespace priv
{
template <GLenum EnumT>
class ErrorStream : angle::NonCopyable
{
public:
ErrorStream();
template <typename T>
ErrorStream &operator<<(T value);
operator Error();
template <typename T>
operator ErrorOrResult<T>()
{
return static_cast<Error>(*this);
}
private:
std::ostringstream mErrorStream;
};
// These convience methods for HRESULTS (really long) are used all over the place in the D3D
// back-ends.
#if defined(ANGLE_PLATFORM_WINDOWS)
template <>
template <>
inline ErrorStream<GL_OUT_OF_MEMORY> &ErrorStream<GL_OUT_OF_MEMORY>::operator<<(HRESULT hresult)
{
mErrorStream << "HRESULT: 0x" << std::ios::hex << hresult;
return *this;
}
template <>
template <>
inline ErrorStream<GL_INVALID_OPERATION> &ErrorStream<GL_INVALID_OPERATION>::operator<<(
HRESULT hresult)
{
mErrorStream << "HRESULT: 0x" << std::ios::hex << hresult;
return *this;
}
#endif // defined(ANGLE_PLATFORM_WINDOWS)
template <GLenum EnumT>
template <typename T>
ErrorStream<EnumT> &ErrorStream<EnumT>::operator<<(T value)
{
mErrorStream << value;
return *this;
}
} // namespace priv
using OutOfMemory = priv::ErrorStream<GL_OUT_OF_MEMORY>;
using InternalError = priv::ErrorStream<GL_INVALID_OPERATION>;
template <typename T>
class ErrorOrResult
{
......
......@@ -181,7 +181,6 @@ class Blit11 : angle::NonCopyable
};
gl::Error initResources();
void freeResources();
ShaderSupport getShaderSupport(const Shader &shader);
......@@ -262,12 +261,12 @@ class Blit11 : angle::NonCopyable
std::map<SwizzleShaderType, Shader> mSwizzleShaderMap;
bool mResourcesInitialized;
ID3D11Buffer *mVertexBuffer;
ID3D11SamplerState *mPointSampler;
ID3D11SamplerState *mLinearSampler;
ID3D11RasterizerState *mScissorEnabledRasterizerState;
ID3D11RasterizerState *mScissorDisabledRasterizerState;
ID3D11DepthStencilState *mDepthStencilState;
angle::ComPtr<ID3D11Buffer> mVertexBuffer;
angle::ComPtr<ID3D11SamplerState> mPointSampler;
angle::ComPtr<ID3D11SamplerState> mLinearSampler;
angle::ComPtr<ID3D11RasterizerState> mScissorEnabledRasterizerState;
angle::ComPtr<ID3D11RasterizerState> mScissorDisabledRasterizerState;
angle::ComPtr<ID3D11DepthStencilState> mDepthStencilState;
d3d11::LazyInputLayout mQuad2DIL;
d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS;
......@@ -279,15 +278,15 @@ class Blit11 : angle::NonCopyable
d3d11::LazyBlendState mAlphaMaskBlendState;
ID3D11Buffer *mSwizzleCB;
angle::ComPtr<ID3D11Buffer> mSwizzleCB;
d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS;
ID3D11ShaderResourceView *mStencilSRV;
angle::ComPtr<ID3D11ShaderResourceView> mStencilSRV;
TextureHelper11 mResolvedDepthStencil;
ID3D11RenderTargetView *mResolvedDepthStencilRTView;
angle::ComPtr<ID3D11RenderTargetView> mResolvedDepthStencilRTView;
};
} // namespace rx
......
......@@ -13,9 +13,7 @@
#include "libANGLE/angletypes.h"
#include "libANGLE/Error.h"
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
typedef void* EventRegistrationToken;
#else
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
#include <EventToken.h>
#endif
......
......@@ -135,6 +135,12 @@ void SetPositionDepthColorVertex(PositionDepthColorVertex<T>* vertex, float x, f
HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name);
template <typename T>
HRESULT SetDebugName(angle::ComPtr<T> &resource, const char *name)
{
return SetDebugName(resource.Get(), name);
}
template <typename outType>
outType* DynamicCastComObject(IUnknown* object)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment