Backed out changeset a89f08f4fd3e (bug 959089)

This commit is contained in:
Carsten "Tomcat" Book 2014-04-29 12:21:52 +02:00
parent 8e6bf98035
commit 201692bdbe
36 changed files with 661 additions and 254 deletions

View File

@ -29,7 +29,6 @@
#include "mozilla/ipc/TestShellChild.h"
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/PCompositorChild.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/Preferences.h"
@ -689,13 +688,6 @@ ContentChild::AllocPCompositorChild(mozilla::ipc::Transport* aTransport,
return CompositorChild::Create(aTransport, aOtherProcess);
}
PSharedBufferManagerChild*
ContentChild::AllocPSharedBufferManagerChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return SharedBufferManagerChild::StartUpInChildProcess(aTransport, aOtherProcess);
}
PImageBridgeChild*
ContentChild::AllocPImageBridgeChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)

View File

@ -89,11 +89,6 @@ public:
PCompositorChild*
AllocPCompositorChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PSharedBufferManagerChild*
AllocPSharedBufferManagerChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PImageBridgeChild*
AllocPImageBridgeChild(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;

View File

@ -54,7 +54,6 @@
#include "mozilla/ipc/InputStreamUtils.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeParent.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/net/NeckoParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
@ -1596,10 +1595,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority,
}
}
}
#ifdef MOZ_WIDGET_GONK
DebugOnly<bool> opened = PSharedBufferManager::Open(this);
MOZ_ASSERT(opened);
#endif
if (aSendRegisteredChrome) {
nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
@ -2197,13 +2192,6 @@ ContentParent::AllocPBackgroundParent(Transport* aTransport,
return BackgroundParent::Alloc(this, aTransport, aOtherProcess);
}
PSharedBufferManagerParent*
ContentParent::AllocPSharedBufferManagerParent(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess)
{
return SharedBufferManagerParent::Create(aTransport, aOtherProcess);
}
bool
ContentParent::RecvGetProcessAttributes(uint64_t* aId,
bool* aIsForApp, bool* aIsForBrowser)

View File

@ -47,7 +47,6 @@ class PJavaScriptParent;
namespace layers {
class PCompositorParent;
class PSharedBufferManagerParent;
} // namespace layers
namespace dom {
@ -328,9 +327,6 @@ private:
AllocPImageBridgeParent(mozilla::ipc::Transport* aTransport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PSharedBufferManagerParent*
AllocPSharedBufferManagerParent(mozilla::ipc::Transport* aTranport,
base::ProcessId aOtherProcess) MOZ_OVERRIDE;
PBackgroundParent*
AllocPBackgroundParent(Transport* aTransport, ProcessId aOtherProcess)
MOZ_OVERRIDE;

View File

@ -21,7 +21,6 @@ include protocol PImageBridge;
include protocol PIndexedDB;
include protocol PMemoryReportRequest;
include protocol PNecko;
include protocol PSharedBufferManager;
include protocol PSms;
include protocol PSpeechSynthesis;
include protocol PStorage;
@ -264,7 +263,6 @@ struct PrefSetting {
intr protocol PContent
{
parent opens PCompositor;
parent opens PSharedBufferManager;
parent opens PImageBridge;
child opens PBackground;

View File

@ -81,10 +81,6 @@ public:
HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04,
};
enum {
GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK,
};
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
@ -102,11 +98,6 @@ public:
return static_cast<uint8_t*>(GetNativeBuffer());
}
int GetUsage()
{
return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
}
private:
RefPtr<GrallocTextureClientOGL> mTextureClient;
};

View File

@ -16,7 +16,6 @@
#include "mozilla/RefPtr.h" // for RefPtr
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/ContentHost.h" // for ContentHostBase
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG

View File

@ -14,7 +14,6 @@
#include "mozilla/Atomics.h" // for PrimitiveIntrinsics
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "ShadowLayerUtils.h"
#include "mozilla/mozalloc.h" // for operator delete[], etc
#include "nsAutoPtr.h" // for nsRefPtr, getter_AddRefs, etc
@ -309,20 +308,5 @@ ISurfaceAllocator::ShrinkShmemSectionHeap()
}
}
bool
ISurfaceAllocator::AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle)
{
return SharedBufferManagerChild::GetSingleton()->AllocGrallocBuffer(aSize, aFormat, aUsage, aHandle);
}
void
ISurfaceAllocator::DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle)
{
SharedBufferManagerChild::GetSingleton()->DeallocGrallocBuffer(*aHandle);
}
} // namespace
} // namespace

View File

@ -46,6 +46,7 @@ class DataSourceSurface;
namespace layers {
class PGrallocBufferChild;
class MaybeMagicGrallocBufferHandle;
class MemoryTextureClient;
class MemoryTextureHost;
@ -154,12 +155,18 @@ public:
virtual void DestroySharedSurface(SurfaceDescriptor* aSurface);
// method that does the actual allocation work
bool AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle);
virtual PGrallocBufferChild* AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle)
{
return nullptr;
}
void DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle);
virtual void DeallocGrallocBuffer(PGrallocBufferChild* aChild)
{
NS_RUNTIMEABORT("should not be called");
}
virtual bool IPCOpen() const { return true; }
virtual bool IsSameProcess() const = 0;

View File

