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 @@ ...@@ -23,6 +23,10 @@
namespace angle 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 class NonCopyable
{ {
public: public:
......
...@@ -65,6 +65,10 @@ ...@@ -65,6 +65,10 @@
# include <d3dcompiler.h> # include <d3dcompiler.h>
# endif # endif
#if defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
#include <wrl.h>
#endif
# if defined(ANGLE_ENABLE_WINDOWS_STORE) # if defined(ANGLE_ENABLE_WINDOWS_STORE)
# include <dxgi1_3.h> # include <dxgi1_3.h>
# if defined(_DEBUG) # if defined(_DEBUG)
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
namespace gl 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) Error::Error(GLenum errorCode, const char *msg, ...) : mCode(errorCode), mID(errorCode)
{ {
va_list vararg; va_list vararg;
...@@ -64,8 +69,27 @@ bool Error::operator!=(const Error &other) const ...@@ -64,8 +69,27 @@ bool Error::operator!=(const Error &other) const
{ {
return !(*this == other); 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 namespace egl
{ {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define LIBANGLE_ERROR_H_ #define LIBANGLE_ERROR_H_
#include "angle_gl.h" #include "angle_gl.h"
#include "common/angleutils.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include <string> #include <string>
...@@ -18,10 +19,14 @@ ...@@ -18,10 +19,14 @@
namespace gl namespace gl
{ {
template <typename T>
class ErrorOrResult;
class Error final class Error final
{ {
public: public:
explicit inline Error(GLenum errorCode); explicit inline Error(GLenum errorCode);
Error(GLenum errorCode, std::string &&msg);
Error(GLenum errorCode, const char *msg, ...); Error(GLenum errorCode, const char *msg, ...);
Error(GLenum errorCode, GLuint id, const char *msg, ...); Error(GLenum errorCode, GLuint id, const char *msg, ...);
inline Error(const Error &other); inline Error(const Error &other);
...@@ -48,6 +53,63 @@ class Error final ...@@ -48,6 +53,63 @@ class Error final
mutable std::unique_ptr<std::string> mMessage; 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> template <typename T>
class ErrorOrResult class ErrorOrResult
{ {
......
...@@ -181,7 +181,6 @@ class Blit11 : angle::NonCopyable ...@@ -181,7 +181,6 @@ class Blit11 : angle::NonCopyable
}; };
gl::Error initResources(); gl::Error initResources();
void freeResources();
ShaderSupport getShaderSupport(const Shader &shader); ShaderSupport getShaderSupport(const Shader &shader);
...@@ -262,12 +261,12 @@ class Blit11 : angle::NonCopyable ...@@ -262,12 +261,12 @@ class Blit11 : angle::NonCopyable
std::map<SwizzleShaderType, Shader> mSwizzleShaderMap; std::map<SwizzleShaderType, Shader> mSwizzleShaderMap;
bool mResourcesInitialized; bool mResourcesInitialized;
ID3D11Buffer *mVertexBuffer; angle::ComPtr<ID3D11Buffer> mVertexBuffer;
ID3D11SamplerState *mPointSampler; angle::ComPtr<ID3D11SamplerState> mPointSampler;
ID3D11SamplerState *mLinearSampler; angle::ComPtr<ID3D11SamplerState> mLinearSampler;
ID3D11RasterizerState *mScissorEnabledRasterizerState; angle::ComPtr<ID3D11RasterizerState> mScissorEnabledRasterizerState;
ID3D11RasterizerState *mScissorDisabledRasterizerState; angle::ComPtr<ID3D11RasterizerState> mScissorDisabledRasterizerState;
ID3D11DepthStencilState *mDepthStencilState; angle::ComPtr<ID3D11DepthStencilState> mDepthStencilState;
d3d11::LazyInputLayout mQuad2DIL; d3d11::LazyInputLayout mQuad2DIL;
d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS; d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS;
...@@ -279,15 +278,15 @@ class Blit11 : angle::NonCopyable ...@@ -279,15 +278,15 @@ class Blit11 : angle::NonCopyable
d3d11::LazyBlendState mAlphaMaskBlendState; d3d11::LazyBlendState mAlphaMaskBlendState;
ID3D11Buffer *mSwizzleCB; angle::ComPtr<ID3D11Buffer> mSwizzleCB;
d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS; d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS; d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS; d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS; d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS;
ID3D11ShaderResourceView *mStencilSRV; angle::ComPtr<ID3D11ShaderResourceView> mStencilSRV;
TextureHelper11 mResolvedDepthStencil; TextureHelper11 mResolvedDepthStencil;
ID3D11RenderTargetView *mResolvedDepthStencilRTView; angle::ComPtr<ID3D11RenderTargetView> mResolvedDepthStencilRTView;
}; };
} // namespace rx } // namespace rx
......
...@@ -13,9 +13,7 @@ ...@@ -13,9 +13,7 @@
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) #if defined(ANGLE_ENABLE_WINDOWS_STORE)
typedef void* EventRegistrationToken;
#else
#include <EventToken.h> #include <EventToken.h>
#endif #endif
......
...@@ -135,6 +135,12 @@ void SetPositionDepthColorVertex(PositionDepthColorVertex<T>* vertex, float x, f ...@@ -135,6 +135,12 @@ void SetPositionDepthColorVertex(PositionDepthColorVertex<T>* vertex, float x, f
HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name); 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> template <typename outType>
outType* DynamicCastComObject(IUnknown* object) 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