mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1046550 - Part 1: Add content device to gfxWindowsPlatform. r=mattwoodrow
This commit is contained in:
parent
89390bcff9
commit
00d3edd7d3
@ -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<D3D_FEATURE_LEVEL> 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<IDXGIAdapter1> 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<D3D_FEATURE_LEVEL> 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<IDXGIAdapter1> 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();
|
||||
}
|
@ -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<IDXGIAdapter1> mAdapter;
|
||||
nsRefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
|
||||
mozilla::RefPtr<ID3D11Device> mD3D11Device;
|
||||
mozilla::RefPtr<ID3D11Device> mD3D11ContentDevice;
|
||||
bool mD3D11DeviceInitialized;
|
||||
mozilla::RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user