Bug 1363280 - Fix Updating sImageBridges handling r=dvander,nical

This commit is contained in:
sotaro 2017-05-31 09:11:53 +09:00
Родитель 7e3dbfd756
Коммит 9825a21a17
5 изменённых файлов: 34 добавлений и 39 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include "MainThreadUtils.h" #include "MainThreadUtils.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "CompositorBridgeParent.h" #include "CompositorBridgeParent.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/media/MediaSystemResourceService.h" #include "mozilla/media/MediaSystemResourceService.h"
namespace mozilla { namespace mozilla {
@ -105,6 +106,7 @@ CompositorThreadHolder::CreateCompositorThread()
} }
CompositorBridgeParent::Setup(); CompositorBridgeParent::Setup();
ImageBridgeParent::Setup();
return compositorThread; return compositorThread;
} }

Просмотреть файл

@ -10,6 +10,7 @@
#include "base/message_loop.h" // for MessageLoop #include "base/message_loop.h" // for MessageLoop
#include "base/process.h" // for ProcessId #include "base/process.h" // for ProcessId
#include "base/task.h" // for CancelableTask, DeleteTask, etc #include "base/task.h" // for CancelableTask, DeleteTask, etc
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/gfx/Point.h" // for IntSize #include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/Hal.h" // for hal::SetCurrentThreadPriority() #include "mozilla/Hal.h" // for hal::SetCurrentThreadPriority()
#include "mozilla/HalTypes.h" // for hal::THREAD_PRIORITY_COMPOSITOR #include "mozilla/HalTypes.h" // for hal::THREAD_PRIORITY_COMPOSITOR
@ -23,6 +24,7 @@
#include "mozilla/layers/PImageBridgeParent.h" #include "mozilla/layers/PImageBridgeParent.h"
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL #include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
#include "mozilla/layers/Compositor.h" #include "mozilla/layers/Compositor.h"
#include "mozilla/Monitor.h"
#include "mozilla/mozalloc.h" // for operator new, etc #include "mozilla/mozalloc.h" // for operator new, etc
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
#include "nsDebug.h" // for NS_RUNTIMEABORT, etc #include "nsDebug.h" // for NS_RUNTIMEABORT, etc
@ -42,11 +44,21 @@ using namespace mozilla::media;
std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeParent::sImageBridges; std::map<base::ProcessId, ImageBridgeParent*> ImageBridgeParent::sImageBridges;
MessageLoop* ImageBridgeParent::sMainLoop = nullptr; StaticAutoPtr<mozilla::Monitor> sImageBridgesLock;
// defined in CompositorBridgeParent.cpp // defined in CompositorBridgeParent.cpp
CompositorThreadHolder* GetCompositorThreadHolder(); CompositorThreadHolder* GetCompositorThreadHolder();
/* static */ void
ImageBridgeParent::Setup()
{
MOZ_ASSERT(NS_IsMainThread());
if (!sImageBridgesLock) {
sImageBridgesLock = new Monitor("ImageBridges");
mozilla::ClearOnShutdown(&sImageBridgesLock);
}
}
ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop, ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
ProcessId aChildProcessId) ProcessId aChildProcessId)
: mMessageLoop(aLoop) : mMessageLoop(aLoop)
@ -54,17 +66,18 @@ ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop,
, mClosed(false) , mClosed(false)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
sMainLoop = MessageLoop::current();
// creates the map only if it has not been created already, so it is safe // creates the map only if it has not been created already, so it is safe
// with several bridges // with several bridges
sImageBridges[aChildProcessId] = this; {
MonitorAutoLock lock(*sImageBridgesLock);
sImageBridges[aChildProcessId] = this;
}
SetOtherProcessId(aChildProcessId); SetOtherProcessId(aChildProcessId);
} }
ImageBridgeParent::~ImageBridgeParent() ImageBridgeParent::~ImageBridgeParent()
{ {
sImageBridges.erase(OtherPid());
} }
static StaticRefPtr<ImageBridgeParent> sImageBridgeParentSingleton; static StaticRefPtr<ImageBridgeParent> sImageBridgeParentSingleton;
@ -105,7 +118,10 @@ ImageBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
// Can't alloc/dealloc shmems from now on. // Can't alloc/dealloc shmems from now on.
mClosed = true; mClosed = true;
mCompositables.clear(); mCompositables.clear();
{
MonitorAutoLock lock(*sImageBridgesLock);
sImageBridges.erase(OtherPid());
}
MessageLoop::current()->PostTask(NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy)); MessageLoop::current()->PostTask(NewRunnableMethod(this, &ImageBridgeParent::DeferredDestroy));
// It is very important that this method gets called at shutdown (be it a clean // It is very important that this method gets called at shutdown (be it a clean
@ -327,9 +343,11 @@ ImageBridgeParent::DeferredDestroy()
mSelfRef = nullptr; // "this" ImageBridge may get deleted here. mSelfRef = nullptr; // "this" ImageBridge may get deleted here.
} }
ImageBridgeParent* RefPtr<ImageBridgeParent>
ImageBridgeParent::GetInstance(ProcessId aId) ImageBridgeParent::GetInstance(ProcessId aId)
{ {
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
MonitorAutoLock lock(*sImageBridgesLock);
NS_ASSERTION(sImageBridges.count(aId) == 1, "ImageBridgeParent for the process"); NS_ASSERTION(sImageBridges.count(aId) == 1, "ImageBridgeParent for the process");
return sImageBridges[aId]; return sImageBridges[aId];
} }
@ -377,26 +395,6 @@ bool ImageBridgeParent::IsSameProcess() const
return OtherPid() == base::GetCurrentProcId(); return OtherPid() == base::GetCurrentProcId();
} }
/*static*/ void
ImageBridgeParent::SetAboutToSendAsyncMessages(base::ProcessId aChildProcessId)
{
ImageBridgeParent* imageBridge = ImageBridgeParent::GetInstance(aChildProcessId);
if (!imageBridge) {
return;
}
imageBridge->SetAboutToSendAsyncMessages();
}
/*static*/ void
ImageBridgeParent::SendPendingAsyncMessages(base::ProcessId aChildProcessId)
{
ImageBridgeParent* imageBridge = ImageBridgeParent::GetInstance(aChildProcessId);
if (!imageBridge) {
return;
}
imageBridge->SendPendingAsyncMessages();
}
void void
ImageBridgeParent::NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId) ImageBridgeParent::NotifyNotUsed(PTextureParent* aTexture, uint64_t aTransactionId)
{ {

Просмотреть файл

@ -50,6 +50,11 @@ protected:
public: public:
~ImageBridgeParent(); ~ImageBridgeParent();
/**
* Creates the globals of ImageBridgeParent.
*/
static void Setup();
static ImageBridgeParent* CreateSameProcess(); static ImageBridgeParent* CreateSameProcess();
static bool CreateForGPUProcess(Endpoint<PImageBridgeParent>&& aEndpoint); static bool CreateForGPUProcess(Endpoint<PImageBridgeParent>&& aEndpoint);
static bool CreateForContent(Endpoint<PImageBridgeParent>&& aEndpoint); static bool CreateForContent(Endpoint<PImageBridgeParent>&& aEndpoint);
@ -107,13 +112,7 @@ public:
virtual bool IsSameProcess() const override; virtual bool IsSameProcess() const override;
using CompositableParentManager::SetAboutToSendAsyncMessages; static RefPtr<ImageBridgeParent> GetInstance(ProcessId aId);
static void SetAboutToSendAsyncMessages(base::ProcessId aChildProcessId);
using CompositableParentManager::SendPendingAsyncMessages;
static void SendPendingAsyncMessages(base::ProcessId aChildProcessId);
static ImageBridgeParent* GetInstance(ProcessId aId);
static bool NotifyImageComposites(nsTArray<ImageCompositeNotificationInfo>& aNotifications); static bool NotifyImageComposites(nsTArray<ImageCompositeNotificationInfo>& aNotifications);
@ -141,8 +140,6 @@ private:
*/ */
static std::map<base::ProcessId, ImageBridgeParent*> sImageBridges; static std::map<base::ProcessId, ImageBridgeParent*> sImageBridges;
static MessageLoop* sMainLoop;
RefPtr<CompositorThreadHolder> mCompositorThreadHolder; RefPtr<CompositorThreadHolder> mCompositorThreadHolder;
}; };

