From d1ef6f2696fd1a840444e63198c72ce6829b5f92 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 13 Sep 2016 16:30:56 -0700 Subject: [PATCH] Simplify ImageBridgeChild asynchronous initialization. (bug 1298938 part 2, r=mattwoodrow) --HG-- extra : rebase_source : 1bdb57079ca7f3b4c2be6d1bcd5dd3f0ee0c92c1 --- gfx/layers/ipc/ImageBridgeChild.cpp | 65 ++++++++++++++--------------- gfx/layers/ipc/ImageBridgeChild.h | 11 ++--- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 723f290d4112..316163111f61 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -521,13 +521,6 @@ ImageBridgeChild::CreateCanvasClientSync(SynchronousTask* aTask, *outResult = CreateCanvasClientNow(aType, aFlags); } -static void ConnectImageBridge(ImageBridgeChild * child, ImageBridgeParent * parent) -{ - MessageLoop *parentMsgLoop = parent->GetMessageLoop(); - ipc::MessageChannel *parentChannel = parent->GetIPCChannel(); - child->Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide); -} - ImageBridgeChild::ImageBridgeChild() : mShuttingDown(false) , mFwdTransactionId(0) @@ -872,16 +865,10 @@ void ImageBridgeChild::SendImageBridgeThreadId() { #ifdef MOZ_WIDGET_GONK - SendImageBridgeThreadId(gettid()); + PImageBridgeChild::SendImageBridgeThreadId(gettid()); #endif } -static void CallSendImageBridgeThreadId(ImageBridgeChild* aImageBridgeChild) -{ - MOZ_ASSERT(InImageBridgeChildThread()); - aImageBridgeChild->SendImageBridgeThreadId(); -} - bool ImageBridgeChild::InitForContent(Endpoint&& aEndpoint) { @@ -894,22 +881,37 @@ ImageBridgeChild::InitForContent(Endpoint&& aEndpoint) return false; } - sImageBridgeChildSingleton = new ImageBridgeChild(); + RefPtr child = new ImageBridgeChild(); - MessageLoop* loop = sImageBridgeChildSingleton->GetMessageLoop(); + sImageBridgeChildSingleton = child; - loop->PostTask(NewRunnableMethod&&>( - sImageBridgeChildSingleton, &ImageBridgeChild::Bind, Move(aEndpoint))); - loop->PostTask(NewRunnableFunction( - CallSendImageBridgeThreadId, sImageBridgeChildSingleton.get())); + RefPtr runnable = NewRunnableMethod&&>( + child, + &ImageBridgeChild::Bind, + Move(aEndpoint)); + child->GetMessageLoop()->PostTask(runnable.forget()); - return sImageBridgeChildSingleton; + return true; } void ImageBridgeChild::Bind(Endpoint&& aEndpoint) { - aEndpoint.Bind(this); + if (!aEndpoint.Bind(this)) { + return; + } + + SendImageBridgeThreadId(); +} + +void +ImageBridgeChild::BindSameProcess(RefPtr aParent) +{ + MessageLoop *parentMsgLoop = aParent->GetMessageLoop(); + ipc::MessageChannel *parentChannel = aParent->GetIPCChannel(); + Open(parentChannel, parentMsgLoop, mozilla::ipc::ChildSide); + + SendImageBridgeThreadId(); } void ImageBridgeChild::ShutDown() @@ -959,13 +961,16 @@ ImageBridgeChild::InitSameProcess() sImageBridgeChildThread->Start(); } - sImageBridgeChildSingleton = new ImageBridgeChild(); + RefPtr child = new ImageBridgeChild(); RefPtr parent = ImageBridgeParent::CreateSameProcess(); - sImageBridgeChildSingleton->ConnectAsync(parent); - sImageBridgeChildSingleton->GetMessageLoop()->PostTask( - NewRunnableFunction(CallSendImageBridgeThreadId, - sImageBridgeChildSingleton.get())); + sImageBridgeChildSingleton = child; + + RefPtr runnable = WrapRunnable( + child, + &ImageBridgeChild::BindSameProcess, + parent); + child->GetMessageLoop()->PostTask(runnable.forget()); } /* static */ void @@ -998,12 +1003,6 @@ MessageLoop * ImageBridgeChild::GetMessageLoop() const return sImageBridgeChildThread ? sImageBridgeChildThread->message_loop() : nullptr; } -void ImageBridgeChild::ConnectAsync(ImageBridgeParent* aParent) -{ - GetMessageLoop()->PostTask(NewRunnableFunction(&ConnectImageBridge, - this, aParent)); -} - void ImageBridgeChild::IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier) { diff --git a/gfx/layers/ipc/ImageBridgeChild.h b/gfx/layers/ipc/ImageBridgeChild.h index 4e47439aa6b2..af131a93db6c 100644 --- a/gfx/layers/ipc/ImageBridgeChild.h +++ b/gfx/layers/ipc/ImageBridgeChild.h @@ -160,14 +160,6 @@ public: static ImageBridgeChild* GetSingleton(); - /** - * Dispatches a task to the ImageBridgeChild thread to do the connection - */ - void ConnectAsync(ImageBridgeParent* aParent); - - using PImageBridgeChild::SendImageBridgeThreadId; - void SendImageBridgeThreadId(); - static void IdentifyCompositorTextureHost(const TextureFactoryIdentifier& aIdentifier); void BeginTransaction(); @@ -402,6 +394,9 @@ protected: bool aUnsafe); void Bind(Endpoint&& aEndpoint); + void BindSameProcess(RefPtr aParent); + + void SendImageBridgeThreadId(); private: CompositableTransaction* mTxn;