From b0fbe12bd39420c7b342ee184b934fbe811e3e69 Mon Sep 17 00:00:00 2001 From: sotaro Date: Thu, 31 May 2018 09:35:24 +0900 Subject: [PATCH] Bug 1465306 - Make D3D11YCbCrRecycleAllocator handle device reset r=nical --- gfx/layers/D3D11YCbCrImage.cpp | 20 +++++++++++++++++--- gfx/layers/D3D11YCbCrImage.h | 7 +------ gfx/layers/ImageContainer.cpp | 19 +++---------------- gfx/thebes/DeviceManagerDx.cpp | 32 ++++++++++++++++++++++++++++++++ gfx/thebes/DeviceManagerDx.h | 2 ++ 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/gfx/layers/D3D11YCbCrImage.cpp b/gfx/layers/D3D11YCbCrImage.cpp index ef5cbf09fa75..fcb12742cd7e 100644 --- a/gfx/layers/D3D11YCbCrImage.cpp +++ b/gfx/layers/D3D11YCbCrImage.cpp @@ -7,6 +7,7 @@ #include "D3D11YCbCrImage.h" #include "YCbCrUtils.h" #include "mozilla/gfx/gfxVars.h" +#include "mozilla/gfx/DeviceManagerDx.h" #include "mozilla/layers/CompositableClient.h" #include "mozilla/layers/CompositableForwarder.h" #include "mozilla/layers/TextureD3D11.h" @@ -56,8 +57,13 @@ D3D11YCbCrImage::SetData(KnowsCompositor* aAllocator, return false; } + RefPtr device = gfx::DeviceManagerDx::Get()->GetImageDevice(); + if (!device) { + return false; + } + { - DXGIYCbCrTextureAllocationHelper helper(aData, TextureFlags::DEFAULT, allocator->GetDevice()); + DXGIYCbCrTextureAllocationHelper helper(aData, TextureFlags::DEFAULT, device); mTextureClient = allocator->CreateOrRecycle(helper); } @@ -73,7 +79,7 @@ D3D11YCbCrImage::SetData(KnowsCompositor* aAllocator, ID3D11Texture2D* textureCr = data->GetD3D11Texture(2); RefPtr mt; - HRESULT hr = allocator->GetDevice()->QueryInterface( + HRESULT hr = device->QueryInterface( (ID3D10Multithread**)getter_AddRefs(mt)); if (FAILED(hr) || !mt) { @@ -89,7 +95,7 @@ D3D11YCbCrImage::SetData(KnowsCompositor* aAllocator, D3D11MTAutoEnter mtAutoEnter(mt.forget()); RefPtr ctx; - allocator->GetDevice()->GetImmediateContext(getter_AddRefs(ctx)); + device->GetImmediateContext(getter_AddRefs(ctx)); if (!ctx) { gfxCriticalError() << "Failed to get immediate context."; return false; @@ -323,6 +329,14 @@ DXGIYCbCrTextureAllocationHelper::IsCompatible(TextureClient* aTextureClient) dxgiData->GetYUVColorSpace() != mData.mYUVColorSpace) { return false; } + + RefPtr texY = dxgiData->GetD3D11Texture(0); + RefPtr device; + texY->GetDevice(getter_AddRefs(device)); + if (!device || device != gfx::DeviceManagerDx::Get()->GetImageDevice()) { + return false; + } + return true; } diff --git a/gfx/layers/D3D11YCbCrImage.h b/gfx/layers/D3D11YCbCrImage.h index 78de41446c63..5fdeff0b5dd0 100644 --- a/gfx/layers/D3D11YCbCrImage.h +++ b/gfx/layers/D3D11YCbCrImage.h @@ -25,14 +25,11 @@ class DXGIYCbCrTextureData; class D3D11YCbCrRecycleAllocator : public TextureClientRecycleAllocator { public: - explicit D3D11YCbCrRecycleAllocator(KnowsCompositor* aAllocator, - ID3D11Device* aDevice) + explicit D3D11YCbCrRecycleAllocator(KnowsCompositor* aAllocator) : TextureClientRecycleAllocator(aAllocator) - , mDevice(aDevice) { } - ID3D11Device* GetDevice() const { return mDevice; } KnowsCompositor* GetAllocator() const { return mSurfaceAllocator; } protected: @@ -42,8 +39,6 @@ protected: BackendSelector aSelector, TextureFlags aTextureFlags, TextureAllocationFlags aAllocFlags) override; - - RefPtr mDevice; }; class D3D11YCbCrImage : public Image diff --git a/gfx/layers/ImageContainer.cpp b/gfx/layers/ImageContainer.cpp index 6d460edd992e..2f70420ddf2f 100644 --- a/gfx/layers/ImageContainer.cpp +++ b/gfx/layers/ImageContainer.cpp @@ -472,26 +472,13 @@ ImageContainer::GetD3D11YCbCrRecycleAllocator(KnowsCompositor* aAllocator) return mD3D11YCbCrRecycleAllocator; } - RefPtr device = gfx::DeviceManagerDx::Get()->GetContentDevice(); - if (!device) { - device = gfx::DeviceManagerDx::Get()->GetCompositorDevice(); - } - - if (!device || !aAllocator->SupportsD3D11()) { + if (!aAllocator->SupportsD3D11() || + !gfx::DeviceManagerDx::Get()->GetImageDevice()) { return nullptr; } - RefPtr multi; - HRESULT hr = - device->QueryInterface((ID3D10Multithread**)getter_AddRefs(multi)); - if (FAILED(hr) || !multi) { - gfxWarning() << "Multithread safety interface not supported. " << hr; - return nullptr; - } - multi->SetMultithreadProtected(TRUE); - mD3D11YCbCrRecycleAllocator = - new D3D11YCbCrRecycleAllocator(aAllocator, device); + new D3D11YCbCrRecycleAllocator(aAllocator); return mD3D11YCbCrRecycleAllocator; } #endif diff --git a/gfx/thebes/DeviceManagerDx.cpp b/gfx/thebes/DeviceManagerDx.cpp index 203d236571f5..189707ac752e 100644 --- a/gfx/thebes/DeviceManagerDx.cpp +++ b/gfx/thebes/DeviceManagerDx.cpp @@ -867,6 +867,7 @@ DeviceManagerDx::ResetDevices() mMLGDevice = nullptr; mCompositorDevice = nullptr; mContentDevice = nullptr; + mImageDevice = nullptr; mDeviceStatus = Nothing(); mDeviceResetReason = Nothing(); Factory::SetDirect3D11Device(nullptr); @@ -1053,6 +1054,37 @@ DeviceManagerDx::GetContentDevice() return mContentDevice; } +RefPtr +DeviceManagerDx::GetImageDevice() +{ + MutexAutoLock lock(mDeviceLock); + if (mImageDevice) { + return mImageDevice; + } + + RefPtr device = mContentDevice; + if (!device) { + device = mCompositorDevice; + } + + if (!device) { + return nullptr; + } + + RefPtr multi; + HRESULT hr = + device->QueryInterface((ID3D10Multithread**)getter_AddRefs(multi)); + if (FAILED(hr) || !multi) { + gfxWarning() << "Multithread safety interface not supported. " << hr; + return nullptr; + } + multi->SetMultithreadProtected(TRUE); + + mImageDevice = device; + + return mImageDevice; +} + RefPtr DeviceManagerDx::GetVRDevice() { diff --git a/gfx/thebes/DeviceManagerDx.h b/gfx/thebes/DeviceManagerDx.h index 6db4828b1254..e764b43fdd0c 100644 --- a/gfx/thebes/DeviceManagerDx.h +++ b/gfx/thebes/DeviceManagerDx.h @@ -58,6 +58,7 @@ public: RefPtr GetCompositorDevice(); RefPtr GetContentDevice(); + RefPtr GetImageDevice(); RefPtr GetDirectCompositionDevice(); RefPtr GetVRDevice(); RefPtr CreateDecoderDevice(); @@ -163,6 +164,7 @@ private: RefPtr mAdapter; RefPtr mCompositorDevice; RefPtr mContentDevice; + RefPtr mImageDevice; RefPtr mVRDevice; RefPtr mDecoderDevice; RefPtr mDirectCompositionDevice;