Bug 1381085 - Part 1: Create new D3D11Device for WebVR
MozReview-Commit-ID: EewUkNxU3BI
--- a/gfx/thebes/DeviceManagerDx.cpp
+++ b/gfx/thebes/DeviceManagerDx.cpp
@@ -104,16 +104,17 @@ DeviceManagerDx::LoadD3D11()
return true;
}
void
DeviceManagerDx::ReleaseD3D11()
{
MOZ_ASSERT(!mCompositorDevice);
MOZ_ASSERT(!mContentDevice);
+ MOZ_ASSERT(!mVRDevice);
MOZ_ASSERT(!mDecoderDevice);
mD3D11Module.reset();
sD3D11CreateDeviceFn = nullptr;
}
static inline bool
ProcessOwnsCompositor()
@@ -164,16 +165,51 @@ DeviceManagerDx::CreateCompositorDevices
if (!d3d11.IsEnabled()) {
return false;
}
PreloadAttachmentsOnCompositorThread();
return true;
}
+bool
+DeviceManagerDx::CreateVRDevice()
+{
+ MOZ_ASSERT(ProcessOwnsCompositor());
+
+ if (mVRDevice) {
+ return true;
+ }
+
+ if (!LoadD3D11()) {
+ return false;
+ }
+
+ RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
+ if (!adapter) {
+ NS_WARNING("Failed to acquire a DXGI adapter for VR");
+ return false;
+ }
+
+ UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
+
+ HRESULT hr;
+ if (!CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, flags, hr, mVRDevice)) {
+ gfxCriticalError() << "Crash during D3D11 device creation for VR";
+ return false;
+ }
+
+ if (FAILED(hr) || !mVRDevice) {
+ NS_WARNING("Failed to acquire a D3D11 device for VR");
+ return false;
+ }
+
+ return true;
+}
+
void
DeviceManagerDx::ImportDeviceInfo(const D3D11DeviceStatus& aDeviceStatus)
{
MOZ_ASSERT(!ProcessOwnsCompositor());
mDeviceStatus = Some(aDeviceStatus);
}
@@ -938,16 +974,26 @@ DeviceManagerDx::GetCompositorDevice()
RefPtr<ID3D11Device>
DeviceManagerDx::GetContentDevice()
{
MutexAutoLock lock(mDeviceLock);
return mContentDevice;
}
+RefPtr<ID3D11Device>
+DeviceManagerDx::GetVRDevice()
+{
+ MutexAutoLock lock(mDeviceLock);
+ if(!mVRDevice) {
+ CreateVRDevice();
+ }
+ return mVRDevice;
+}
+
unsigned
DeviceManagerDx::GetCompositorFeatureLevel() const
{
if (!mDeviceStatus) {
return 0;
}
return mDeviceStatus->featureLevel();
}
--- a/gfx/thebes/DeviceManagerDx.h
+++ b/gfx/thebes/DeviceManagerDx.h
@@ -52,16 +52,17 @@ public:
DeviceManagerDx();
static DeviceManagerDx* Get() {
return sInstance;
}
RefPtr<ID3D11Device> GetCompositorDevice();
RefPtr<ID3D11Device> GetContentDevice();
+ RefPtr<ID3D11Device> GetVRDevice();
RefPtr<ID3D11Device> CreateDecoderDevice();
RefPtr<layers::MLGDevice> GetMLGDevice();
IDirectDraw7* GetDirectDraw();
unsigned GetCompositorFeatureLevel() const;
bool TextureSharingWorks();
bool IsWARP();
bool CanUseNV12();
@@ -118,16 +119,17 @@ private:
bool CreateCompositorDeviceHelper(
mozilla::gfx::FeatureState& aD3d11,
IDXGIAdapter1* aAdapter,
bool aAttemptVideoSupport,
RefPtr<ID3D11Device>& aOutDevice);
void CreateWARPCompositorDevice();
void CreateMLGDevice();
+ bool CreateVRDevice();
mozilla::gfx::FeatureStatus CreateContentDevice();
bool CreateDevice(IDXGIAdapter* aAdapter,
D3D_DRIVER_TYPE aDriverType,
UINT aFlags,
HRESULT& aResOut,
RefPtr<ID3D11Device>& aOutDevice);
@@ -149,16 +151,17 @@ private:
// the ref and unassign the module).
nsModuleHandle mD3D11Module;
mozilla::Mutex mDeviceLock;
nsTArray<D3D_FEATURE_LEVEL> mFeatureLevels;
RefPtr<IDXGIAdapter1> mAdapter;
RefPtr<ID3D11Device> mCompositorDevice;
RefPtr<ID3D11Device> mContentDevice;
+ RefPtr<ID3D11Device> mVRDevice;
RefPtr<ID3D11Device> mDecoderDevice;
RefPtr<layers::DeviceAttachmentsD3D11> mCompositorAttachments;
RefPtr<layers::MLGDevice> mMLGDevice;
bool mCompositorDeviceSupportsVideo;
Maybe<D3D11DeviceStatus> mDeviceStatus;
nsModuleHandle mDirectDrawDLL;