2014-05-01 01:50:00 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "mozilla/layers/SharedBufferManagerParent.h"
|
|
|
|
#include "base/message_loop.h" // for MessageLoop
|
|
|
|
#include "base/process.h" // for ProcessHandle
|
|
|
|
#include "base/process_util.h" // for OpenProcessHandle
|
|
|
|
#include "base/task.h" // for CancelableTask, DeleteTask, etc
|
|
|
|
#include "base/tracked.h" // for FROM_HERE
|
|
|
|
#include "base/thread.h"
|
|
|
|
#include "mozilla/ipc/MessageChannel.h" // for MessageChannel, etc
|
|
|
|
#include "mozilla/ipc/ProtocolUtils.h"
|
|
|
|
#include "mozilla/ipc/Transport.h" // for Transport
|
2014-07-16 20:05:42 +00:00
|
|
|
#include "mozilla/UniquePtr.h" // for UniquePtr
|
2014-05-01 01:50:00 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "ui/PixelFormat.h"
|
|
|
|
#endif
|
2014-06-15 15:27:00 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2014-05-01 01:50:00 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-05-20 20:50:25 +00:00
|
|
|
using namespace android;
|
2014-05-01 01:50:00 +00:00
|
|
|
#endif
|
|
|
|
using std::map;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2014-06-15 15:27:00 +00:00
|
|
|
map<base::ProcessId, SharedBufferManagerParent* > SharedBufferManagerParent::sManagers;
|
|
|
|
StaticAutoPtr<Monitor> SharedBufferManagerParent::sManagerMonitor;
|
2014-07-02 21:45:59 +00:00
|
|
|
uint64_t SharedBufferManagerParent::sBufferKey(0);
|
2014-06-15 15:27:00 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-05-01 01:50:00 +00:00
|
|
|
class GrallocReporter MOZ_FINAL : public nsIMemoryReporter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2014-05-01 01:50:00 +00:00
|
|
|
{
|
2014-07-14 13:35:23 +00:00
|
|
|
if (SharedBufferManagerParent::sManagerMonitor) {
|
|
|
|
SharedBufferManagerParent::sManagerMonitor->Lock();
|
|
|
|
}
|
2014-06-15 15:27:00 +00:00
|
|
|
map<base::ProcessId, SharedBufferManagerParent*>::iterator it;
|
|
|
|
for (it = SharedBufferManagerParent::sManagers.begin(); it != SharedBufferManagerParent::sManagers.end(); it++) {
|
|
|
|
base::ProcessId pid = it->first;
|
|
|
|
SharedBufferManagerParent *mgr = it->second;
|
|
|
|
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mgr->mLock);
|
2014-07-02 21:45:59 +00:00
|
|
|
std::map<int64_t, android::sp<android::GraphicBuffer> >::iterator buf_it;
|
2014-06-15 15:27:00 +00:00
|
|
|
for (buf_it = mgr->mBuffers.begin(); buf_it != mgr->mBuffers.end(); buf_it++) {
|
|
|
|
nsresult rv;
|
|
|
|
android::sp<android::GraphicBuffer> gb = buf_it->second;
|
|
|
|
int bpp = android::bytesPerPixel(gb->getPixelFormat());
|
|
|
|
int stride = gb->getStride();
|
|
|
|
int height = gb->getHeight();
|
|
|
|
int amount = bpp > 0
|
|
|
|
? (stride * height * bpp)
|
|
|
|
// Special case for BSP specific formats (mainly YUV formats, count it as normal YUV buffer).
|
|
|
|
: (stride * height * 3 / 2);
|
|
|
|
|
|
|
|
nsPrintfCString gpath("gralloc/pid(%d)/buffer(width=%d, height=%d, bpp=%d)",
|
|
|
|
pid, gb->getWidth(), height, bpp);
|
|
|
|
|
|
|
|
rv = aHandleReport->Callback(EmptyCString(), gpath, KIND_OTHER, UNITS_BYTES, amount,
|
|
|
|
NS_LITERAL_CSTRING(
|
|
|
|
"Special RAM that can be shared between processes and directly accessed by "
|
|
|
|
"both the CPU and GPU. Gralloc memory is usually a relatively precious "
|
|
|
|
"resource, with much less available than generic RAM. When it's exhausted, "
|
|
|
|
"graphics performance can suffer. This value can be incorrect because of race "
|
|
|
|
"conditions."),
|
|
|
|
aData);
|
|
|
|
if (rv != NS_OK) {
|
2014-07-14 13:35:23 +00:00
|
|
|
if (SharedBufferManagerParent::sManagerMonitor) {
|
|
|
|
SharedBufferManagerParent::sManagerMonitor->Unlock();
|
|
|
|
}
|
2014-06-15 15:27:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 13:35:23 +00:00
|
|
|
if (SharedBufferManagerParent::sManagerMonitor) {
|
|
|
|
SharedBufferManagerParent::sManagerMonitor->Unlock();
|
|
|
|
}
|
2014-06-15 15:27:00 +00:00
|
|
|
return NS_OK;
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(GrallocReporter, nsIMemoryReporter)
|
2014-06-15 15:27:00 +00:00
|
|
|
#endif
|
2014-05-01 01:50:00 +00:00
|
|
|
|
|
|
|
void InitGralloc() {
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
2014-06-15 15:27:00 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2014-05-01 01:50:00 +00:00
|
|
|
RegisterStrongMemoryReporter(new GrallocReporter());
|
2014-06-15 15:27:00 +00:00
|
|
|
#endif
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 20:05:42 +00:00
|
|
|
/**
|
|
|
|
* Task that deletes SharedBufferManagerParent on a specified thread.
|
|
|
|
*/
|
|
|
|
class DeleteSharedBufferManagerParentTask : public Task
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent> aSharedBufferManager)
|
|
|
|
: mSharedBufferManager(Move(aSharedBufferManager)) {
|
|
|
|
}
|
|
|
|
virtual void Run() MOZ_OVERRIDE {}
|
|
|
|
private:
|
|
|
|
UniquePtr<SharedBufferManagerParent> mSharedBufferManager;
|
|
|
|
};
|
|
|
|
|
2014-05-01 01:50:00 +00:00
|
|
|
SharedBufferManagerParent::SharedBufferManagerParent(Transport* aTransport, base::ProcessId aOwner, base::Thread* aThread)
|
|
|
|
: mTransport(aTransport)
|
|
|
|
, mThread(aThread)
|
2014-07-16 20:05:42 +00:00
|
|
|
, mMainMessageLoop(MessageLoop::current())
|
|
|
|
, mDestroyed(false)
|
|
|
|
, mLock("SharedBufferManagerParent.mLock")
|
2014-05-01 01:50:00 +00:00
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-07-08 13:46:17 +00:00
|
|
|
if (!sManagerMonitor) {
|
2014-05-01 01:50:00 +00:00
|
|
|
sManagerMonitor = new Monitor("Manager Monitor");
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
|
|
|
|
MonitorAutoLock lock(*sManagerMonitor.get());
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread");
|
2014-07-08 13:46:17 +00:00
|
|
|
if (!aThread->IsRunning()) {
|
2014-05-01 01:50:00 +00:00
|
|
|
aThread->Start();
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sManagers.count(aOwner) != 0) {
|
|
|
|
printf_stderr("SharedBufferManagerParent already exists.");
|
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
mOwner = aOwner;
|
|
|
|
sManagers[aOwner] = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedBufferManagerParent::~SharedBufferManagerParent()
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(*sManagerMonitor.get());
|
|
|
|
if (mTransport) {
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
|
|
|
new DeleteTask<Transport>(mTransport));
|
|
|
|
}
|
|
|
|
sManagers.erase(mOwner);
|
|
|
|
delete mThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SharedBufferManagerParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
mDestroyed = true;
|
2014-05-01 01:50:00 +00:00
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
|
|
|
mBuffers.clear();
|
|
|
|
#endif
|
2014-07-16 20:05:42 +00:00
|
|
|
DeleteSharedBufferManagerParentTask* task =
|
|
|
|
new DeleteSharedBufferManagerParentTask(UniquePtr<SharedBufferManagerParent>(this));
|
|
|
|
mMainMessageLoop->PostTask(FROM_HERE, task);
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ConnectSharedBufferManagerInParentProcess(SharedBufferManagerParent* aManager,
|
|
|
|
Transport* aTransport,
|
|
|
|
base::ProcessHandle aOtherProcess)
|
|
|
|
{
|
|
|
|
aManager->Open(aTransport, aOtherProcess, XRE_GetIOMessageLoop(), ipc::ParentSide);
|
|
|
|
}
|
|
|
|
|
|
|
|
PSharedBufferManagerParent* SharedBufferManagerParent::Create(Transport* aTransport, ProcessId aOtherProcess)
|
|
|
|
{
|
|
|
|
ProcessHandle processHandle;
|
|
|
|
if (!base::OpenProcessHandle(aOtherProcess, &processHandle)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-07 18:24:14 +00:00
|
|
|
base::Thread* thread = nullptr;
|
2014-07-08 13:46:17 +00:00
|
|
|
char thrname[128];
|
|
|
|
base::snprintf(thrname, 128, "BufMgrParent#%d", aOtherProcess);
|
|
|
|
thread = new base::Thread(thrname);
|
|
|
|
|
2014-05-01 01:50:00 +00:00
|
|
|
SharedBufferManagerParent* manager = new SharedBufferManagerParent(aTransport, aOtherProcess, thread);
|
2014-07-08 13:46:17 +00:00
|
|
|
if (!thread->IsRunning()) {
|
2014-05-01 01:50:00 +00:00
|
|
|
thread->Start();
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
thread->message_loop()->PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(ConnectSharedBufferManagerInParentProcess,
|
|
|
|
manager, aTransport, processHandle));
|
|
|
|
return manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SharedBufferManagerParent::RecvAllocateGrallocBuffer(const IntSize& aSize, const uint32_t& aFormat, const uint32_t& aUsage, mozilla::layers::MaybeMagicGrallocBufferHandle* aHandle)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
2014-05-20 20:50:25 +00:00
|
|
|
|
|
|
|
*aHandle = null_t();
|
|
|
|
|
|
|
|
if (aFormat == 0 || aUsage == 0) {
|
|
|
|
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- format and usage must be non-zero");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the requested size is too big (i.e. exceeds the commonly used max GL texture size)
|
|
|
|
// then we risk OOMing the parent process. It's better to just deny the allocation and
|
|
|
|
// kill the child process, which is what the following code does.
|
|
|
|
// TODO: actually use GL_MAX_TEXTURE_SIZE instead of hardcoding 4096
|
|
|
|
if (aSize.width > 4096 || aSize.height > 4096) {
|
|
|
|
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- requested gralloc buffer is too big.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-01 01:50:00 +00:00
|
|
|
sp<GraphicBuffer> outgoingBuffer = new GraphicBuffer(aSize.width, aSize.height, aFormat, aUsage);
|
2014-05-20 20:50:25 +00:00
|
|
|
if (!outgoingBuffer.get() || outgoingBuffer->initCheck() != NO_ERROR) {
|
|
|
|
printf_stderr("SharedBufferManagerParent::RecvAllocateGrallocBuffer -- gralloc buffer allocation failed");
|
|
|
|
return true;
|
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
|
2014-07-08 13:46:17 +00:00
|
|
|
int64_t bufferKey;
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(*sManagerMonitor.get());
|
|
|
|
bufferKey = ++sBufferKey;
|
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
GrallocBufferRef ref;
|
|
|
|
ref.mOwner = mOwner;
|
2014-07-08 13:46:17 +00:00
|
|
|
ref.mKey = bufferKey;
|
2014-05-01 01:50:00 +00:00
|
|
|
*aHandle = MagicGrallocBufferHandle(outgoingBuffer, ref);
|
|
|
|
|
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2014-07-08 13:46:17 +00:00
|
|
|
mBuffers[bufferKey] = outgoingBuffer;
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SharedBufferManagerParent::RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
|
|
|
NS_ASSERTION(handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef, "We shouldn't interact with the real buffer!");
|
2014-07-02 21:45:59 +00:00
|
|
|
int64_t bufferKey = handle.get_GrallocBufferRef().mKey;
|
2014-05-01 01:50:00 +00:00
|
|
|
sp<GraphicBuffer> buf = GetGraphicBuffer(bufferKey);
|
2014-05-20 20:50:25 +00:00
|
|
|
MOZ_ASSERT(buf.get());
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2014-06-12 06:06:00 +00:00
|
|
|
NS_ASSERTION(mBuffers.count(bufferKey) == 1, "No such buffer");
|
2014-05-01 01:50:00 +00:00
|
|
|
mBuffers.erase(bufferKey);
|
|
|
|
|
2014-05-20 20:50:25 +00:00
|
|
|
if(!buf.get()) {
|
|
|
|
printf_stderr("SharedBufferManagerParent::RecvDropGrallocBuffer -- invalid buffer key.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-01 01:50:00 +00:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:05:42 +00:00
|
|
|
/*static*/
|
2014-05-01 01:50:00 +00:00
|
|
|
void SharedBufferManagerParent::DropGrallocBufferSync(SharedBufferManagerParent* mgr, mozilla::layers::SurfaceDescriptor aDesc)
|
|
|
|
{
|
|
|
|
mgr->DropGrallocBufferImpl(aDesc);
|
|
|
|
}
|
|
|
|
|
2014-07-16 20:05:42 +00:00
|
|
|
/*static*/
|
|
|
|
void SharedBufferManagerParent::DropGrallocBuffer(ProcessId id, mozilla::layers::SurfaceDescriptor aDesc)
|
2014-05-01 01:50:00 +00:00
|
|
|
{
|
2014-07-08 13:46:17 +00:00
|
|
|
if (aDesc.type() != SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
|
2014-05-01 01:50:00 +00:00
|
|
|
return;
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
|
2014-07-16 20:05:42 +00:00
|
|
|
MonitorAutoLock lock(*sManagerMonitor.get());
|
|
|
|
SharedBufferManagerParent* mgr = SharedBufferManagerParent::GetInstance(id);
|
|
|
|
if (!mgr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MutexAutoLock mgrlock(mgr->mLock);
|
|
|
|
if (mgr->mDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlatformThread::CurrentId() == mgr->mThread->thread_id()) {
|
|
|
|
MOZ_CRASH("SharedBufferManagerParent::DropGrallocBuffer should not be called on SharedBufferManagerParent thread");
|
2014-05-01 01:50:00 +00:00
|
|
|
} else {
|
2014-07-16 20:05:42 +00:00
|
|
|
mgr->mThread->message_loop()->PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(&DropGrallocBufferSync, mgr, aDesc));
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedBufferManagerParent::DropGrallocBufferImpl(mozilla::layers::SurfaceDescriptor aDesc)
|
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
|
|
|
if (mDestroyed) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
2014-07-02 21:45:59 +00:00
|
|
|
int64_t key = -1;
|
2014-05-01 01:50:00 +00:00
|
|
|
MaybeMagicGrallocBufferHandle handle;
|
2014-07-08 13:46:17 +00:00
|
|
|
if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
|
2014-05-01 01:50:00 +00:00
|
|
|
handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer();
|
2014-07-08 13:46:17 +00:00
|
|
|
} else {
|
2014-05-01 01:50:00 +00:00
|
|
|
return;
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
|
2014-07-08 13:46:17 +00:00
|
|
|
if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
|
2014-05-01 01:50:00 +00:00
|
|
|
key = handle.get_GrallocBufferRef().mKey;
|
2014-07-08 13:46:17 +00:00
|
|
|
} else if (handle.type() == MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
|
2014-05-01 01:50:00 +00:00
|
|
|
key = handle.get_MagicGrallocBufferHandle().mRef.mKey;
|
2014-07-08 13:46:17 +00:00
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
|
|
|
|
NS_ASSERTION(key != -1, "Invalid buffer key");
|
2014-06-12 06:06:00 +00:00
|
|
|
NS_ASSERTION(mBuffers.count(key) == 1, "No such buffer");
|
2014-05-01 01:50:00 +00:00
|
|
|
mBuffers.erase(key);
|
|
|
|
SendDropGrallocBuffer(handle);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageLoop* SharedBufferManagerParent::GetMessageLoop()
|
|
|
|
{
|
|
|
|
return mThread->message_loop();
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedBufferManagerParent* SharedBufferManagerParent::GetInstance(ProcessId id)
|
|
|
|
{
|
2014-05-01 01:52:00 +00:00
|
|
|
NS_ASSERTION(sManagers.count(id) == 1, "No BufferManager for the process");
|
2014-05-01 01:50:00 +00:00
|
|
|
return sManagers[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
|
|
|
|
android::sp<android::GraphicBuffer>
|
2014-07-02 21:45:59 +00:00
|
|
|
SharedBufferManagerParent::GetGraphicBuffer(int64_t key)
|
2014-05-01 01:50:00 +00:00
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MutexAutoLock lock(mLock);
|
2014-06-12 06:06:00 +00:00
|
|
|
if (mBuffers.count(key) == 1) {
|
|
|
|
return mBuffers[key];
|
2014-07-08 13:46:17 +00:00
|
|
|
} else {
|
2014-06-12 06:06:00 +00:00
|
|
|
// The buffer can be dropped, or invalid
|
2014-07-08 13:46:17 +00:00
|
|
|
printf_stderr("SharedBufferManagerParent::GetGraphicBuffer -- invalid key");
|
2014-06-12 06:06:00 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-01 01:50:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
android::sp<android::GraphicBuffer>
|
|
|
|
SharedBufferManagerParent::GetGraphicBuffer(GrallocBufferRef aRef)
|
|
|
|
{
|
2014-07-16 20:05:42 +00:00
|
|
|
MonitorAutoLock lock(*sManagerMonitor.get());
|
2014-05-01 01:50:00 +00:00
|
|
|
return GetInstance(aRef.mOwner)->GetGraphicBuffer(aRef.mKey);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
IToplevelProtocol*
|
|
|
|
SharedBufferManagerParent::CloneToplevel(const InfallibleTArray<ProtocolFdMapping>& aFds,
|
|
|
|
base::ProcessHandle aPeerProcess,
|
|
|
|
mozilla::ipc::ProtocolCloneContext* aCtx)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < aFds.Length(); i++) {
|
|
|
|
if (aFds[i].protocolId() == unsigned(GetProtocolId())) {
|
|
|
|
Transport* transport = OpenDescriptor(aFds[i].fd(),
|
|
|
|
Transport::MODE_SERVER);
|
|
|
|
PSharedBufferManagerParent* bufferManager = Create(transport, base::GetProcId(aPeerProcess));
|
|
|
|
bufferManager->CloneManagees(this, aCtx);
|
|
|
|
bufferManager->IToplevelProtocol::SetTransport(transport);
|
|
|
|
return bufferManager;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace layers */
|
|
|
|
} /* namespace mozilla */
|