@ -52,6 +52,7 @@ class Shmem;
namespace layers {
class PGrallocBufferChild;
typedef std::vector<CompositableOperation> OpVector;
struct CompositableTransaction
@ -203,6 +204,44 @@ static void CreateImageClientSync(RefPtr<ImageClient>* result,
barrier->NotifyAll();
}
struct GrallocParam {
IntSize size;
uint32_t format;
uint32_t usage;
MaybeMagicGrallocBufferHandle* handle;
PGrallocBufferChild** child;
GrallocParam(const IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
MaybeMagicGrallocBufferHandle* aHandle,
PGrallocBufferChild** aChild)
: size(aSize)
, format(aFormat)
, usage(aUsage)
, handle(aHandle)
, child(aChild)
{}
};
// dispatched function
static void AllocGrallocBufferSync(const GrallocParam& aParam,
Monitor* aBarrier,
bool* aDone)
{
MonitorAutoLock autoMon(*aBarrier);
sImageBridgeChildSingleton->AllocGrallocBufferNow(aParam.size,
aParam.format,
aParam.usage,
aParam.handle,
aParam.child);
*aDone = true;
aBarrier->NotifyAll();
}
// dispatched function
static void ConnectImageBridge(ImageBridgeChild * child, ImageBridgeParent * parent)
{
MessageLoop *parentMsgLoop = parent->GetMessageLoop();
@ -616,6 +655,30 @@ ImageBridgeChild::CreateImageClientNow(CompositableType aType)
return client.forget();
}
PGrallocBufferChild*
ImageBridgeChild::AllocPGrallocBufferChild(const IntSize&, const uint32_t&, const uint32_t&,
MaybeMagicGrallocBufferHandle*)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
return GrallocBufferActor::Create();
#else
NS_RUNTIMEABORT("No gralloc buffers for you");
return nullptr;
#endif
}
bool
ImageBridgeChild::DeallocPGrallocBufferChild(PGrallocBufferChild* actor)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
delete actor;
return true;
#else
NS_RUNTIMEABORT("Um, how did we get here?");
return false;
#endif
}
bool
ImageBridgeChild::AllocUnsafeShmem(size_t aSize,
ipc::SharedMemory::SharedMemoryType aType,
@ -737,6 +800,99 @@ ImageBridgeChild::DeallocShmem(ipc::Shmem& aShmem)
}
}
PGrallocBufferChild*
ImageBridgeChild::AllocGrallocBuffer(const IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle)
{
if (InImageBridgeChildThread()) {
PGrallocBufferChild* child = nullptr;
ImageBridgeChild::AllocGrallocBufferNow(aSize, aFormat, aUsage, aHandle, &child);
return child;
}
Monitor barrier("AllocGrallocBuffer Lock");
MonitorAutoLock autoMon(barrier);
bool done = false;
PGrallocBufferChild* child = nullptr;
GetMessageLoop()->PostTask(
FROM_HERE,
NewRunnableFunction(&AllocGrallocBufferSync,
GrallocParam(aSize, aFormat, aUsage, aHandle, &child), &barrier, &done));
while (!done) {
barrier.Wait();
}
return child;
}
void
ImageBridgeChild::AllocGrallocBufferNow(const gfx::IntSize& aSize,
uint32_t aFormat, uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle,
PGrallocBufferChild** aChild)
{
#ifdef MOZ_WIDGET_GONK
*aChild = SendPGrallocBufferConstructor(aSize,
aFormat,
aUsage,
aHandle);
#else
NS_RUNTIMEABORT("not implemented");
aChild = nullptr;
#endif
}
static void ProxyDeallocGrallocBufferNow(ISurfaceAllocator* aAllocator,
PGrallocBufferChild* aChild,
ReentrantMonitor* aBarrier,
bool* aDone)
{
MOZ_ASSERT(aChild);
MOZ_ASSERT(aDone);
MOZ_ASSERT(aBarrier);
#ifdef MOZ_WIDGET_GONK
PGrallocBufferChild::Send__delete__(aChild);
#else
NS_RUNTIMEABORT("not implemented");
#endif
ReentrantMonitorAutoEnter autoMon(*aBarrier);
*aDone = true;
aBarrier->NotifyAll();
}
void
ImageBridgeChild::DeallocGrallocBuffer(PGrallocBufferChild* aChild)
{
MOZ_ASSERT(aChild);
if (InImageBridgeChildThread()) {
#ifdef MOZ_WIDGET_GONK
PGrallocBufferChild::Send__delete__(aChild);
#else
NS_RUNTIMEABORT("not implemented");
#endif
} else {
ReentrantMonitor barrier("AllocatorProxy Dealloc");
ReentrantMonitorAutoEnter autoMon(barrier);
bool done = false;
GetMessageLoop()->PostTask(FROM_HERE,
NewRunnableFunction(&ProxyDeallocGrallocBufferNow,
this,
aChild,
&barrier,
&done));
while (!done) {
barrier.Wait();
}
}
}
PTextureChild*
ImageBridgeChild::AllocPTextureChild(const SurfaceDescriptor&,
const TextureFlags&)

View File

@ -13,6 +13,7 @@
#include "mozilla/ipc/SharedMemory.h" // for SharedMemory, etc
#include "mozilla/layers/CompositableForwarder.h"
#include "mozilla/layers/CompositorTypes.h" // for TextureIdentifier, etc
#include "mozilla/layers/LayersSurfaces.h" // for PGrallocBufferChild
#include "mozilla/layers/PImageBridgeChild.h"
#include "nsDebug.h" // for NS_RUNTIMEABORT
#include "nsRegion.h" // for nsIntRegion
@ -186,6 +187,13 @@ public:
*/
~ImageBridgeChild();
virtual PGrallocBufferChild*
AllocPGrallocBufferChild(const gfx::IntSize&, const uint32_t&, const uint32_t&,
MaybeMagicGrallocBufferHandle*) MOZ_OVERRIDE;
virtual bool
DeallocPGrallocBufferChild(PGrallocBufferChild* actor) MOZ_OVERRIDE;
virtual PTextureChild*
AllocPTextureChild(const SurfaceDescriptor& aSharedData, const TextureFlags& aFlags) MOZ_OVERRIDE;
@ -302,6 +310,10 @@ public:
virtual bool IsSameProcess() const MOZ_OVERRIDE;
void AllocGrallocBufferNow(const gfx::IntSize& aSize,
uint32_t aFormat, uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle,
PGrallocBufferChild** aChild);
protected:
ImageBridgeChild();
bool DispatchAllocShmemInternal(size_t aSize,
@ -310,6 +322,13 @@ protected:
bool aUnsafe);
CompositableTransaction* mTxn;
// ISurfaceAllocator
virtual PGrallocBufferChild* AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat, uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle) MOZ_OVERRIDE;
virtual void DeallocGrallocBuffer(PGrallocBufferChild* aChild) MOZ_OVERRIDE;
};
} // layers

View File

