diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index a9031d6a4e462..bf0f6f5a5a1d0 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -29,6 +29,7 @@ #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" @@ -688,6 +689,13 @@ 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) diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 252612729c0da..cb818a4072b67 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -89,6 +89,11 @@ class ContentChild : public PContentChild 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; diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index b1064eb6b8b36..2ee5d8dd86bc6 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -54,6 +54,7 @@ #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" @@ -1595,6 +1596,10 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority, } } } +#ifdef MOZ_WIDGET_GONK + DebugOnly opened = PSharedBufferManager::Open(this); + MOZ_ASSERT(opened); +#endif if (aSendRegisteredChrome) { nsCOMPtr registrySvc = nsChromeRegistry::GetService(); @@ -2192,6 +2197,13 @@ 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) diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index a88c3b23acd26..b29acebe55a97 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -47,6 +47,7 @@ class PJavaScriptParent; namespace layers { class PCompositorParent; +class PSharedBufferManagerParent; } // namespace layers namespace dom { @@ -327,6 +328,9 @@ class ContentParent : public PContentParent 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; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 23cc221787403..2306ccb7295e1 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -21,6 +21,7 @@ include protocol PImageBridge; include protocol PIndexedDB; include protocol PMemoryReportRequest; include protocol PNecko; +include protocol PSharedBufferManager; include protocol PSms; include protocol PSpeechSynthesis; include protocol PStorage; @@ -263,6 +264,7 @@ struct PrefSetting { intr protocol PContent { parent opens PCompositor; + parent opens PSharedBufferManager; parent opens PImageBridge; child opens PBackground; diff --git a/gfx/layers/GrallocImages.h b/gfx/layers/GrallocImages.h index 1a4e30d9dec33..1cbd77a10cf50 100644 --- a/gfx/layers/GrallocImages.h +++ b/gfx/layers/GrallocImages.h @@ -81,6 +81,10 @@ class GrallocImage : public PlanarYCbCrImage HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS = 0x7FA30C04, }; + enum { + GRALLOC_SW_UAGE = android::GraphicBuffer::USAGE_SOFTWARE_MASK, + }; + virtual TemporaryRef GetAsSourceSurface() MOZ_OVERRIDE; android::sp GetGraphicBuffer() const; @@ -98,6 +102,11 @@ class GrallocImage : public PlanarYCbCrImage return static_cast(GetNativeBuffer()); } + int GetUsage() + { + return (static_cast(GetNativeBuffer()))->usage; + } + private: RefPtr mTextureClient; }; diff --git a/gfx/layers/ipc/CompositableTransactionParent.cpp b/gfx/layers/ipc/CompositableTransactionParent.cpp index cf9c9414fe798..510f9277416c9 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.cpp +++ b/gfx/layers/ipc/CompositableTransactionParent.cpp @@ -16,6 +16,7 @@ #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 diff --git a/gfx/layers/ipc/ISurfaceAllocator.cpp b/gfx/layers/ipc/ISurfaceAllocator.cpp index bf72bf2899628..07c7b9c4becd6 100644 --- a/gfx/layers/ipc/ISurfaceAllocator.cpp +++ b/gfx/layers/ipc/ISurfaceAllocator.cpp @@ -14,6 +14,7 @@ #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 @@ -308,5 +309,20 @@ 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 diff --git a/gfx/layers/ipc/ISurfaceAllocator.h b/gfx/layers/ipc/ISurfaceAllocator.h index 23fa6bdd579cd..95c5e5a2556f8 100644 --- a/gfx/layers/ipc/ISurfaceAllocator.h +++ b/gfx/layers/ipc/ISurfaceAllocator.h @@ -46,7 +46,6 @@ class DataSourceSurface; namespace layers { -class PGrallocBufferChild; class MaybeMagicGrallocBufferHandle; class MemoryTextureClient; class MemoryTextureHost; @@ -155,18 +154,12 @@ class ISurfaceAllocator : public AtomicRefCountedWithFinalize virtual void DestroySharedSurface(SurfaceDescriptor* aSurface); // method that does the actual allocation work - virtual PGrallocBufferChild* AllocGrallocBuffer(const gfx::IntSize& aSize, - uint32_t aFormat, - uint32_t aUsage, - MaybeMagicGrallocBufferHandle* aHandle) - { - return nullptr; - } + bool AllocGrallocBuffer(const gfx::IntSize& aSize, + uint32_t aFormat, + uint32_t aUsage, + MaybeMagicGrallocBufferHandle* aHandle); - virtual void DeallocGrallocBuffer(PGrallocBufferChild* aChild) - { - NS_RUNTIMEABORT("should not be called"); - } + void DeallocGrallocBuffer(MaybeMagicGrallocBufferHandle* aHandle); virtual bool IPCOpen() const { return true; } virtual bool IsSameProcess() const = 0; diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index b039cfe2a5f57..5f602776664b6 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -52,7 +52,6 @@ class Shmem; namespace layers { -class PGrallocBufferChild; typedef std::vector OpVector; struct CompositableTransaction @@ -204,44 +203,6 @@ static void CreateImageClientSync(RefPtr* 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(); @@ -655,30 +616,6 @@ 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, @@ -800,99 +737,6 @@ 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&) diff --git a/gfx/layers/ipc/ImageBridgeChild.h b/gfx/layers/ipc/ImageBridgeChild.h index 2f80438765d25..8e91b53a5e993 100644 --- a/gfx/layers/ipc/ImageBridgeChild.h +++ b/gfx/layers/ipc/ImageBridgeChild.h @@ -13,7 +13,6 @@ #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 @@ -187,13 +186,6 @@ class ImageBridgeChild : public PImageBridgeChild */ ~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; @@ -310,10 +302,6 @@ class ImageBridgeChild : public PImageBridgeChild 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, @@ -322,13 +310,6 @@ class ImageBridgeChild : public PImageBridgeChild 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 diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 31736e58e7a82..640427a6c88bf 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -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,8 +40,6 @@ using namespace mozilla::gfx; namespace mozilla { namespace layers { -class PGrallocBufferParent; - ImageBridgeParent::ImageBridgeParent(MessageLoop* aLoop, Transport* aTransport) : mMessageLoop(aLoop) , mTransport(aTransport) @@ -161,32 +159,6 @@ 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) diff --git a/gfx/layers/ipc/ImageBridgeParent.h b/gfx/layers/ipc/ImageBridgeParent.h index 7228d7c0f1efb..316666129a711 100644 --- a/gfx/layers/ipc/ImageBridgeParent.h +++ b/gfx/layers/ipc/ImageBridgeParent.h @@ -20,6 +20,10 @@ class MessageLoop; +namespace base { +class Thread; +} + namespace mozilla { namespace ipc { class Shmem; @@ -49,13 +53,6 @@ class ImageBridgeParent : public PImageBridgeParent, 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; diff --git a/gfx/layers/ipc/LayerTransactionChild.cpp b/gfx/layers/ipc/LayerTransactionChild.cpp index 98459ecd79902..85b14e0087181 100644 --- a/gfx/layers/ipc/LayerTransactionChild.cpp +++ b/gfx/layers/ipc/LayerTransactionChild.cpp @@ -7,7 +7,6 @@ #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 @@ -18,7 +17,6 @@ namespace mozilla { namespace layers { -class PGrallocBufferChild; void LayerTransactionChild::Destroy() @@ -29,31 +27,6 @@ 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() diff --git a/gfx/layers/ipc/LayerTransactionChild.h b/gfx/layers/ipc/LayerTransactionChild.h index 22d57abd4c354..1b9a4aaebae57 100644 --- a/gfx/layers/ipc/LayerTransactionChild.h +++ b/gfx/layers/ipc/LayerTransactionChild.h @@ -43,13 +43,6 @@ class LayerTransactionChild : public PLayerTransactionChild {} ~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; diff --git a/gfx/layers/ipc/LayerTransactionParent.cpp b/gfx/layers/ipc/LayerTransactionParent.cpp index 997cfa7267dbd..9f9ee50e78c36 100644 --- a/gfx/layers/ipc/LayerTransactionParent.cpp +++ b/gfx/layers/ipc/LayerTransactionParent.cpp @@ -740,33 +740,6 @@ 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() { diff --git a/gfx/layers/ipc/LayerTransactionParent.h b/gfx/layers/ipc/LayerTransactionParent.h index 36b39c561a4de..9cf9a6c4932ad 100644 --- a/gfx/layers/ipc/LayerTransactionParent.h +++ b/gfx/layers/ipc/LayerTransactionParent.h @@ -103,13 +103,6 @@ class LayerTransactionParent : public PLayerTransactionParent, 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; diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index adffd55ba242e..abe0699f865c8 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -8,7 +8,6 @@ include LayersSurfaces; include protocol PCompositable; include protocol PCompositor; -include protocol PGrallocBuffer; include protocol PLayer; include protocol PRenderFrame; include protocol PTexture; diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index c43032912a9b9..75abc2455b0d4 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -2,14 +2,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 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"; @@ -25,6 +23,7 @@ namespace layers { union MaybeMagicGrallocBufferHandle { MagicGrallocBufferHandle; + GrallocBufferRef; null_t; }; @@ -58,7 +57,7 @@ struct SharedTextureDescriptor { }; struct NewSurfaceDescriptorGralloc { - PGrallocBuffer buffer; + MaybeMagicGrallocBufferHandle buffer; /** * android::GraphicBuffer has a size information. But there are cases * that GraphicBuffer's size and actual video's size are different. diff --git a/gfx/layers/ipc/PCompositor.ipdl b/gfx/layers/ipc/PCompositor.ipdl index 3efb6b7dfd9e6..a879584d7dab8 100644 --- a/gfx/layers/ipc/PCompositor.ipdl +++ b/gfx/layers/ipc/PCompositor.ipdl @@ -6,7 +6,6 @@ * 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"; diff --git a/gfx/layers/ipc/PGrallocBuffer.ipdl b/gfx/layers/ipc/PGrallocBuffer.ipdl deleted file mode 100644 index ddf7fdc042e67..0000000000000 --- a/gfx/layers/ipc/PGrallocBuffer.ipdl +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- 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 diff --git a/gfx/layers/ipc/PImageBridge.ipdl b/gfx/layers/ipc/PImageBridge.ipdl index 60fe2e0248f49..bdc8dfbf9ca20 100644 --- a/gfx/layers/ipc/PImageBridge.ipdl +++ b/gfx/layers/ipc/PImageBridge.ipdl @@ -5,8 +5,8 @@ include LayersSurfaces; include LayersMessages; -include protocol PGrallocBuffer; include protocol PCompositable; +include protocol PLayer; include protocol PTexture; include ProtocolTypes; @@ -26,7 +26,6 @@ namespace layers { intr protocol PImageBridge { manages PCompositable; - manages PGrallocBuffer; manages PTexture; parent: @@ -34,14 +33,6 @@ 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. diff --git a/gfx/layers/ipc/PLayerTransaction.ipdl b/gfx/layers/ipc/PLayerTransaction.ipdl index 3965d853fa226..cb6b8181c29db 100644 --- a/gfx/layers/ipc/PLayerTransaction.ipdl +++ b/gfx/layers/ipc/PLayerTransaction.ipdl @@ -9,7 +9,6 @@ include LayersSurfaces; include LayersMessages; include protocol PCompositable; include protocol PCompositor; -include protocol PGrallocBuffer; include protocol PLayer; include protocol PRenderFrame; include protocol PTexture; @@ -40,39 +39,9 @@ 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); diff --git a/gfx/layers/ipc/PTexture.ipdl b/gfx/layers/ipc/PTexture.ipdl index 349b9d0a4bb88..69ad54536dac9 100644 --- a/gfx/layers/ipc/PTexture.ipdl +++ b/gfx/layers/ipc/PTexture.ipdl @@ -8,7 +8,6 @@ include LayersSurfaces; include protocol PLayerTransaction; include protocol PImageBridge; -include protocol PGrallocBuffer; include "mozilla/GfxMessageUtils.h"; using struct mozilla::layers::FrameMetrics from "FrameMetrics.h"; diff --git a/gfx/layers/ipc/ShadowLayerUtils.h b/gfx/layers/ipc/ShadowLayerUtils.h index 225abd52588fa..de37f97bbc6f4 100644 --- a/gfx/layers/ipc/ShadowLayerUtils.h +++ b/gfx/layers/ipc/ShadowLayerUtils.h @@ -38,6 +38,10 @@ namespace mozilla { namespace layers { struct MagicGrallocBufferHandle { bool operator==(const MagicGrallocBufferHandle&) const { return false; } }; + +struct GrallocBufferRef { + bool operator==(const GrallocBufferRef&) const { return false; } +}; } } #endif @@ -82,6 +86,13 @@ struct ParamTraits { static void Write(Message*, const paramType&) {} static bool Read(const Message*, void**, paramType*) { return false; } }; + +template <> +struct ParamTraits { + 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 <> diff --git a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp index dc83cb2907e66..cd0673614372a 100644 --- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp +++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.cpp @@ -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,6 +39,28 @@ using namespace mozilla::gl; namespace IPC { +void +ParamTraits::Write(Message* aMsg, + const paramType& aParam) +{ + aMsg->WriteInt(aParam.mOwner); + aMsg->WriteInt32(aParam.mKey); +} + +bool +ParamTraits::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::Write(Message* aMsg, const paramType& aParam) @@ -70,7 +92,8 @@ ParamTraits::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); @@ -90,15 +113,19 @@ ParamTraits::Read(const Message* aMsg, size_t nbytes; size_t nfds; const char* data; + int owner; + int index; - if (!aMsg->ReadSize(aIter, &nbytes) || + if (!aMsg->ReadInt(aIter, &owner) || + !aMsg->ReadInt32(aIter, &index) || + !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)) { @@ -109,27 +136,41 @@ ParamTraits::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. - bool sameProcess = (XRE_GetProcessType() == GeckoProcessType_Default); - int dupFd = sameProcess ? dup(fd.fd) : fd.fd; + int dupFd = sameProcess && index < 0 ? dup(fd.fd) : fd.fd; fds[n] = dupFd; } - sp buffer(new GraphicBuffer()); + 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 #if ANDROID_VERSION >= 19 - // 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)) { + sp 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; + } #else - Flattenable *flattenable = buffer.get(); + sp buffer(new GraphicBuffer()); + Flattenable *flattenable = buffer.get(); - if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) { + if (NO_ERROR == flattenable->unflatten(data, nbytes, fds, nfds)) { + aResult->mGraphicBuffer = buffer; + } #endif - aResult->mGraphicBuffer = buffer; - return true; + } } - return false; + + if (aResult->mGraphicBuffer == nullptr) { + return false; + } + + return true; } } // namespace IPC @@ -137,8 +178,9 @@ ParamTraits::Read(const Message* aMsg, namespace mozilla { namespace layers { -MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp& aGraphicBuffer) +MagicGrallocBufferHandle::MagicGrallocBufferHandle(const sp& aGraphicBuffer, GrallocBufferRef ref) : mGraphicBuffer(aGraphicBuffer) + , mRef(ref) { } @@ -213,122 +255,6 @@ 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 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() { @@ -342,49 +268,33 @@ LayerManagerComposite::PlatformSyncBeforeReplyUpdate() } //----------------------------------------------------------------------------- -// Child process - -/*static*/ PGrallocBufferChild* -GrallocBufferActor::Create() -{ - return new GrallocBufferActor(); -} - -void -GrallocBufferActor::InitFromHandle(const MagicGrallocBufferHandle& aHandle) -{ - MOZ_ASSERT(!mGraphicBuffer.get()); - MOZ_ASSERT(aHandle.mGraphicBuffer.get()); - - mGraphicBuffer = aHandle.mGraphicBuffer; -} +// Both processes -PGrallocBufferChild* -ShadowLayerForwarder::AllocGrallocBuffer(const gfx::IntSize& aSize, - uint32_t aFormat, - uint32_t aUsage, - MaybeMagicGrallocBufferHandle* aHandle) +/*static*/ sp +GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle) { - if (!mShadowManager->IPCOpen()) { - return nullptr; + 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 mShadowManager->SendPGrallocBufferConstructor(aSize, aFormat, aUsage, aHandle); + return nullptr; } -void -ShadowLayerForwarder::DeallocGrallocBuffer(PGrallocBufferChild* aChild) +android::sp +GetGraphicBufferFromDesc(SurfaceDescriptor aDesc) { - MOZ_ASSERT(aChild); - PGrallocBufferChild::Send__delete__(aChild); -} - -//----------------------------------------------------------------------------- -// Both processes - -android::GraphicBuffer* -GrallocBufferActor::GetGraphicBuffer() -{ - return mGraphicBuffer.get(); + MaybeMagicGrallocBufferHandle handle; + if (aDesc.type() == SurfaceDescriptor::TNewSurfaceDescriptorGralloc) { + handle = aDesc.get_NewSurfaceDescriptorGralloc().buffer(); + } + return GetGraphicBufferFrom(handle); } /*static*/ void diff --git a/gfx/layers/ipc/ShadowLayerUtilsGralloc.h b/gfx/layers/ipc/ShadowLayerUtilsGralloc.h index baaafae2a36e2..99b664f088739 100644 --- a/gfx/layers/ipc/ShadowLayerUtilsGralloc.h +++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.h @@ -11,9 +11,8 @@ #include #include +#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 @@ -22,8 +21,24 @@ 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 @@ -34,11 +49,9 @@ class TextureHost; */ struct MagicGrallocBufferHandle { typedef android::GraphicBuffer GraphicBuffer; + MagicGrallocBufferHandle() {} - MagicGrallocBufferHandle() - { } - - MagicGrallocBufferHandle(const android::sp& aGraphicBuffer); + MagicGrallocBufferHandle(const android::sp& aGraphicBuffer, GrallocBufferRef ref); // Default copy ctor and operator= are OK @@ -47,58 +60,15 @@ struct MagicGrallocBufferHandle { } android::sp mGraphicBuffer; + GrallocBufferRef mRef; }; /** - * GrallocBufferActor is an "IPC wrapper" for an underlying - * GraphicBuffer (pmem region). It allows us to cheaply and - * conveniently share gralloc handles between processes. + * Util function to find GraphicBuffer from SurfaceDescriptor, caller of this function should check origin + * to make sure not corrupt others buffer */ -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 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; -}; +android::sp GetGraphicBufferFrom(MaybeMagicGrallocBufferHandle aHandle); +android::sp GetGraphicBufferFromDesc(SurfaceDescriptor aDesc); } // namespace layers } // namespace mozilla @@ -113,6 +83,14 @@ struct ParamTraits { static bool Read(const Message* aMsg, void** aIter, paramType* aResult); }; +template<> +struct ParamTraits { + 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 diff --git a/gfx/layers/ipc/ShadowLayers.h b/gfx/layers/ipc/ShadowLayers.h index fb940e5a4218d..c817c8ea5533e 100644 --- a/gfx/layers/ipc/ShadowLayers.h +++ b/gfx/layers/ipc/ShadowLayers.h @@ -376,16 +376,6 @@ class ShadowLayerForwarder : public CompositableForwarder RefPtr 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; diff --git a/gfx/layers/ipc/SharedBufferManagerChild.cpp b/gfx/layers/ipc/SharedBufferManagerChild.cpp index b96049cfe71e9..611e4516d79cd 100644 --- a/gfx/layers/ipc/SharedBufferManagerChild.cpp +++ b/gfx/layers/ipc/SharedBufferManagerChild.cpp @@ -297,7 +297,7 @@ void SharedBufferManagerChild::DeallocGrallocBufferNow(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer) { #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC - NS_ASSERTION(aBuffer.type() == mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle, "We shouldn't trying to do IPC with real buffer"); + NS_ASSERTION(aBuffer.type() != mozilla::layers::MaybeMagicGrallocBufferHandle::TMagicGrallocBufferHandle, "We shouldn't trying to do IPC with real buffer"); { MutexAutoLock lock(mBufferMutex); diff --git a/gfx/layers/ipc/SharedBufferManagerParent.cpp b/gfx/layers/ipc/SharedBufferManagerParent.cpp index ddf3aab1ebe39..8e0fbdfe89f5b 100644 --- a/gfx/layers/ipc/SharedBufferManagerParent.cpp +++ b/gfx/layers/ipc/SharedBufferManagerParent.cpp @@ -176,7 +176,7 @@ bool SharedBufferManagerParent::RecvDropGrallocBuffer(const mozilla::layers::May int bufferKey = handle.get_GrallocBufferRef().mKey; sp buf = GetGraphicBuffer(bufferKey); MutexAutoLock lock(mBuffersMutex); - NS_ASSERTION(mBuffers.count(bufferKey) == 0, "How can you drop others buffer"); + NS_ASSERTION(mBuffers.count(bufferKey) == 1, "How can you drop others buffer"); mBuffers.erase(bufferKey); int bpp = 0; @@ -226,7 +226,7 @@ void SharedBufferManagerParent::DropGrallocBufferImpl(mozilla::layers::SurfaceDe key = handle.get_MagicGrallocBufferHandle().mRef.mKey; NS_ASSERTION(key != -1, "Invalid buffer key"); - NS_ASSERTION(mBuffers.count(key) == 0, "How can you drop others buffer"); + NS_ASSERTION(mBuffers.count(key) == 1, "How can you drop others buffer"); mBuffers.erase(key); SendDropGrallocBuffer(handle); #endif @@ -240,7 +240,7 @@ MessageLoop* SharedBufferManagerParent::GetMessageLoop() SharedBufferManagerParent* SharedBufferManagerParent::GetInstance(ProcessId id) { MonitorAutoLock lock(*sManagerMonitor.get()); - NS_ASSERTION(sManagers.count(id) == 0, "No BufferManager for the process"); + NS_ASSERTION(sManagers.count(id) == 1, "No BufferManager for the process"); return sManagers[id]; } @@ -249,7 +249,7 @@ android::sp SharedBufferManagerParent::GetGraphicBuffer(int key) { MutexAutoLock lock(mBuffersMutex); - NS_ASSERTION(mBuffers.count(key) == 0, "No such buffer, or the buffer is belongs to other session"); + NS_ASSERTION(mBuffers.count(key) == 1, "No such buffer, or the buffer is belongs to other session"); return mBuffers[key]; } diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 26378539f0909..a84732f539888 100644 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -147,6 +147,8 @@ 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', @@ -282,6 +284,8 @@ 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', @@ -327,10 +331,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', ] diff --git a/gfx/layers/opengl/GrallocTextureClient.cpp b/gfx/layers/opengl/GrallocTextureClient.cpp index 7b170f69eaf3c..41050d3467632 100644 --- a/gfx/layers/opengl/GrallocTextureClient.cpp +++ b/gfx/layers/opengl/GrallocTextureClient.cpp @@ -20,8 +20,8 @@ using namespace android; class GrallocTextureClientData : public TextureClientData { public: - GrallocTextureClientData(GrallocBufferActor* aActor) - : mGrallocActor(aActor) + GrallocTextureClientData(MaybeMagicGrallocBufferHandle aDesc) + : mGrallocHandle(aDesc) { MOZ_COUNT_CTOR(GrallocTextureClientData); } @@ -29,37 +29,34 @@ class GrallocTextureClientData : public TextureClientData { ~GrallocTextureClientData() { MOZ_COUNT_DTOR(GrallocTextureClientData); - MOZ_ASSERT(!mGrallocActor); } virtual void DeallocateSharedData(ISurfaceAllocator* allocator) MOZ_OVERRIDE { - allocator->DeallocGrallocBuffer(mGrallocActor); - mGrallocActor = nullptr; + allocator->DeallocGrallocBuffer(&mGrallocHandle); } private: - GrallocBufferActor* mGrallocActor; + MaybeMagicGrallocBufferHandle mGrallocHandle; }; TextureClientData* GrallocTextureClientOGL::DropTextureData() { - TextureClientData* result = new GrallocTextureClientData(mGrallocActor); - mGrallocActor = nullptr; - mGraphicBuffer = nullptr; + TextureClientData* result = new GrallocTextureClientData(mGrallocHandle); return result; } -GrallocTextureClientOGL::GrallocTextureClientOGL(GrallocBufferActor* aActor, +GrallocTextureClientOGL::GrallocTextureClientOGL(MaybeMagicGrallocBufferHandle buffer, gfx::IntSize aSize, gfx::BackendType aMoz2dBackend, TextureFlags aFlags) : BufferTextureClient(nullptr, gfx::SurfaceFormat::UNKNOWN, aMoz2dBackend, aFlags) +, mGrallocHandle(buffer) , mMappedBuffer(nullptr) , mMediaBuffer(nullptr) { - InitWith(aActor, aSize); + InitWith(buffer, aSize); MOZ_COUNT_CTOR(GrallocTextureClientOGL); } @@ -79,18 +76,17 @@ GrallocTextureClientOGL::~GrallocTextureClientOGL() MOZ_COUNT_DTOR(GrallocTextureClientOGL); if (ShouldDeallocateInDestructor()) { ISurfaceAllocator* allocator = GetAllocator(); - allocator->DeallocGrallocBuffer(mGrallocActor); + allocator->DeallocGrallocBuffer(&mGrallocHandle); } } void -GrallocTextureClientOGL::InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize) +GrallocTextureClientOGL::InitWith(MaybeMagicGrallocBufferHandle aHandle, gfx::IntSize aSize) { - MOZ_ASSERT(aActor); MOZ_ASSERT(!IsAllocated()); MOZ_ASSERT(IsValid()); - mGrallocActor = aActor; - mGraphicBuffer = aActor->GetGraphicBuffer(); + mGrallocHandle = aHandle; + mGraphicBuffer = GetGraphicBufferFrom(aHandle); mSize = aSize; } @@ -102,7 +98,7 @@ GrallocTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) return false; } - aOutDescriptor = NewSurfaceDescriptorGralloc(nullptr, mGrallocActor, mSize); + aOutDescriptor = NewSurfaceDescriptorGralloc(mGrallocHandle, mSize); return true; } @@ -305,18 +301,16 @@ GrallocTextureClientOGL::AllocateGralloc(gfx::IntSize aSize, ISurfaceAllocator* allocator = GetAllocator(); MaybeMagicGrallocBufferHandle handle; - PGrallocBufferChild* actor = + bool allocateResult = allocator->AllocGrallocBuffer(aSize, aAndroidFormat, aUsage, &handle); - if (!actor) { + if (!allocateResult) { return false; } - GrallocBufferActor* gba = static_cast(actor); - gba->InitFromHandle(handle.get_MagicGrallocBufferHandle()); - sp graphicBuffer = gba->GetGraphicBuffer(); + sp graphicBuffer = GetGraphicBufferFrom(handle); if (!graphicBuffer.get()) { return false; } @@ -325,7 +319,7 @@ GrallocTextureClientOGL::AllocateGralloc(gfx::IntSize aSize, return false; } - mGrallocActor = gba; + mGrallocHandle = handle; mGraphicBuffer = graphicBuffer; mSize = aSize; return true; diff --git a/gfx/layers/opengl/GrallocTextureClient.h b/gfx/layers/opengl/GrallocTextureClient.h index 8c55fdc6d720c..30ee169c082a2 100644 --- a/gfx/layers/opengl/GrallocTextureClient.h +++ b/gfx/layers/opengl/GrallocTextureClient.h @@ -37,7 +37,7 @@ namespace layers { class GrallocTextureClientOGL : public BufferTextureClient { public: - GrallocTextureClientOGL(GrallocBufferActor* aActor, + GrallocTextureClientOGL(MaybeMagicGrallocBufferHandle buffer, gfx::IntSize aSize, gfx::BackendType aMoz2dBackend, TextureFlags aFlags = TextureFlags::DEFAULT); @@ -66,7 +66,7 @@ class GrallocTextureClientOGL : public BufferTextureClient virtual void WaitReleaseFence() MOZ_OVERRIDE; - void InitWith(GrallocBufferActor* aActor, gfx::IntSize aSize); + void InitWith(MaybeMagicGrallocBufferHandle aDesc, gfx::IntSize aSize); void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); } @@ -120,7 +120,7 @@ class GrallocTextureClientOGL : public BufferTextureClient /** * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor. */ - GrallocBufferActor* mGrallocActor; + MaybeMagicGrallocBufferHandle mGrallocHandle; android::sp mGraphicBuffer; diff --git a/gfx/layers/opengl/GrallocTextureHost.cpp b/gfx/layers/opengl/GrallocTextureHost.cpp index 7931d7f6ce775..eb18afb1d9667 100644 --- a/gfx/layers/opengl/GrallocTextureHost.cpp +++ b/gfx/layers/opengl/GrallocTextureHost.cpp @@ -3,12 +3,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 "base/process.h" #include "GLContext.h" #include "gfx2DGlue.h" #include #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" @@ -276,23 +278,18 @@ GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags, const NewSurfaceDescriptorGralloc& aDescriptor) : TextureHost(aFlags) { - android::GraphicBuffer* graphicBuffer = nullptr; - gfx::SurfaceFormat format = gfx::SurfaceFormat::UNKNOWN; + mGrallocHandle = aDescriptor; - mSize = aDescriptor.size(); - mGrallocActor = - static_cast(aDescriptor.bufferParent()); - - if (mGrallocActor) { - mGrallocActor->AddTextureHost(this); - graphicBuffer = mGrallocActor->GetGraphicBuffer(); + android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get(); + if (!graphicBuffer) { + NS_RUNTIMEABORT("Invalid SurfaceDescriptor passed in"); } - if (graphicBuffer) { - format = - SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(), - aFlags); - } + mSize = aDescriptor.size(); + gfx::SurfaceFormat format = + SurfaceFormatForAndroidPixelFormat(graphicBuffer->getPixelFormat(), + aFlags & TextureFlags::RB_SWAPPED); + mTextureSource = new GrallocTextureSourceOGL(nullptr, graphicBuffer, format); @@ -301,10 +298,6 @@ GrallocTextureHostOGL::GrallocTextureHostOGL(TextureFlags aFlags, GrallocTextureHostOGL::~GrallocTextureHostOGL() { mTextureSource = nullptr; - if (mGrallocActor) { - mGrallocActor->RemoveTextureHost(); - mGrallocActor = nullptr; - } } void @@ -347,8 +340,17 @@ GrallocTextureHostOGL::DeallocateSharedData() if (mTextureSource) { mTextureSource->ForgetBuffer(); } - if (mGrallocActor) { - PGrallocBufferParent::Send__delete__(mGrallocActor); + 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); } } diff --git a/gfx/layers/opengl/GrallocTextureHost.h b/gfx/layers/opengl/GrallocTextureHost.h index d581f17e06fb9..1738168d018a6 100644 --- a/gfx/layers/opengl/GrallocTextureHost.h +++ b/gfx/layers/opengl/GrallocTextureHost.h @@ -125,14 +125,8 @@ class GrallocTextureHostOGL : public TextureHost 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: - GrallocBufferActor* mGrallocActor; + NewSurfaceDescriptorGralloc mGrallocHandle; RefPtr mTextureSource; gfx::IntSize mSize; // See comment in textureClientOGL.h }; diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 859e266d1a5f0..f7807c1600430 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -10,6 +10,7 @@ #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" @@ -375,6 +376,9 @@ gfxPlatform::Init() if (gfxPrefs::AsyncVideoEnabled()) { ImageBridgeChild::StartUp(); } +#ifdef MOZ_WIDGET_GONK + SharedBufferManagerChild::StartUp(); +#endif } nsresult rv; @@ -496,7 +500,9 @@ 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; diff --git a/hal/sandbox/PHal.ipdl b/hal/sandbox/PHal.ipdl index 82d012ad6867d..41f75a7d07f68 100644 --- a/hal/sandbox/PHal.ipdl +++ b/hal/sandbox/PHal.ipdl @@ -7,6 +7,8 @@ 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"; diff --git a/ipc/chromium/src/chrome/common/file_descriptor_set_posix.h b/ipc/chromium/src/chrome/common/file_descriptor_set_posix.h index b011baf783aeb..7ef57eec59fb6 100644 --- a/ipc/chromium/src/chrome/common/file_descriptor_set_posix.h +++ b/ipc/chromium/src/chrome/common/file_descriptor_set_posix.h @@ -30,7 +30,7 @@ class FileDescriptorSet : public base::RefCountedThreadSafe { // 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 = 4 + MAX_DESCRIPTORS_PER_MESSAGE = 7 }; // ---------------------------------------------------------------------------