зеркало из https://github.com/mozilla/gecko-dev.git
Protect ImageBridgeChild's singleton with a StaticMutex. (bug 1298938 part 5, r=mattwoodrow)
--HG-- extra : rebase_source : ca2adf8e3a11e35633fdafd8a824e6528a3b7182
This commit is contained in:
Родитель
91559fcffe
Коммит
dfe373c79e
|
@ -428,7 +428,7 @@ D3D9DXVA2Manager::Init(nsACString& aFailureReason)
|
|||
mDeviceManager = deviceManager;
|
||||
mSyncSurface = syncSurf;
|
||||
|
||||
mTextureClientAllocator = new D3D9RecycleAllocator(layers::ImageBridgeChild::GetSingleton(),
|
||||
mTextureClientAllocator = new D3D9RecycleAllocator(layers::ImageBridgeChild::GetSingleton().get(),
|
||||
mDevice);
|
||||
mTextureClientAllocator->SetMaxPoolSize(5);
|
||||
|
||||
|
@ -752,7 +752,7 @@ D3D11DXVA2Manager::Init(nsACString& aFailureReason)
|
|||
hr = mDevice->CreateTexture2D(&desc, NULL, getter_AddRefs(mSyncSurface));
|
||||
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
|
||||
|
||||
mTextureClientAllocator = new D3D11RecycleAllocator(layers::ImageBridgeChild::GetSingleton(),
|
||||
mTextureClientAllocator = new D3D11RecycleAllocator(layers::ImageBridgeChild::GetSingleton().get(),
|
||||
mDevice);
|
||||
mTextureClientAllocator->SetMaxPoolSize(5);
|
||||
|
||||
|
|
|
@ -677,7 +677,7 @@ PluginInstanceParent::RecvInitDXGISurface(const gfx::SurfaceFormat& format,
|
|||
return true;
|
||||
}
|
||||
|
||||
ImageBridgeChild* forwarder = ImageBridgeChild::GetSingleton();
|
||||
RefPtr<ImageBridgeChild> forwarder = ImageBridgeChild::GetSingleton();
|
||||
if (!forwarder) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3129,7 +3129,7 @@ layers::TextureClientRecycleAllocator*
|
|||
PluginModuleParent::EnsureTextureAllocator()
|
||||
{
|
||||
if (!mTextureAllocator) {
|
||||
mTextureAllocator = new TextureClientRecycleAllocator(ImageBridgeChild::GetSingleton());
|
||||
mTextureAllocator = new TextureClientRecycleAllocator(ImageBridgeChild::GetSingleton().get());
|
||||
}
|
||||
return mTextureAllocator;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "nsTArrayForwardDeclare.h" // for AutoTArray
|
||||
#include "nsThreadUtils.h" // for NS_IsMainThread
|
||||
#include "nsXULAppAPI.h" // for XRE_GetIOMessageLoop
|
||||
#include "mozilla/StaticMutex.h"
|
||||
#include "mozilla/StaticPtr.h" // for StaticRefPtr
|
||||
#include "mozilla/layers/TextureClient.h"
|
||||
|
||||
|
@ -390,6 +391,7 @@ ImageBridgeChild::CancelWaitForRecycle(uint64_t aTextureId)
|
|||
}
|
||||
|
||||
// Singleton
|
||||
static StaticMutex sImageBridgeSingletonLock;
|
||||
static StaticRefPtr<ImageBridgeChild> sImageBridgeChildSingleton;
|
||||
static Thread *sImageBridgeChildThread = nullptr;
|
||||
|
||||
|
@ -598,8 +600,10 @@ Thread* ImageBridgeChild::GetThread() const
|
|||
return sImageBridgeChildThread;
|
||||
}
|
||||
|
||||
ImageBridgeChild* ImageBridgeChild::GetSingleton()
|
||||
/* static */ RefPtr<ImageBridgeChild>
|
||||
ImageBridgeChild::GetSingleton()
|
||||
{
|
||||
StaticMutexAutoLock lock(sImageBridgeSingletonLock);
|
||||
return sImageBridgeChildSingleton;
|
||||
}
|
||||
|
||||
|
@ -880,14 +884,18 @@ ImageBridgeChild::InitForContent(Endpoint<PImageBridgeChild>&& aEndpoint)
|
|||
|
||||
RefPtr<ImageBridgeChild> child = new ImageBridgeChild();
|
||||
|
||||
sImageBridgeChildSingleton = child;
|
||||
|
||||
RefPtr<Runnable> runnable = NewRunnableMethod<Endpoint<PImageBridgeChild>&&>(
|
||||
child,
|
||||
&ImageBridgeChild::Bind,
|
||||
Move(aEndpoint));
|
||||
child->GetMessageLoop()->PostTask(runnable.forget());
|
||||
|
||||
// Assign this after so other threads can't post messages before we connect to IPDL.
|
||||
{
|
||||
StaticMutexAutoLock lock(sImageBridgeSingletonLock);
|
||||
sImageBridgeChildSingleton = child;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -922,6 +930,7 @@ void ImageBridgeChild::ShutDown()
|
|||
if (RefPtr<ImageBridgeChild> child = GetSingleton()) {
|
||||
child->WillShutdown();
|
||||
|
||||
StaticMutexAutoLock lock(sImageBridgeSingletonLock);
|
||||
sImageBridgeChildSingleton = nullptr;
|
||||
}
|
||||
|
||||
|
@ -978,13 +987,17 @@ ImageBridgeChild::InitSameProcess()
|
|||
RefPtr<ImageBridgeChild> child = new ImageBridgeChild();
|
||||
RefPtr<ImageBridgeParent> parent = ImageBridgeParent::CreateSameProcess();
|
||||
|
||||
sImageBridgeChildSingleton = child;
|
||||
|
||||
RefPtr<Runnable> runnable = WrapRunnable(
|
||||
child,
|
||||
&ImageBridgeChild::BindSameProcess,
|
||||
parent);
|
||||
child->GetMessageLoop()->PostTask(runnable.forget());
|
||||
|
||||
// Assign this after so other threads can't post messages before we connect to IPDL.
|
||||
{
|
||||
StaticMutexAutoLock lock(sImageBridgeSingletonLock);
|
||||
sImageBridgeChildSingleton = child;
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
|
@ -999,11 +1012,17 @@ ImageBridgeChild::InitWithGPUProcess(Endpoint<PImageBridgeChild>&& aEndpoint)
|
|||
sImageBridgeChildThread->Start();
|
||||
}
|
||||
|
||||
sImageBridgeChildSingleton = new ImageBridgeChild();
|
||||
RefPtr<ImageBridgeChild> child = new ImageBridgeChild();
|
||||
|
||||
MessageLoop* loop = sImageBridgeChildSingleton->GetMessageLoop();
|
||||
MessageLoop* loop = child->GetMessageLoop();
|
||||
loop->PostTask(NewRunnableMethod<Endpoint<PImageBridgeChild>&&>(
|
||||
sImageBridgeChildSingleton, &ImageBridgeChild::Bind, Move(aEndpoint)));
|
||||
child, &ImageBridgeChild::Bind, Move(aEndpoint)));
|
||||
|
||||
// Assign this after so other threads can't post messages before we connect to IPDL.
|
||||
{
|
||||
StaticMutexAutoLock lock(sImageBridgeSingletonLock);
|
||||
sImageBridgeChildSingleton = child;
|
||||
}
|
||||
}
|
||||
|
||||
bool InImageBridgeChildThread()
|
||||
|
@ -1017,11 +1036,11 @@ MessageLoop * ImageBridgeChild::GetMessageLoop() const
|
|||
return sImageBridgeChildThread ? sImageBridgeChildThread->message_loop() : nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
/* static */ void
|
||||
ImageBridgeChild::IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier)
|
||||
{
|
||||
if (sImageBridgeChildSingleton) {
|
||||
sImageBridgeChildSingleton->IdentifyTextureHost(aIdentifier);
|
||||
if (RefPtr<ImageBridgeChild> child = GetSingleton()) {
|
||||
child->IdentifyTextureHost(aIdentifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
*
|
||||
* can be called from any thread.
|
||||
*/
|
||||
static ImageBridgeChild* GetSingleton();
|
||||
static RefPtr<ImageBridgeChild> GetSingleton();
|
||||
|
||||
|
||||
static void IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier);
|
||||
|
|
Загрузка…
Ссылка в новой задаче