@ -12,7 +12,7 @@
#include "base/process_util.h" // for OpenProcessHandle
#include "base/task.h" // for CancelableTask, DeleteTask, etc
#include "base/tracked.h" // for FROM_HERE
#include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/ipc/MessageChannel.h" // for MessageChannel, etc
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/Transport.h" // for Transport
@ -40,6 +40,8 @@ using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
class PGrallocBufferParent;
ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop, Transport* aTransport)
: mMessageLoop(aLoop)
, mTransport(aTransport)
@ -159,6 +161,32 @@ static uint64_t GenImageContainerID() {
return sNextImageID;
}
PGrallocBufferParent*
ImageBridgeParent::AllocPGrallocBufferParent(const IntSize& 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::DeallocPGrallocBufferParent(PGrallocBufferParent* actor)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
delete actor;
return true;
#else
NS_RUNTIMEABORT("Um, how did we get here?");
return false;
#endif
}
PCompositableParent*
ImageBridgeParent::AllocPCompositableParent(const TextureInfo& aInfo,
uint64_t* aID)

View File

@ -20,10 +20,6 @@
class MessageLoop;
namespace base {
class Thread;
}
namespace mozilla {
namespace ipc {
class Shmem;
@ -53,6 +49,13 @@ public:
static PImageBridgeParent*
Create(Transport* aTransport, ProcessId aOtherProcess);
virtual PGrallocBufferParent*
AllocPGrallocBufferParent(const IntSize&, const uint32_t&, const uint32_t&,
MaybeMagicGrallocBufferHandle*) MOZ_OVERRIDE;
virtual bool
DeallocPGrallocBufferParent(PGrallocBufferParent* actor) MOZ_OVERRIDE;
// PImageBridge
virtual bool RecvUpdate(const EditArray& aEdits, EditReplyArray* aReply) MOZ_OVERRIDE;
virtual bool RecvUpdateNoSwap(const EditArray& aEdits) MOZ_OVERRIDE;

View File

@ -7,6 +7,7 @@
#include "LayerTransactionChild.h"
#include "mozilla/layers/CompositableClient.h" // for CompositableChild
#include "mozilla/layers/LayersSurfaces.h" // for PGrallocBufferChild
#include "mozilla/layers/PCompositableChild.h" // for PCompositableChild
#include "mozilla/layers/PLayerChild.h" // for PLayerChild
#include "mozilla/mozalloc.h" // for operator delete, etc
@ -17,6 +18,7 @@
namespace mozilla {
namespace layers {
class PGrallocBufferChild;
void
LayerTransactionChild::Destroy()
@ -27,6 +29,31 @@ LayerTransactionChild::Destroy()
// WARNING: |this| has gone to the great heap in the sky
}
PGrallocBufferChild*
LayerTransactionChild::AllocPGrallocBufferChild(const IntSize&,
const uint32_t&,
const uint32_t&,
MaybeMagicGrallocBufferHandle*)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
return GrallocBufferActor::Create();
#else
NS_RUNTIMEABORT("No gralloc buffers for you");
return nullptr;
#endif
}
bool
LayerTransactionChild::DeallocPGrallocBufferChild(PGrallocBufferChild* actor)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
delete actor;
return true;
#else
NS_RUNTIMEABORT("Um, how did we get here?");
return false;
#endif
}
PLayerChild*
LayerTransactionChild::AllocPLayerChild()

View File

@ -43,6 +43,13 @@ protected:
{}
~LayerTransactionChild() { }
virtual PGrallocBufferChild*
AllocPGrallocBufferChild(const IntSize&,
const uint32_t&, const uint32_t&,
MaybeMagicGrallocBufferHandle*) MOZ_OVERRIDE;
virtual bool
DeallocPGrallocBufferChild(PGrallocBufferChild* actor) MOZ_OVERRIDE;
virtual PLayerChild* AllocPLayerChild() MOZ_OVERRIDE;
virtual bool DeallocPLayerChild(PLayerChild* actor) MOZ_OVERRIDE;

View File

@ -740,6 +740,33 @@ LayerTransactionParent::RecvForceComposite()
return true;
}
PGrallocBufferParent*
LayerTransactionParent::AllocPGrallocBufferParent(const IntSize& 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
LayerTransactionParent::DeallocPGrallocBufferParent(PGrallocBufferParent* actor)
{
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
delete actor;
return true;
#else
NS_RUNTIMEABORT("Um, how did we get here?");
return false;
#endif
}
PLayerParent*
LayerTransactionParent::AllocPLayerParent()
{

View File

@ -103,6 +103,13 @@ protected:
virtual bool RecvSetAsyncScrollOffset(PLayerParent* aLayer,
const int32_t& aX, const int32_t& aY) MOZ_OVERRIDE;
virtual PGrallocBufferParent*
AllocPGrallocBufferParent(const IntSize& aSize,
const uint32_t& aFormat, const uint32_t& aUsage,
MaybeMagicGrallocBufferHandle* aOutHandle) MOZ_OVERRIDE;
virtual bool
DeallocPGrallocBufferParent(PGrallocBufferParent* actor) MOZ_OVERRIDE;
virtual PLayerParent* AllocPLayerParent() MOZ_OVERRIDE;
virtual bool DeallocPLayerParent(PLayerParent* actor) MOZ_OVERRIDE;

View File

@ -8,6 +8,7 @@
include LayersSurfaces;
include protocol PCompositable;
include protocol PCompositor;
include protocol PGrallocBuffer;
include protocol PLayer;
include protocol PRenderFrame;
include protocol PTexture;

View File

@ -2,12 +2,14 @@
* 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 protocol PGrallocBuffer;
using struct gfxPoint from "gfxPoint.h";
using struct nsIntRect from "nsRect.h";
using nsIntRegion from "nsRegion.h";
using struct nsIntSize from "nsSize.h";
using struct mozilla::layers::MagicGrallocBufferHandle from "gfxipc/ShadowLayerUtils.h";
using struct mozilla::layers::GrallocBufferRef from "gfxipc/ShadowLayerUtils.h";
using struct mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
@ -23,7 +25,6 @@ namespace layers {
union MaybeMagicGrallocBufferHandle {
MagicGrallocBufferHandle;
GrallocBufferRef;
null_t;
};
@ -57,7 +58,7 @@ struct SharedTextureDescriptor {
};
struct NewSurfaceDescriptorGralloc {
MaybeMagicGrallocBufferHandle buffer;
PGrallocBuffer buffer;
/**
* android::GraphicBuffer has a size information. But there are cases
* that GraphicBuffer's size and actual video's size are different.

View File

@ -6,6 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include LayersSurfaces;
include protocol PGrallocBuffer;
include protocol PLayerTransaction;
include "mozilla/GfxMessageUtils.h";
include "nsRegion.h";

View File

@ -0,0 +1,30 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=8 et :
*/
/* 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 protocol PCompositor;
include protocol PImageBridge;
include protocol PLayerTransaction;
namespace mozilla {
namespace layers {
/**
* This is a trivial protocol that's used to track gralloc buffers
* across thread contexts. A live PGrallocBuffer actor always
* corresponds 1:1 to a pre-shared gralloc buffer (sharing is done by
* the PGrallocBuffer constructor).
*/
async protocol PGrallocBuffer {
manager PImageBridge or PLayerTransaction;
/** Gralloc buffers can be "owned" by either parent or child. */
both:
async __delete__();
};
} // namespace layers
} // namespace mozilla

View File

@ -5,8 +5,8 @@
include LayersSurfaces;
include LayersMessages;
include protocol PGrallocBuffer;
include protocol PCompositable;
include protocol PLayer;
include protocol PTexture;
include ProtocolTypes;
@ -26,6 +26,7 @@ namespace layers {
intr protocol PImageBridge
{
manages PCompositable;
manages PGrallocBuffer;
manages PTexture;
parent:
@ -33,6 +34,14 @@ parent:
sync Update(CompositableOperation[] ops) returns (EditReply[] reply);
async UpdateNoSwap(CompositableOperation[] ops);
// Allocates a gralloc buffer that may not suitable to use with
// gfxImageSurface but allows hardware decoder to write to the
// buffer directly. The format is a enum defined in
// system/graphics.h and the usage is the GraphicBuffer usage
// flag. See GraphicBuffer.h and gralloc.h.
sync PGrallocBuffer(IntSize size, uint32_t format, uint32_t usage)
returns (MaybeMagicGrallocBufferHandle handle);
// First step of the destruction sequence. This puts all the ImageContainerParents
// in a state in which they can't send asynchronous messages to their child
// counterpart so as to not race with the upcomming __delete__ message.

View File

@ -9,6 +9,7 @@ include LayersSurfaces;
include LayersMessages;
include protocol PCompositable;
include protocol PCompositor;
include protocol PGrallocBuffer;
include protocol PLayer;
include protocol PRenderFrame;
include protocol PTexture;
@ -39,9 +40,39 @@ sync protocol PLayerTransaction {
manager PRenderFrame or PCompositor;
manages PLayer;
manages PCompositable;
manages PGrallocBuffer;
manages PTexture;
parent:
/**
* Only the parent side has privileges to allocate the buffer.
* Allocation may fail (pmem is a scarce resource), and if so null_t
* is returned.
*
* |format| is an Android PixelFormat (see PixelFormat.h)
*
* commonly used PixelFormats are:
* PIXEL_FORMAT_RGBA_8888
* PIXEL_FORMAT_RGBX_8888
* PIXEL_FORMAT_BGRA_8888
*
* Note that SurfaceDescriptorGralloc has a "isRBSwapped" boolean
* that can treat the R/B bytes as swapped when they are rendered
* to the screen, to help with matching the native pixel format
* of other rendering engines.
*
* |usage| is a USAGE_* mask (see GraphicBuffer.h)
*
* commonly used USAGE flags are:
* USAGE_SW_READ_OFTEN | USAGE_SW_WRITE_OFTEN | USAGE_HW_TEXTURE
* - used for software rendering to a buffer which the compositor
* treats as a texture
* USAGE_HW_RENDER | USAGE_HW_TEXTURE
* - used for GL rendering to a buffer which the compositor
* treats as a texture
*/
sync PGrallocBuffer(IntSize size, uint32_t format, uint32_t usage)
returns (MaybeMagicGrallocBufferHandle handle);
async PLayer();
async PCompositable(TextureInfo aTextureInfo);
async PTexture(SurfaceDescriptor aSharedData, TextureFlags aTextureFlags);

View File

@ -8,6 +8,7 @@
include LayersSurfaces;
include protocol PLayerTransaction;
include protocol PImageBridge;
include protocol PGrallocBuffer;
include "mozilla/GfxMessageUtils.h";
using struct mozilla::layers::FrameMetrics from "FrameMetrics.h";

View File

@ -38,10 +38,6 @@ namespace mozilla { namespace layers {
struct MagicGrallocBufferHandle {
bool operator==(const MagicGrallocBufferHandle&) const { return false; }
};
struct GrallocBufferRef {
bool operator==(const GrallocBufferRef&) const { return false; }
};
} }
#endif
@ -86,13 +82,6 @@ struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
static void Write(Message*, const paramType&) {}
static bool Read(const Message*, void**, paramType*) { return false; }
};
template <>
struct ParamTraits<mozilla::layers::GrallocBufferRef> {
typedef mozilla::layers::GrallocBufferRef paramType;
static void Write(Message*, const paramType&) {}
static bool Read(const Message*, void**, paramType*) { return false; }
};
#endif // !defined(MOZ_HAVE_XSURFACEDESCRIPTORGRALLOC)
template <>

View File

@ -8,13 +8,13 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/layers/PGrallocBufferChild.h"
#include "mozilla/layers/PGrallocBufferParent.h"
#include "mozilla/layers/LayerTransactionChild.h"
#include "mozilla/layers/ShadowLayers.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/CompositorTypes.h"
#include "mozilla/layers/TextureHost.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "mozilla/unused.h"
#include "nsXULAppAPI.h"
@ -39,28 +39,6 @@ using namespace mozilla::gl;
namespace IPC {
void
ParamTraits<GrallocBufferRef>::Write(Message* aMsg,
const paramType& aParam)
{
aMsg->WriteInt(aParam.mOwner);
aMsg->WriteInt32(aParam.mKey);
}
bool
ParamTraits<GrallocBufferRef>::Read(const Message* aMsg, void** aIter,
paramType* aParam)
{
int owner;
int index;
if (!aMsg->ReadInt(aIter, &owner) ||
!aMsg->ReadInt32(aIter, &index))
return false;
aParam->mOwner = owner;
aParam->mKey = index;
return true;
}
void
ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
const paramType& aParam)
@ -92,8 +70,7 @@ ParamTraits<MagicGrallocBufferHandle>::Write(Message* aMsg,
#else
flattenable->flatten(data, nbytes, fds, nfds);
#endif
aMsg->WriteInt(aParam.mRef.mOwner);
aMsg->WriteInt32(aParam.mRef.mKey);
aMsg->WriteSize(nbytes);
aMsg->WriteSize(nfds);
@ -113,19 +90,15 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
size_t nbytes;
size_t nfds;
const char* data;
int owner;
int index;
if (!aMsg->ReadInt(aIter, &owner) ||
!aMsg->ReadInt32(aIter, &index) ||
!aMsg->ReadSize(aIter, &nbytes) ||
if (!aMsg->ReadSize(aIter, &nbytes) ||
!aMsg->ReadSize(aIter, &nfds) ||
!aMsg->ReadBytes(aIter, &data, nbytes)) {
return false;
}
int fds[nfds];
bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default);
for (size_t n = 0; n < nfds; ++n) {
FileDescriptor fd;
if (!aMsg->ReadFileDescriptor(aIter, &fd)) {
@ -136,41 +109,27 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
// SCM_RIGHTS doesn't dup the fd. That's surprising, but we just
// deal with it here. NB: only the "default" (master) process can
// alloc gralloc buffers.
int dupFd = sameProcess && index < 0 ? dup(fd.fd) : fd.fd;
bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default);
int dupFd = sameProcess ? dup(fd.fd) : fd.fd;
fds[n] = dupFd;
}
aResult->mRef.mOwner = owner;
aResult->mRef.mKey = index;
if (sameProcess)
aResult->mGraphicBuffer = SharedBufferManagerParent::GetGraphicBuffer(aResult->mRef);
else {
aResult->mGraphicBuffer = SharedBufferManagerChild::GetSingleton()->GetGraphicBuffer(index);
if (index >= 0 && aResult->mGraphicBuffer == nullptr) {
//Only newly created GraphicBuffer should deserialize
sp<GraphicBuffer> buffer(new GraphicBuffer());
#if ANDROID_VERSION >= 19
sp<GraphicBuffer> flattenable(new GraphicBuffer());
const void* datap = (const void*)data;
const int* fdsp = &fds[0];
if (NO_ERROR == flattenable->unflatten(datap, nbytes, fdsp, nfds)) {
aResult->mGraphicBuffer = flattenable;
}
// Make a copy of "data" and "fds" for unflatten() to avoid casting problem
void const *pdata = (void const *)data;
int const *pfds = fds;
if (NO_ERROR == buffer->unflatten(pdata, nbytes, pfds, nfds)) {
#else
sp<GraphicBuffer> buffer(new GraphicBuffer());
Flattenable *flattenable = buffer.get();
Flattenable *flattenable = buffer.get();
if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) {
aResult->mGraphicBuffer = buffer;
}
if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) {
#endif
}
aResult->mGraphicBuffer = buffer;
return true;
}
if (aResult->mGraphicBuffer == nullptr) {
return false;
}
return true;
return false;
}
} // namespace IPC
@ -178,9 +137,8 @@ ParamTraits<MagicGrallocBufferHandle>::Read(const Message* aMsg,
namespace mozilla {
namespace layers {
MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref)
MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp<GraphicBuffer>& aGraphicBuffer)
: mGraphicBuffer(aGraphicBuffer)
, mRef(ref)
{
}
@ -255,6 +213,122 @@ ContentTypeFromPixelFormat(android::PixelFormat aFormat)
return gfxASurface::ContentFromFormat(ImageFormatForPixelFormat(aFormat));
}
class GrallocReporter MOZ_FINAL : public nsIMemoryReporter
{
friend class GrallocBufferActor;
public:
NS_DECL_ISUPPORTS
GrallocReporter()
{
#ifdef DEBUG
// There must be only one instance of this class, due to |sAmount|
// being static. Assert this.
static bool hasRun = false;
MOZ_ASSERT(!hasRun);
hasRun = true;
#endif
}
NS_IMETHOD CollectReports(nsIHandleReportCallback* aHandleReport,
nsISupports* aData)
{
return MOZ_COLLECT_REPORT(
"gralloc", KIND_OTHER, UNITS_BYTES, sAmount,
"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.");
}
private:
static int64_t sAmount;
};
NS_IMPL_ISUPPORTS(GrallocReporter, nsIMemoryReporter)
int64_t GrallocReporter::sAmount = 0;
void InitGralloc() {
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
RegisterStrongMemoryReporter(new GrallocReporter());
}
GrallocBufferActor::GrallocBufferActor()
: mAllocBytes(0)
, mTextureHost(nullptr)
{
}
GrallocBufferActor::~GrallocBufferActor()
{
if (mAllocBytes > 0) {
GrallocReporter::sAmount -= mAllocBytes;
}
}
/*static*/ PGrallocBufferParent*
GrallocBufferActor::Create(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
MaybeMagicGrallocBufferHandle* aOutHandle)
{
PROFILER_LABEL("GrallocBufferActor", "Create");
GrallocBufferActor* actor = new GrallocBufferActor();
*aOutHandle = null_t();
uint32_t format = aFormat;
uint32_t usage = aUsage;
if (format == 0 || usage == 0) {
printf_stderr("GrallocBufferActor::Create -- format and usage must be non-zero");
return actor;
}
// 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("GrallocBufferActor::Create -- requested gralloc buffer is too big. Killing child instead.");
delete actor;
return nullptr;
}
sp<GraphicBuffer> buffer(new GraphicBuffer(aSize.width, aSize.height, format, usage));
if (buffer->initCheck() != OK)
return actor;
size_t bpp = BytesPerPixelForPixelFormat(format);
actor->mAllocBytes = aSize.width * aSize.height * bpp;
GrallocReporter::sAmount += actor->mAllocBytes;
actor->mGraphicBuffer = buffer;
*aOutHandle = MagicGrallocBufferHandle(buffer);
return actor;
}
void GrallocBufferActor::ActorDestroy(ActorDestroyReason)
{
// Used only for hacky fix for bug 966446.
if (mTextureHost) {
mTextureHost->ForgetBufferActor();
mTextureHost = nullptr;
}
}
void GrallocBufferActor::AddTextureHost(TextureHost* aTextureHost)
{
mTextureHost = aTextureHost;
}
void GrallocBufferActor::RemoveTextureHost()
{
mTextureHost = nullptr;
}
/*static*/ bool
LayerManagerComposite::SupportsDirectTexturing()
{
@ -268,33 +342,49 @@ LayerManagerComposite::PlatformSyncBeforeReplyUpdate()
}
//-----------------------------------------------------------------------------
// Both processes
// Child process
/*static*/ sp<GraphicBuffer>
GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle)
/*static*/ PGrallocBufferChild*
GrallocBufferActor::Create()
{
if (aHandle.type() != MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle) {
if (aHandle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
if (XRE_GetProcessType() == GeckoProcessType_Default) {
return SharedBufferManagerParent::GetGraphicBuffer(aHandle.get_GrallocBufferRef());
}
return SharedBufferManagerChild::GetSingleton()->GetGraphicBuffer(aHandle.get_GrallocBufferRef().mKey);
}
} else {
MagicGrallocBufferHandle realHandle = aHandle.get_MagicGrallocBufferHandle();
return realHandle.mGraphicBuffer;
}
return nullptr;
return new GrallocBufferActor();
}
android::sp<android::GraphicBuffer>
GetGraphicBufferFromDesc(SurfaceDescriptor aDesc)
void
GrallocBufferActor::InitFromHandle(const MagicGrallocBufferHandle& aHandle)
{
MaybeMagicGrallocBufferHandle handle;
if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) {
handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer();
MOZ_ASSERT(!mGraphicBuffer.get());
MOZ_ASSERT(aHandle.mGraphicBuffer.get());
mGraphicBuffer = aHandle.mGraphicBuffer;
}
PGrallocBufferChild*
ShadowLayerForwarder::AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle)
{
if (!mShadowManager->IPCOpen()) {
return nullptr;
}
return GetGraphicBufferFrom(handle);
return mShadowManager->SendPGrallocBufferConstructor(aSize, aFormat, aUsage, aHandle);
}
void
ShadowLayerForwarder::DeallocGrallocBuffer(PGrallocBufferChild* aChild)
{
MOZ_ASSERT(aChild);
PGrallocBufferChild::Send__delete__(aChild);
}
//-----------------------------------------------------------------------------
// Both processes
android::GraphicBuffer*
GrallocBufferActor::GetGraphicBuffer()
{
return mGraphicBuffer.get();
}
/*static*/ void

