Bug 1271491: P2. Allow initialization of WMFPlatformDecoderModule from any threads. r?mattwoodrow
This is a very rough and lame attempt at making some parts of gfx thread-safe, however some parts rely on Preferences::AddBoolCache which isn't thread-safe.
Must still be called once gfx has been initialized.
MozReview-Commit-ID: BSpr9cp6USR
--- a/dom/media/platforms/wmf/WMFDecoderModule.cpp
+++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp
@@ -22,17 +22,17 @@
#include "MediaInfo.h"
#include "MediaPrefs.h"
#include "prsystem.h"
#include "mozilla/Maybe.h"
#include "mozilla/StaticMutex.h"
namespace mozilla {
-static bool sDXVAEnabled = false;
+static Atomic<bool> sDXVAEnabled(false);
WMFDecoderModule::WMFDecoderModule()
: mWMFInitialized(false)
{
}
WMFDecoderModule::~WMFDecoderModule()
{
@@ -41,17 +41,16 @@ WMFDecoderModule::~WMFDecoderModule()
NS_ASSERTION(SUCCEEDED(hr), "MFShutdown failed");
}
}
/* static */
void
WMFDecoderModule::Init()
{
- MOZ_ASSERT(NS_IsMainThread(), "Must be on main thread.");
sDXVAEnabled = gfxPlatform::GetPlatform()->CanUseHardwareVideoDecoding();
}
/* static */
int
WMFDecoderModule::GetNumDecoderThreads()
{
int32_t numCores = PR_GetNumberOfProcessors();
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -123,16 +123,17 @@ static const uint32_t kDefaultGlyphCache
#if !defined(USE_SKIA) || !defined(USE_SKIA_GPU)
class mozilla::gl::SkiaGLGlue : public GenericAtomicRefCounted {
};
#endif
#include "mozilla/Preferences.h"
#include "mozilla/Assertions.h"
+#include "mozilla/Atomics.h"
#include "mozilla/Attributes.h"
#include "mozilla/Mutex.h"
#include "nsAlgorithm.h"
#include "nsIGfxInfo.h"
#include "nsIXULRuntime.h"
#include "VsyncSource.h"
#include "SoftwareVsyncSource.h"
@@ -2057,22 +2058,22 @@ gfxPlatform::OptimalFormatForContent(gfx
/**
* There are a number of layers acceleration (or layers in general) preferences
* that should be consistent for the lifetime of the application (bug 840967).
* As such, we will evaluate them all as soon as one of them is evaluated
* and remember the values. Changing these preferences during the run will
* not have any effect until we restart.
*/
bool gANGLESupportsD3D11 = false;
-static bool sLayersSupportsHardwareVideoDecoding = false;
+static mozilla::Atomic<bool> sLayersSupportsHardwareVideoDecoding(false);
static bool sLayersHardwareVideoDecodingFailed = false;
static bool sBufferRotationCheckPref = true;
static bool sPrefBrowserTabsRemoteAutostart = false;
-static bool sLayersAccelerationPrefsInitialized = false;
+static mozilla::Atomic<bool> sLayersAccelerationPrefsInitialized(false);
void
gfxPlatform::InitAcceleration()
{
if (sLayersAccelerationPrefsInitialized) {
return;
}
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -222,17 +222,17 @@ public:
HRESULT& aResOut);
bool DwmCompositionEnabled();
mozilla::layers::ReadbackManagerD3D11* GetReadbackManager();
static bool IsOptimus();
- bool IsWARP() { return mIsWARP; }
+ bool IsWARP() const { return mIsWARP; }
// Returns whether the compositor's D3D11 device supports texture sharing.
bool CompositorD3D11TextureSharingWorks() const {
return mCompositorD3D11TextureSharingWorks;
}
bool SupportsApzWheelInput() const override {
return true;
@@ -325,20 +325,20 @@ private:
DWRITE_MEASURING_MODE mMeasuringMode;
mozilla::Mutex mDeviceLock;
RefPtr<IDXGIAdapter1> mAdapter;
RefPtr<ID3D11Device> mD3D11Device;
RefPtr<ID3D11Device> mD3D11ContentDevice;
RefPtr<ID3D11Device> mD3D11ImageBridgeDevice;
RefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
- bool mIsWARP;
+ mozilla::Atomic<bool> mIsWARP;
bool mHasDeviceReset;
bool mHasFakeDeviceReset;
- bool mCompositorD3D11TextureSharingWorks;
+ mozilla::Atomic<bool> mCompositorD3D11TextureSharingWorks;
mozilla::Atomic<bool> mHasD3D9DeviceReset;
DeviceResetReason mDeviceResetReason;
RefPtr<mozilla::layers::ReadbackManagerD3D11> mD3D11ReadbackManager;
nsTArray<D3D_FEATURE_LEVEL> mFeatureLevels;
};