From 00d3edd7d3ad289c7137063051d3d43a8e09b6b2 Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Sun, 14 Sep 2014 23:51:27 +0200 Subject: [PATCH] Bug 1046550 - Part 1: Add content device to gfxWindowsPlatform. r=mattwoodrow --- gfx/thebes/gfxWindowsPlatform.cpp | 106 ++++++++++++++++++++---------- gfx/thebes/gfxWindowsPlatform.h | 3 + 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp index 2c44930c9794..ae83f45c8cbb 100644 --- a/gfx/thebes/gfxWindowsPlatform.cpp +++ b/gfx/thebes/gfxWindowsPlatform.cpp @@ -1366,43 +1366,23 @@ gfxWindowsPlatform::GetD3D11Device() return mD3D11Device; } - mD3D11DeviceInitialized = true; - - nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll")); - decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*) - GetProcAddress(d3d11Module, "D3D11CreateDevice"); - - if (!d3d11CreateDevice) { - return nullptr; - } - - nsTArray featureLevels; - if (IsWin8OrLater()) { - featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1); - } - featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0); - featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1); - featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0); - featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3); - - RefPtr adapter = GetDXGIAdapter(); - - if (!adapter) { - return nullptr; - } - - HRESULT hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, - D3D11_CREATE_DEVICE_BGRA_SUPPORT, - featureLevels.Elements(), featureLevels.Length(), - D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr); - - // We leak these everywhere and we need them our entire runtime anyway, let's - // leak it here as well. - d3d11Module.disown(); + InitD3D11Devices(); return mD3D11Device; } +ID3D11Device* +gfxWindowsPlatform::GetD3D11ContentDevice() +{ + if (mD3D11DeviceInitialized) { + return mD3D11ContentDevice; + } + + InitD3D11Devices(); + + return mD3D11ContentDevice; +} + ReadbackManagerD3D11* gfxWindowsPlatform::GetReadbackManager() { @@ -1487,3 +1467,63 @@ gfxWindowsPlatform::GetDXGIAdapter() return mAdapter; } + +void +gfxWindowsPlatform::InitD3D11Devices() +{ + mD3D11DeviceInitialized = true; + + nsModuleHandle d3d11Module(LoadLibrarySystem32(L"d3d11.dll")); + decltype(D3D11CreateDevice)* d3d11CreateDevice = (decltype(D3D11CreateDevice)*) + GetProcAddress(d3d11Module, "D3D11CreateDevice"); + + if (!d3d11CreateDevice) { + return; + } + + nsTArray featureLevels; + if (IsWin8OrLater()) { + featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_1); + } + featureLevels.AppendElement(D3D_FEATURE_LEVEL_11_0); + featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_1); + featureLevels.AppendElement(D3D_FEATURE_LEVEL_10_0); + featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3); + + RefPtr adapter = GetDXGIAdapter(); + + if (!adapter) { + return; + } + + HRESULT hr; + + hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, + featureLevels.Elements(), featureLevels.Length(), + D3D11_SDK_VERSION, byRef(mD3D11Device), nullptr, nullptr); + + if (FAILED(hr)) { + return; + } + +#ifdef USE_D2D1_1 + if (Factory::SupportsD2D1()) { + hr = d3d11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, + featureLevels.Elements(), featureLevels.Length(), + D3D11_SDK_VERSION, byRef(mD3D11ContentDevice), nullptr, nullptr); + + if (FAILED(hr)) { + mD3D11Device = nullptr; + return; + } + + Factory::SetDirect3D11Device(mD3D11ContentDevice); + } +#endif + + // We leak these everywhere and we need them our entire runtime anyway, let's + // leak it here as well. + d3d11Module.disown(); +} \ No newline at end of file diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h index bc3a8e2c360f..ec7658104264 100644 --- a/gfx/thebes/gfxWindowsPlatform.h +++ b/gfx/thebes/gfxWindowsPlatform.h @@ -261,6 +261,7 @@ public: ID3D10Device1 *GetD3D10Device() { return mD2DDevice ? cairo_d2d_device_get_device(mD2DDevice) : nullptr; } #endif ID3D11Device *GetD3D11Device(); + ID3D11Device *GetD3D11ContentDevice(); mozilla::layers::ReadbackManagerD3D11* GetReadbackManager(); @@ -274,6 +275,7 @@ protected: private: void Init(); + void InitD3D11Devices(); IDXGIAdapter1 *GetDXGIAdapter(); bool mUseDirectWrite; @@ -291,6 +293,7 @@ private: mozilla::RefPtr mAdapter; nsRefPtr mDeviceManager; mozilla::RefPtr mD3D11Device; + mozilla::RefPtr mD3D11ContentDevice; bool mD3D11DeviceInitialized; mozilla::RefPtr mD3D11ReadbackManager;