2012-07-13 12:38:09 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
2012-08-29 05:24:48 -07:00
|
|
|
#include "base/thread.h"
|
|
|
|
|
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2012-07-13 12:38:09 -07:00
|
|
|
#include "mozilla/layers/ImageBridgeParent.h"
|
|
|
|
#include "mozilla/layers/ImageContainerParent.h"
|
|
|
|
#include "nsTArray.h"
|
2012-08-29 05:24:48 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
|
|
|
|
using namespace base;
|
|
|
|
using namespace mozilla::ipc;
|
2012-07-13 12:38:09 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
|
|
|
|
ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop)
|
|
|
|
: mMessageLoop(aLoop)
|
|
|
|
{
|
|
|
|
ImageContainerParent::CreateSharedImageMap();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageBridgeParent::~ImageBridgeParent()
|
|
|
|
{
|
|
|
|
ImageContainerParent::DestroySharedImageMap();
|
|
|
|
}
|
|
|
|
|
2012-08-29 05:24:48 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-13 12:38:09 -07:00
|
|
|
bool ImageBridgeParent::RecvStop()
|
|
|
|
{
|
2012-10-05 13:46:01 -07:00
|
|
|
unsigned int numChildren = ManagedPImageContainerParent().Length();
|
2012-07-13 12:38:09 -07:00
|
|
|
for (unsigned int i = 0; i < numChildren; ++i) {
|
|
|
|
static_cast<ImageContainerParent*>(
|
|
|
|
ManagedPImageContainerParent()[i]
|
|
|
|
)->DoStop();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint64_t GenImageContainerID() {
|
|
|
|
static uint64_t sNextImageID = 1;
|
2012-07-13 12:38:09 -07:00
|
|
|
|
|
|
|
++sNextImageID;
|
|
|
|
return sNextImageID;
|
|
|
|
}
|
|
|
|
|
2012-08-17 03:56:55 -07:00
|
|
|
PGrallocBufferParent*
|
|
|
|
ImageBridgeParent::AllocPGrallocBuffer(const gfxIntSize& aSize,
|
|
|
|
const uint32_t& aFormat,
|
|
|
|
const uint32_t& aUsage,
|
|
|
|
MaybeMagicGrallocBufferHandle* aOutHandle)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
|
|
|
return GrallocBufferActor::Create(aSize, aFormat, aUsage, aOutHandle);
|
|
|
|
#else
|
|
|
|
NS_RUNTIMEABORT("No gralloc buffers for you");
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ImageBridgeParent::DeallocPGrallocBuffer(PGrallocBufferParent* actor)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_RUNTIMEABORT("Um, how did we get here?");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
PImageContainerParent* ImageBridgeParent::AllocPImageContainer(uint64_t* aID)
|
2012-07-13 12:38:09 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t id = GenImageContainerID();
|
2012-07-13 12:38:09 -07:00
|
|
|
*aID = id;
|
2012-08-19 17:07:31 -07:00
|
|
|
return new ImageContainerParent(id);
|
2012-07-13 12:38:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageBridgeParent::DeallocPImageContainer(PImageContainerParent* toDealloc)
|
|
|
|
{
|
|
|
|
delete toDealloc;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageLoop * ImageBridgeParent::GetMessageLoop() {
|
|
|
|
return mMessageLoop;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // layers
|
|
|
|
} // mozilla
|
|
|
|
|