View File

@ -11,8 +11,9 @@
#include <unistd.h>
#include <ui/GraphicBuffer.h>
#include "base/process.h"
#include "ipc/IPCMessageUtils.h"
#include "mozilla/layers/PGrallocBufferChild.h"
#include "mozilla/layers/PGrallocBufferParent.h"
#define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
@ -21,24 +22,8 @@ namespace mozilla {
namespace layers {
class MaybeMagicGrallocBufferHandle;
class SurfaceDescriptor;
class TextureHost;
struct GrallocBufferRef {
base::ProcessId mOwner;
int mKey;
GrallocBufferRef()
: mOwner(0)
, mKey(-1)
{
}
bool operator== (const GrallocBufferRef rhs) const{
return mOwner == rhs.mOwner && mKey == rhs.mKey;
}
};
/**
* This class exists to share the underlying GraphicBuffer resources
* from one thread context to another. This requires going through
@ -49,9 +34,11 @@ struct GrallocBufferRef {
*/
struct MagicGrallocBufferHandle {
typedef android::GraphicBuffer GraphicBuffer;
MagicGrallocBufferHandle() {}
MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer, GrallocBufferRef ref);
MagicGrallocBufferHandle()
{ }
MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer);
// Default copy ctor and operator= are OK
@ -60,15 +47,58 @@ struct MagicGrallocBufferHandle {
}
android::sp<GraphicBuffer> mGraphicBuffer;
GrallocBufferRef mRef;
};
/**
* Util function to find GraphicBuffer from SurfaceDescriptor, caller of this function should check origin
* to make sure not corrupt others buffer
* GrallocBufferActor is an "IPC wrapper" for an underlying
* GraphicBuffer (pmem region). It allows us to cheaply and
* conveniently share gralloc handles between processes.
*/
android::sp<android::GraphicBuffer> GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle);
android::sp<android::GraphicBuffer> GetGraphicBufferFromDesc(SurfaceDescriptor aDesc);
class GrallocBufferActor : public PGrallocBufferChild
, public PGrallocBufferParent
{
friend class ShadowLayerForwarder;
friend class LayerManagerComposite;
friend class ImageBridgeChild;
typedef android::GraphicBuffer GraphicBuffer;
public:
virtual ~GrallocBufferActor();
static PGrallocBufferParent*
Create(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
MaybeMagicGrallocBufferHandle* aOutHandle);
static PGrallocBufferChild*
Create();
// used only for hacky fix in gecko 23 for bug 862324
// see bug 865908 about fixing this.
void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
void AddTextureHost(TextureHost* aTextureHost);
void RemoveTextureHost();
android::GraphicBuffer* GetGraphicBuffer();
void InitFromHandle(const MagicGrallocBufferHandle& aHandle);
private:
GrallocBufferActor();
android::sp<GraphicBuffer> mGraphicBuffer;
// This value stores the number of bytes allocated in this
// BufferActor. This will be used for the memory reporter.
size_t mAllocBytes;
// Used only for hacky fix for bug 966446.
TextureHost* mTextureHost;
friend class ISurfaceAllocator;
};
} // namespace layers
} // namespace mozilla
@ -83,14 +113,6 @@ struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
};
template<>
struct ParamTraits<mozilla::layers::GrallocBufferRef> {
typedef mozilla::layers::GrallocBufferRef paramType;
static void Write(Message* aMsg, const paramType& aParam);
static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
};
} // namespace IPC
#endif // mozilla_layers_ShadowLayerUtilsGralloc_h

