Bug 782456, part 0: Add the cross-process ImageBridge glue. r=roc

This commit is contained in:
Chris Jones 2012-08-29 09:24:48 -03:00
parent 7a11d0e803
commit 72c3b33a5d
9 changed files with 117 additions and 16 deletions

View File

@ -27,6 +27,7 @@
#include "mozilla/ipc/XPCShellEnvironment.h"
#include "mozilla/jsipc/PContextWrapperChild.h"
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/PCompositorChild.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/Preferences.h"
@ -416,6 +417,13 @@ ContentChild::AllocPCompositor(mozilla::ipc::Transport* aTransport,
return CompositorChild::Create(aTransport, aOtherProcess);
}
PImageBridgeChild*
ContentChild::AllocPImageBridge(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return ImageBridgeChild::StartUpInChildProcess(aTransport, aOtherProcess);
}
PBrowserChild*
ContentChild::AllocPBrowser(const uint32_t& aChromeFlags,
const bool& aIsBrowserElement, const AppId& aApp)

View File

@ -41,7 +41,6 @@ class ClonedMessageData;
class ContentChild : public PContentChild
{
typedef layers::PCompositorChild PCompositorChild;
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
typedef mozilla::ipc::URIParams URIParams;
@ -70,8 +69,12 @@ public:
return mAppInfo;
}
PCompositorChild* AllocPCompositor(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PCompositorChild*
AllocPCompositor(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PImageBridgeChild*
AllocPImageBridge(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
virtual PBrowserChild* AllocPBrowser(const uint32_t& aChromeFlags,
const bool& aIsBrowserElement,

View File

@ -31,6 +31,7 @@
#include "mozilla/hal_sandbox/PHalParent.h"
#include "mozilla/ipc/TestShellParent.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/net/NeckoParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
@ -695,6 +696,11 @@ ContentParent::ContentParent(const nsAString& aAppManifestURL,
if (useOffMainThreadCompositing) {
DebugOnly<bool> opened = PCompositor::Open(this);
MOZ_ASSERT(opened);
if (Preferences::GetBool("layers.async-video.enabled",false)) {
opened = PImageBridge::Open(this);
MOZ_ASSERT(opened);
}
}
nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
@ -1051,6 +1057,13 @@ ContentParent::AllocPCompositor(mozilla::ipc::Transport* aTransport,
return CompositorParent::Create(aTransport, aOtherProcess);
}
PImageBridgeParent*
ContentParent::AllocPImageBridge(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return ImageBridgeParent::Create(aTransport, aOtherProcess);
}
PBrowserParent*
ContentParent::AllocPBrowser(const uint32_t& aChromeFlags,
const bool& aIsBrowserElement, const AppId& aApp)

View File

@ -56,7 +56,6 @@ class ContentParent : public PContentParent
typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
typedef mozilla::ipc::TestShellParent TestShellParent;
typedef mozilla::ipc::URIParams URIParams;
typedef mozilla::layers::PCompositorParent PCompositorParent;
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
public:
@ -155,8 +154,12 @@ private:
*/
void ShutDownProcess();
PCompositorParent* AllocPCompositor(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PCompositorParent*
AllocPCompositor(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PImageBridgeParent*
AllocPImageBridge(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
virtual PBrowserParent* AllocPBrowser(const uint32_t& aChromeFlags,
const bool& aIsBrowserElement,

View File

@ -12,6 +12,7 @@ include protocol PCrashReporter;
include protocol PExternalHelperApp;
include protocol PDeviceStorageRequest;
include protocol PHal;
include protocol PImageBridge;
include protocol PIndexedDB;
include protocol PMemoryReportRequest;
include protocol PNecko;
@ -153,6 +154,7 @@ struct PrefSetting {
rpc protocol PContent
{
parent opens PCompositor;
parent opens PImageBridge;
manages PAudio;
manages PBlob;
@ -326,4 +328,4 @@ both:
};
}
}
}

View File

@ -3,18 +3,21 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ImageBridgeChild.h"
#include "ImageContainerChild.h"
#include "CompositorParent.h"
#include "ImageBridgeParent.h"
#include "gfxSharedImageSurface.h"
#include "ImageLayers.h"
#include "base/thread.h"
#include "CompositorParent.h"
#include "ImageBridgeChild.h"
#include "ImageBridgeParent.h"
#include "ImageContainerChild.h"
#include "ImageLayers.h"
#include "gfxSharedImageSurface.h"
#include "mozilla/Monitor.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/layers/ShadowLayers.h"
#include "nsXULAppAPI.h"
using namespace base;
using namespace mozilla::ipc;
namespace mozilla {
namespace layers {
@ -144,6 +147,41 @@ void ImageBridgeChild::StartUp()
ImageBridgeChild::StartUpOnThread(new Thread("ImageBridgeChild"));
}
static void
ConnectImageBridgeInChildProcess(Transport* aTransport,
ProcessHandle aOtherProcess)
{
// Bind the IPC channel to the image bridge thread.
sImageBridgeChildSingleton->Open(aTransport, aOtherProcess,
XRE_GetIOMessageLoop(),
AsyncChannel::Child);
}
PImageBridgeChild*
ImageBridgeChild::StartUpInChildProcess(Transport* aTransport,
ProcessId aOtherProcess)
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");
ProcessHandle processHandle;
if (!base::OpenProcessHandle(aOtherProcess, &processHandle)) {
return nullptr;
}
sImageBridgeChildThread = new Thread("ImageBridgeChild");
if (!sImageBridgeChildThread->Start()) {
return nullptr;
}
sImageBridgeChildSingleton = new ImageBridgeChild();
sImageBridgeChildSingleton->GetMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(ConnectImageBridgeInChildProcess,
aTransport, processHandle));
return sImageBridgeChildSingleton;
}
void ImageBridgeChild::ShutDown()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on the main Thread!");

View File

@ -84,6 +84,9 @@ public:
*/
static void StartUp();
static PImageBridgeChild*
StartUpInChildProcess(Transport* aTransport, ProcessId aOtherProcess);
/**
* Destroys the image bridge by calling DestroyBridge, and destroys the
* ImageBridge's thread.

View File

@ -3,12 +3,16 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/thread.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/ImageContainerParent.h"
#include "mozilla/layers/CompositorParent.h"
#include "base/thread.h"
#include "nsTArray.h"
#include "nsXULAppAPI.h"
using namespace base;
using namespace mozilla::ipc;
namespace mozilla {
namespace layers {
@ -25,6 +29,31 @@ ImageBridgeParent::~ImageBridgeParent()
ImageContainerParent::DestroySharedImageMap();
}
static void
ConnectImageBridgeInParentProcess(ImageBridgeParent* aBridge,
Transport* aTransport,
ProcessHandle aOtherProcess)
{
aBridge->Open(aTransport, aOtherProcess,
XRE_GetIOMessageLoop(), AsyncChannel::Parent);
}
/*static*/ PImageBridgeParent*
ImageBridgeParent::Create(Transport* aTransport, ProcessId aOtherProcess)
{
ProcessHandle processHandle;
if (!base::OpenProcessHandle(aOtherProcess, &processHandle)) {
return nullptr;
}
MessageLoop* loop = CompositorParent::CompositorLoop();
ImageBridgeParent* bridge = new ImageBridgeParent(loop);
loop->PostTask(FROM_HERE,
NewRunnableFunction(ConnectImageBridgeInParentProcess,
bridge, aTransport, processHandle));
return bridge;
}
bool ImageBridgeParent::RecvStop()
{
int numChildren = ManagedPImageContainerParent().Length();

View File

@ -23,6 +23,8 @@ public:
ImageBridgeParent(MessageLoop* aLoop);
~ImageBridgeParent();
static PImageBridgeParent*
Create(Transport* aTransport, ProcessId aOtherProcess);
virtual PGrallocBufferParent*
AllocPGrallocBuffer(const gfxIntSize&, const uint32_t&, const uint32_t&,