DeviceAttachmentsD3D11.h (3270B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_gfx_layers_d3d11_DeviceAttachmentsD3D11_h 8 #define mozilla_gfx_layers_d3d11_DeviceAttachmentsD3D11_h 9 10 #include "mozilla/EnumeratedArray.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/gfx/DeviceManagerDx.h" 13 #include "mozilla/layers/CompositorTypes.h" 14 #include "mozilla/layers/SyncObject.h" 15 #include <d3d11.h> 16 #include <dxgi1_2.h> 17 18 namespace mozilla { 19 namespace layers { 20 21 struct ShaderBytes; 22 23 class DeviceAttachmentsD3D11 final { 24 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DeviceAttachmentsD3D11); 25 26 public: 27 static RefPtr<DeviceAttachmentsD3D11> Create(ID3D11Device* aDevice); 28 29 bool IsValid() const { return mInitialized; } 30 const nsCString& GetFailureId() const { 31 MOZ_ASSERT(!IsValid()); 32 return mInitFailureId; 33 } 34 35 typedef EnumeratedArray<ClipType, RefPtr<ID3D11VertexShader>, 36 size_t(ClipType::NumClipTypes)> 37 VertexShaderArray; 38 typedef EnumeratedArray<ClipType, RefPtr<ID3D11PixelShader>, 39 size_t(ClipType::NumClipTypes)> 40 PixelShaderArray; 41 42 RefPtr<ID3D11InputLayout> mInputLayout; 43 44 RefPtr<ID3D11Buffer> mVertexBuffer; 45 46 VertexShaderArray mVSQuadShader; 47 48 RefPtr<ID3D11PixelShader> mSolidColorShader; 49 PixelShaderArray mRGBAShader; 50 PixelShaderArray mRGBShader; 51 PixelShaderArray mYCbCrShader; 52 PixelShaderArray mNV12Shader; 53 RefPtr<ID3D11Buffer> mPSConstantBuffer; 54 RefPtr<ID3D11Buffer> mVSConstantBuffer; 55 RefPtr<ID3D11RasterizerState> mRasterizerState; 56 RefPtr<ID3D11SamplerState> mLinearSamplerState; 57 RefPtr<ID3D11SamplerState> mPointSamplerState; 58 59 RefPtr<ID3D11BlendState> mPremulBlendState; 60 RefPtr<ID3D11BlendState> mPremulCopyState; 61 RefPtr<ID3D11BlendState> mNonPremulBlendState; 62 RefPtr<ID3D11BlendState> mDisabledBlendState; 63 64 RefPtr<SyncObjectHost> mSyncObject; 65 66 void SetDeviceReset() { mDeviceReset = true; } 67 bool IsDeviceReset() const { return mDeviceReset; } 68 69 private: 70 explicit DeviceAttachmentsD3D11(ID3D11Device* device); 71 ~DeviceAttachmentsD3D11(); 72 73 bool Initialize(); 74 bool CreateShaders(); 75 bool InitSyncObject(); 76 77 void InitVertexShader(const ShaderBytes& aShader, VertexShaderArray& aArray, 78 ClipType aClipType) { 79 InitVertexShader(aShader, getter_AddRefs(aArray[aClipType])); 80 } 81 void InitPixelShader(const ShaderBytes& aShader, PixelShaderArray& aArray, 82 ClipType aClipType) { 83 InitPixelShader(aShader, getter_AddRefs(aArray[aClipType])); 84 } 85 86 void InitVertexShader(const ShaderBytes& aShader, ID3D11VertexShader** aOut); 87 void InitPixelShader(const ShaderBytes& aShader, ID3D11PixelShader** aOut); 88 89 bool Failed(HRESULT hr, const char* aContext); 90 91 private: 92 // Only used during initialization. 93 RefPtr<ID3D11Device> mDevice; 94 bool mContinueInit; 95 bool mInitialized; 96 bool mDeviceReset; 97 nsCString mInitFailureId; 98 }; 99 100 } // namespace layers 101 } // namespace mozilla 102 103 #endif // mozilla_gfx_layers_d3d11_DeviceAttachmentsD3D11_h