View File

@ -376,6 +376,16 @@ protected:
RefPtr<LayerTransactionChild> mShadowManager;
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
// from ISurfaceAllocator
virtual PGrallocBufferChild* AllocGrallocBuffer(const gfx::IntSize& aSize,
uint32_t aFormat,
uint32_t aUsage,
MaybeMagicGrallocBufferHandle* aHandle) MOZ_OVERRIDE;
virtual void DeallocGrallocBuffer(PGrallocBufferChild* aChild) MOZ_OVERRIDE;
#endif
private:
Transaction* mTxn;

View File

@ -147,8 +147,6 @@ EXPORTS.mozilla.layers += [
'ipc/LayerTransactionParent.h',
'ipc/ShadowLayers.h',
'ipc/ShadowLayersManager.h',
'ipc/SharedBufferManagerChild.h',
'ipc/SharedBufferManagerParent.h',
'ipc/SharedPlanarYCbCrImage.h',
'ipc/SharedRGBImage.h',
'LayersTypes.h',
@ -284,8 +282,6 @@ UNIFIED_SOURCES += [
'ipc/ShadowLayerChild.cpp',
'ipc/ShadowLayerParent.cpp',
'ipc/ShadowLayers.cpp',
'ipc/SharedBufferManagerChild.cpp',
'ipc/SharedBufferManagerParent.cpp',
'ipc/SharedPlanarYCbCrImage.cpp',
'ipc/SharedRGBImage.cpp',
'LayerScope.cpp',
@ -331,10 +327,10 @@ IPDL_SOURCES = [
'ipc/LayersSurfaces.ipdlh',
'ipc/PCompositable.ipdl',
'ipc/PCompositor.ipdl',
'ipc/PGrallocBuffer.ipdl',
'ipc/PImageBridge.ipdl',
'ipc/PLayer.ipdl',
'ipc/PLayerTransaction.ipdl',
'ipc/PSharedBufferManager.ipdl',
'ipc/PTexture.ipdl',
]

View File

@ -20,8 +20,8 @@ using namespace android;
class GrallocTextureClientData : public TextureClientData {
public:
GrallocTextureClientData(MaybeMagicGrallocBufferHandle aDesc)
: mGrallocHandle(aDesc)
GrallocTextureClientData(GrallocBufferActor* aActor)
: mGrallocActor(aActor)
{
MOZ_COUNT_CTOR(GrallocTextureClientData);
}
@ -29,34 +29,37 @@ public:
~GrallocTextureClientData()
{
MOZ_COUNT_DTOR(GrallocTextureClientData);
MOZ_ASSERT(!mGrallocActor);
}
virtual void DeallocateSharedData(ISurfaceAllocator* allocator) MOZ_OVERRIDE
{
allocator->DeallocGrallocBuffer(&mGrallocHandle);
allocator->DeallocGrallocBuffer(mGrallocActor);
mGrallocActor = nullptr;
}
private:
MaybeMagicGrallocBufferHandle mGrallocHandle;
GrallocBufferActor* mGrallocActor;
};
TextureClientData*
GrallocTextureClientOGL::DropTextureData()
{
TextureClientData* result = new GrallocTextureClientData(mGrallocHandle);
TextureClientData* result = new GrallocTextureClientData(mGrallocActor);
mGrallocActor = nullptr;
mGraphicBuffer = nullptr;
return result;
}
GrallocTextureClientOGL::GrallocTextureClientOGL(MaybeMagicGrallocBufferHandle buffer,
GrallocTextureClientOGL::GrallocTextureClientOGL(GrallocBufferActor* aActor,
gfx::IntSize aSize,
gfx::BackendType aMoz2dBackend,
TextureFlags aFlags)
: BufferTextureClient(nullptr, gfx::SurfaceFormat::UNKNOWN, aMoz2dBackend, aFlags)
, mGrallocHandle(buffer)
, mMappedBuffer(nullptr)
, mMediaBuffer(nullptr)
{
InitWith(buffer, aSize);
InitWith(aActor, aSize);
MOZ_COUNT_CTOR(GrallocTextureClientOGL);
}
@ -76,17 +79,18 @@ GrallocTextureClientOGL::~GrallocTextureClientOGL()
MOZ_COUNT_DTOR(GrallocTextureClientOGL);
if (ShouldDeallocateInDestructor()) {
ISurfaceAllocator* allocator = GetAllocator();
allocator->DeallocGrallocBuffer(&mGrallocHandle);
allocator->DeallocGrallocBuffer(mGrallocActor);
}
}
void
GrallocTextureClientOGL::InitWith(MaybeMagicGrallocBufferHandle aHandle, gfx::IntSize aSize)
GrallocTextureClientOGL::InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize)
{
MOZ_ASSERT(aActor);
MOZ_ASSERT(!IsAllocated());
MOZ_ASSERT(IsValid());
mGrallocHandle = aHandle;
mGraphicBuffer = GetGraphicBufferFrom(aHandle);
mGrallocActor = aActor;
mGraphicBuffer = aActor->GetGraphicBuffer();
mSize = aSize;
}
@ -98,7 +102,7 @@ GrallocTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
return false;
}
aOutDescriptor = NewSurfaceDescriptorGralloc(mGrallocHandle, mSize);
aOutDescriptor = NewSurfaceDescriptorGralloc(nullptr, mGrallocActor, mSize);
return true;
}
@ -301,16 +305,18 @@ GrallocTextureClientOGL::AllocateGralloc(gfx::IntSize aSize,
ISurfaceAllocator* allocator = GetAllocator();
MaybeMagicGrallocBufferHandle handle;
bool allocateResult =
PGrallocBufferChild* actor =
allocator->AllocGrallocBuffer(aSize,
aAndroidFormat,
aUsage,
&handle);
if (!allocateResult) {
if (!actor) {
return false;
}
GrallocBufferActor* gba = static_cast<GrallocBufferActor*>(actor);
gba->InitFromHandle(handle.get_MagicGrallocBufferHandle());
sp<GraphicBuffer> graphicBuffer = GetGraphicBufferFrom(handle);
sp<GraphicBuffer> graphicBuffer = gba->GetGraphicBuffer();
if (!graphicBuffer.get()) {
return false;
}
@ -319,7 +325,7 @@ GrallocTextureClientOGL::AllocateGralloc(gfx::IntSize aSize,
return false;
}
mGrallocHandle = handle;
mGrallocActor = gba;
mGraphicBuffer = graphicBuffer;
mSize = aSize;
return true;

View File

@ -37,7 +37,7 @@ namespace layers {
class GrallocTextureClientOGL : public BufferTextureClient
{
public:
GrallocTextureClientOGL(MaybeMagicGrallocBufferHandle buffer,
GrallocTextureClientOGL(GrallocBufferActor* aActor,
gfx::IntSize aSize,
gfx::BackendType aMoz2dBackend,
TextureFlags aFlags = TextureFlags::DEFAULT);
@ -66,7 +66,7 @@ public:
virtual void WaitReleaseFence() MOZ_OVERRIDE;
void InitWith(MaybeMagicGrallocBufferHandle aDesc, gfx::IntSize aSize);
void InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize);
void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); }
@ -120,7 +120,7 @@ protected:
/**
* Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor.
*/
MaybeMagicGrallocBufferHandle mGrallocHandle;
GrallocBufferActor* mGrallocActor;
android::sp<android::GraphicBuffer> mGraphicBuffer;

View File

@ -3,14 +3,12 @@
* 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/process.h"
#include "GLContext.h"
#include "gfx2DGlue.h"
#include <ui/GraphicBuffer.h>
#include "GrallocImages.h" // for GrallocImage
#include "mozilla/layers/GrallocTextureHost.h"
#include "mozilla/layers/CompositorOGL.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "EGLImageHelpers.h"
#include "GLReadTexImageHelper.h"
@ -278,18 +276,23 @@ GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags,
const NewSurfaceDescriptorGralloc& aDescriptor)
: TextureHost(aFlags)
{
mGrallocHandle = aDescriptor;
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
if (!graphicBuffer) {
NS_RUNTIMEABORT("Invalid SurfaceDescriptor passed in");
}
android::GraphicBuffer* graphicBuffer = nullptr;
gfx::SurfaceFormat format = gfx::SurfaceFormat::UNKNOWN;
mSize = aDescriptor.size();
gfx::SurfaceFormat format =
SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(),
aFlags & TextureFlags::RB_SWAPPED);
mGrallocActor =
static_cast<GrallocBufferActor*>(aDescriptor.bufferParent());
if (mGrallocActor) {
mGrallocActor->AddTextureHost(this);
graphicBuffer = mGrallocActor->GetGraphicBuffer();
}
if (graphicBuffer) {
format =
SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(),
aFlags);
}
mTextureSource = new GrallocTextureSourceOGL(nullptr,
graphicBuffer,
format);
@ -298,6 +301,10 @@ GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags,
GrallocTextureHostOGL::~GrallocTextureHostOGL()
{
mTextureSource = nullptr;
if (mGrallocActor) {
mGrallocActor->RemoveTextureHost();
mGrallocActor = nullptr;
}
}
void
@ -340,17 +347,8 @@ GrallocTextureHostOGL::DeallocateSharedData()
if (mTextureSource) {
mTextureSource->ForgetBuffer();
}
if (mGrallocHandle.buffer().type() != SurfaceDescriptor::Tnull_t) {
MaybeMagicGrallocBufferHandle handle = mGrallocHandle.buffer();
base::ProcessId owner;
if (handle.type() == MaybeMagicGrallocBufferHandle::TGrallocBufferRef) {
owner = handle.get_GrallocBufferRef().mOwner;
}
else {
owner = handle.get_MagicGrallocBufferHandle().mRef.mOwner;
}
SharedBufferManagerParent::GetInstance(owner)->DropGrallocBuffer(mGrallocHandle);
if (mGrallocActor) {
PGrallocBufferParent::Send__delete__(mGrallocActor);
}
}