Просмотреть файл

@ -111,13 +111,11 @@ public:
, mActorsToDestroy(aDestroyActors) , mActorsToDestroy(aDestroyActors)
{ {
mLayerTransaction->SetAboutToSendAsyncMessages(); mLayerTransaction->SetAboutToSendAsyncMessages();
ImageBridgeParent::SetAboutToSendAsyncMessages(mLayerTransaction->GetChildProcessId());
} }
~AutoLayerTransactionParentAsyncMessageSender() ~AutoLayerTransactionParentAsyncMessageSender()
{ {
mLayerTransaction->SendPendingAsyncMessages(); mLayerTransaction->SendPendingAsyncMessages();
ImageBridgeParent::SendPendingAsyncMessages(mLayerTransaction->GetChildProcessId());
if (mActorsToDestroy) { if (mActorsToDestroy) {
// Destroy the actors after sending the async messages because the latter may contain // Destroy the actors after sending the async messages because the latter may contain
// references to some actors. // references to some actors.
@ -409,7 +407,7 @@ LayerTransactionParent::RecvUpdate(const TransactionInfo& aInfo)
} }
case Edit::TOpAttachAsyncCompositable: { case Edit::TOpAttachAsyncCompositable: {
const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable();
ImageBridgeParent* imageBridge = ImageBridgeParent::GetInstance(OtherPid()); RefPtr<ImageBridgeParent> imageBridge = ImageBridgeParent::GetInstance(OtherPid());
if (!imageBridge) { if (!imageBridge) {
return IPC_FAIL_NO_REASON(this); return IPC_FAIL_NO_REASON(this);
} }

Просмотреть файл

@ -641,7 +641,7 @@ WebRenderBridgeParent::RecvAddExternalImageId(const ExternalImageId& aImageId,
MOZ_ASSERT(!mExternalImageIds.Get(wr::AsUint64(aImageId)).get()); MOZ_ASSERT(!mExternalImageIds.Get(wr::AsUint64(aImageId)).get());
ImageBridgeParent* imageBridge = ImageBridgeParent::GetInstance(OtherPid()); RefPtr<ImageBridgeParent> imageBridge = ImageBridgeParent::GetInstance(OtherPid());
if (!imageBridge) { if (!imageBridge) {
return IPC_FAIL_NO_REASON(this); return IPC_FAIL_NO_REASON(this);
} }