зеркало из https://github.com/mozilla/gecko-dev.git
Move the DeviceManagerD3D9 singleton out of gfxPlatform. (bug 1297182 part 1, r=mattwoodrow)
--HG-- extra : rebase_source : 2ddbac1ce59cad17b9074a85d7ab11862d9b805d
This commit is contained in:
Родитель
5d7e68e2b4
Коммит
2b23d07c29
|
@ -4,6 +4,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "IMFYCbCrImage.h"
|
||||
#include "DeviceManagerD3D9.h"
|
||||
#include "mozilla/layers/TextureD3D11.h"
|
||||
#include "mozilla/layers/CompositableClient.h"
|
||||
#include "mozilla/layers/CompositableForwarder.h"
|
||||
|
@ -156,7 +157,7 @@ static bool UploadData(IDirect3DDevice9* aDevice,
|
|||
TextureClient*
|
||||
IMFYCbCrImage::GetD3D9TextureClient(CompositableClient* aClient)
|
||||
{
|
||||
IDirect3DDevice9* device = gfxWindowsPlatform::GetPlatform()->GetD3D9Device();
|
||||
RefPtr<IDirect3DDevice9> device = DeviceManagerD3D9::GetDevice();
|
||||
if (!device) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "mozilla/layers/ShadowLayers.h"
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "DeviceManagerD3D9.h"
|
||||
#include "mozilla/gfx/DeviceManagerD3D11.h"
|
||||
#include "mozilla/layers/TextureD3D9.h"
|
||||
#include "mozilla/layers/TextureD3D11.h"
|
||||
|
@ -1055,7 +1056,7 @@ TextureClient::CreateForDrawing(TextureForwarder* aAllocator,
|
|||
aSize.width <= maxTextureSize &&
|
||||
aSize.height <= maxTextureSize &&
|
||||
NS_IsMainThread() &&
|
||||
gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
|
||||
DeviceManagerD3D9::GetDevice()) {
|
||||
data = D3D9TextureData::Create(aSize, aFormat, aAllocFlags);
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ CompositorD3D9::Initialize(nsCString* const out_failureReason)
|
|||
{
|
||||
ScopedGfxFeatureReporter reporter("D3D9 Layers");
|
||||
|
||||
mDeviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
|
||||
mDeviceManager = DeviceManagerD3D9::Get();
|
||||
if (!mDeviceManager) {
|
||||
*out_failureReason = "FEATURE_FAILURE_D3D9_DEVICE_MANAGER";
|
||||
return false;
|
||||
|
@ -648,7 +648,7 @@ CompositorD3D9::Ready()
|
|||
"Shouldn't have any render targets around, they must be released before our device");
|
||||
mSwapChain = nullptr;
|
||||
|
||||
mDeviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
|
||||
mDeviceManager = DeviceManagerD3D9::Get();
|
||||
if (!mDeviceManager) {
|
||||
FailedToResetDevice();
|
||||
mParent->InvalidateRemoteLayers();
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
#include "gfxPlatform.h"
|
||||
#include "gfxWindowsPlatform.h"
|
||||
#include "TextureD3D9.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
#include "mozilla/gfx/Point.h"
|
||||
#include "mozilla/layers/CompositorThread.h"
|
||||
#include "gfxPrefs.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -31,6 +33,23 @@ struct vertex {
|
|||
float x, y;
|
||||
};
|
||||
|
||||
static StaticAutoPtr<mozilla::Mutex> sDeviceManagerLock;
|
||||
static StaticRefPtr<DeviceManagerD3D9> sDeviceManager;
|
||||
|
||||
/* static */ void
|
||||
DeviceManagerD3D9::Init()
|
||||
{
|
||||
MOZ_ASSERT(!sDeviceManagerLock);
|
||||
sDeviceManagerLock = new Mutex("DeviceManagerD3D9.sDeviceManagerLock");
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
DeviceManagerD3D9::Shutdown()
|
||||
{
|
||||
sDeviceManagerLock = nullptr;
|
||||
sDeviceManager = nullptr;
|
||||
}
|
||||
|
||||
SwapChainD3D9::SwapChainD3D9(DeviceManagerD3D9 *aDeviceManager)
|
||||
: mDeviceManager(aDeviceManager)
|
||||
, mWnd(0)
|
||||
|
@ -175,8 +194,50 @@ DeviceManagerD3D9::~DeviceManagerD3D9()
|
|||
DestroyDevice();
|
||||
}
|
||||
|
||||
/* static */ RefPtr<DeviceManagerD3D9>
|
||||
DeviceManagerD3D9::Get()
|
||||
{
|
||||
MutexAutoLock lock(*sDeviceManagerLock);
|
||||
|
||||
bool canCreate =
|
||||
!gfxPlatform::UsesOffMainThreadCompositing() ||
|
||||
CompositorThreadHolder::IsInCompositorThread();
|
||||
if (!sDeviceManager && canCreate) {
|
||||
sDeviceManager = new DeviceManagerD3D9();
|
||||
if (!sDeviceManager->Initialize()) {
|
||||
gfxCriticalError() << "[D3D9] Could not Initialize the DeviceManagerD3D9";
|
||||
sDeviceManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
return sDeviceManager;
|
||||
}
|
||||
|
||||
/* static */ RefPtr<IDirect3DDevice9>
|
||||
DeviceManagerD3D9::GetDevice()
|
||||
{
|
||||
MutexAutoLock lock(*sDeviceManagerLock);
|
||||
return sDeviceManager ? sDeviceManager->device() : nullptr;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
DeviceManagerD3D9::OnDeviceManagerDestroy(DeviceManagerD3D9* aDeviceManager)
|
||||
{
|
||||
if (!sDeviceManagerLock) {
|
||||
// If the device manager has shutdown, we don't care anymore. We can get
|
||||
// here when the compositor shuts down asynchronously.
|
||||
MOZ_ASSERT(!sDeviceManager);
|
||||
return;
|
||||
}
|
||||
|
||||
MutexAutoLock lock(*sDeviceManagerLock);
|
||||
if (aDeviceManager == sDeviceManager) {
|
||||
sDeviceManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
DeviceManagerD3D9::Init()
|
||||
DeviceManagerD3D9::Initialize()
|
||||
{
|
||||
WNDCLASSW wc;
|
||||
HRESULT hr;
|
||||
|
@ -618,7 +679,7 @@ DeviceManagerD3D9::DestroyDevice()
|
|||
if (!IsD3D9Ex()) {
|
||||
ReleaseTextureResources();
|
||||
}
|
||||
gfxWindowsPlatform::GetPlatform()->OnDeviceManagerDestroy(this);
|
||||
DeviceManagerD3D9::OnDeviceManagerDestroy(this);
|
||||
}
|
||||
|
||||
DeviceManagerState
|
||||
|
|
|
@ -132,17 +132,21 @@ private:
|
|||
class DeviceManagerD3D9 final
|
||||
{
|
||||
public:
|
||||
DeviceManagerD3D9();
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DeviceManagerD3D9)
|
||||
|
||||
/**
|
||||
* Initialises the device manager, the underlying device, and everything else
|
||||
* the manager needs.
|
||||
* Returns true if initialisation succeeds, false otherwise.
|
||||
* Note that if initisalisation fails, you cannot try again - you must throw
|
||||
* away the DeviceManagerD3D9 and create a new one.
|
||||
* Setup or tear down static resources needed for D3D9.
|
||||
*/
|
||||
bool Init();
|
||||
static void Init();
|
||||
static void Shutdown();
|
||||
|
||||
/**
|
||||
* Static accessors and helpers for accessing the global DeviceManagerD3D9
|
||||
* instance.
|
||||
*/
|
||||
static RefPtr<DeviceManagerD3D9> Get();
|
||||
static RefPtr<IDirect3DDevice9> GetDevice();
|
||||
static void OnDeviceManagerDestroy(DeviceManagerD3D9* aDeviceManager);
|
||||
|
||||
/**
|
||||
* Sets up the render state for the device for layer rendering.
|
||||
|
@ -216,7 +220,18 @@ public:
|
|||
private:
|
||||
friend class SwapChainD3D9;
|
||||
|
||||
DeviceManagerD3D9();
|
||||
~DeviceManagerD3D9();
|
||||
|
||||
/**
|
||||
* Initialises the device manager, the underlying device, and everything else
|
||||
* the manager needs.
|
||||
* Returns true if initialisation succeeds, false otherwise.
|
||||
* Note that if initisalisation fails, you cannot try again - you must throw
|
||||
* away the DeviceManagerD3D9 and create a new one.
|
||||
*/
|
||||
bool Initialize();
|
||||
|
||||
void DestroyDevice();
|
||||
|
||||
/**
|
||||
|
|
|
@ -341,7 +341,7 @@ DataTextureSourceD3D9::Update(gfx::DataSourceSurface* aSurface,
|
|||
}
|
||||
|
||||
uint32_t bpp = BytesPerPixel(aSurface->GetFormat());
|
||||
RefPtr<DeviceManagerD3D9> deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
|
||||
RefPtr<DeviceManagerD3D9> deviceManager = DeviceManagerD3D9::Get();
|
||||
|
||||
mSize = aSurface->GetSize();
|
||||
mFormat = aSurface->GetFormat();
|
||||
|
@ -575,7 +575,7 @@ D3D9TextureData::Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
|
|||
TextureAllocationFlags aAllocFlags)
|
||||
{
|
||||
_D3DFORMAT format = SurfaceFormatToD3D9Format(aFormat);
|
||||
RefPtr<DeviceManagerD3D9> deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
|
||||
RefPtr<DeviceManagerD3D9> deviceManager = DeviceManagerD3D9::Get();
|
||||
RefPtr<IDirect3DTexture9> d3d9Texture = deviceManager ? deviceManager->CreateTexture(aSize, format,
|
||||
D3DPOOL_SYSTEMMEM,
|
||||
nullptr)
|
||||
|
@ -612,7 +612,7 @@ D3D9TextureData::FillInfo(TextureData::Info& aInfo) const
|
|||
bool
|
||||
D3D9TextureData::Lock(OpenMode aMode, FenceHandle*)
|
||||
{
|
||||
if (!gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
|
||||
if (!DeviceManagerD3D9::GetDevice()) {
|
||||
// If the device has failed then we should not lock the surface,
|
||||
// even if we could.
|
||||
mD3D9Surface = nullptr;
|
||||
|
@ -859,7 +859,7 @@ DataTextureSourceD3D9::UpdateFromTexture(IDirect3DTexture9* aTexture,
|
|||
mSize = IntSize(desc.Width, desc.Height);
|
||||
}
|
||||
|
||||
RefPtr<DeviceManagerD3D9> dm = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
|
||||
RefPtr<DeviceManagerD3D9> dm = DeviceManagerD3D9::Get();
|
||||
if (!dm || !dm->device()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -330,7 +330,6 @@ NS_IMPL_ISUPPORTS(D3DSharedTexturesReporter, nsIMemoryReporter)
|
|||
|
||||
gfxWindowsPlatform::gfxWindowsPlatform()
|
||||
: mRenderMode(RENDER_GDI)
|
||||
, mDeviceLock("gfxWindowsPlatform.mDeviceLock")
|
||||
, mHasDeviceReset(false)
|
||||
, mHasFakeDeviceReset(false)
|
||||
, mHasD3D9DeviceReset(false)
|
||||
|
@ -352,8 +351,8 @@ gfxWindowsPlatform::~gfxWindowsPlatform()
|
|||
{
|
||||
mozilla::gfx::Factory::D2DCleanup();
|
||||
|
||||
DeviceManagerD3D9::Shutdown();
|
||||
DeviceManagerD3D11::Shutdown();
|
||||
mDeviceManager = nullptr;
|
||||
|
||||
/*
|
||||
* Uninitialize COM
|
||||
|
@ -384,6 +383,7 @@ gfxWindowsPlatform::InitAcceleration()
|
|||
mFeatureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
|
||||
|
||||
DeviceManagerD3D11::Init();
|
||||
DeviceManagerD3D9::Init();
|
||||
|
||||
InitializeConfig();
|
||||
InitializeDevices();
|
||||
|
@ -1339,48 +1339,11 @@ gfxWindowsPlatform::SetupClearTypeParams()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
gfxWindowsPlatform::OnDeviceManagerDestroy(DeviceManagerD3D9* aDeviceManager)
|
||||
{
|
||||
if (aDeviceManager == mDeviceManager) {
|
||||
MutexAutoLock lock(mDeviceLock);
|
||||
mDeviceManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
IDirect3DDevice9*
|
||||
gfxWindowsPlatform::GetD3D9Device()
|
||||
{
|
||||
RefPtr<DeviceManagerD3D9> manager = GetD3D9DeviceManager();
|
||||
return manager ? manager->device() : nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
gfxWindowsPlatform::D3D9DeviceReset() {
|
||||
mHasD3D9DeviceReset = true;
|
||||
}
|
||||
|
||||
already_AddRefed<DeviceManagerD3D9>
|
||||
gfxWindowsPlatform::GetD3D9DeviceManager()
|
||||
{
|
||||
// We should only create the d3d9 device on the compositor thread
|
||||
// or we don't have a compositor thread.
|
||||
RefPtr<DeviceManagerD3D9> result;
|
||||
if (!mDeviceManager &&
|
||||
(!gfxPlatform::UsesOffMainThreadCompositing() ||
|
||||
CompositorThreadHolder::IsInCompositorThread())) {
|
||||
mDeviceManager = new DeviceManagerD3D9();
|
||||
if (!mDeviceManager->Init()) {
|
||||
gfxCriticalError() << "[D3D9] Could not Initialize the DeviceManagerD3D9";
|
||||
mDeviceManager = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
MutexAutoLock lock(mDeviceLock);
|
||||
result = mDeviceManager;
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
ReadbackManagerD3D11*
|
||||
gfxWindowsPlatform::GetReadbackManager()
|
||||
{
|
||||
|
|
|
@ -211,9 +211,6 @@ public:
|
|||
{ return mRenderingParams[aRenderMode]; }
|
||||
|
||||
public:
|
||||
void OnDeviceManagerDestroy(mozilla::layers::DeviceManagerD3D9* aDeviceManager);
|
||||
already_AddRefed<mozilla::layers::DeviceManagerD3D9> GetD3D9DeviceManager();
|
||||
IDirect3DDevice9* GetD3D9Device();
|
||||
void D3D9DeviceReset();
|
||||
|
||||
bool DwmCompositionEnabled();
|
||||
|
@ -283,8 +280,6 @@ private:
|
|||
RefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
|
||||
DWRITE_MEASURING_MODE mMeasuringMode;
|
||||
|
||||
mozilla::Mutex mDeviceLock;
|
||||
RefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
|
||||
bool mHasDeviceReset;
|
||||
bool mHasFakeDeviceReset;
|
||||
mozilla::Atomic<bool> mHasD3D9DeviceReset;
|
||||
|
|
Загрузка…
Ссылка в новой задаче