View File

@ -125,8 +125,14 @@ public:
virtual const char* Name() MOZ_OVERRIDE { return "GrallocTextureHostOGL"; }
// Forget buffer actor. Used only for hacky fix for bug 966446.
virtual void ForgetBufferActor()
{
mGrallocActor = nullptr;
}
private:
NewSurfaceDescriptorGralloc mGrallocHandle;
GrallocBufferActor* mGrallocActor;
RefPtr<GrallocTextureSourceOGL> mTextureSource;
gfx::IntSize mSize; // See comment in textureClientOGL.h
};

View File

@ -10,7 +10,6 @@
#include "mozilla/layers/CompositorChild.h"
#include "mozilla/layers/CompositorParent.h"
#include "mozilla/layers/ImageBridgeChild.h"
#include "mozilla/layers/SharedBufferManagerChild.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for GfxMemoryImageReporter
#include "prlog.h"
@ -376,9 +375,6 @@ gfxPlatform::Init()
if (gfxPrefs::AsyncVideoEnabled()) {
ImageBridgeChild::StartUp();
}
#ifdef MOZ_WIDGET_GONK
SharedBufferManagerChild::StartUp();
#endif
}
nsresult rv;
@ -500,9 +496,7 @@ gfxPlatform::Shutdown()
// This will block this thread untill the ImageBridge protocol is completely
// deleted.
ImageBridgeChild::ShutDown();
#ifdef MOZ_WIDGET_GONK
SharedBufferManagerChild::ShutDown();
#endif
CompositorParent::ShutDown();
delete gGfxPlatformPrefsLock;

View File

@ -7,8 +7,6 @@
include protocol PContent;
include protocol PBrowser;
include "mozilla/GfxMessageUtils.h";
using mozilla::dom::ScreenOrientation from "mozilla/dom/ScreenOrientation.h";
using mozilla::hal::FlashMode from "mozilla/HalTypes.h";
using mozilla::hal::LightType from "mozilla/HalTypes.h";

View File

@ -30,7 +30,7 @@ class FileDescriptorSet : public base::RefCountedThreadSafe<FileDescriptorSet> {
// In debugging mode, it's a fatal error to try and add more than this number
// of descriptors to a FileDescriptorSet.
enum {
MAX_DESCRIPTORS_PER_MESSAGE = 7
MAX_DESCRIPTORS_PER_MESSAGE = 4
};
// ---------------------------------------------------------------------------