Skip to content

Commit

Permalink
Bug 959089 - Part 2: Use the new protocol to do buffer allocation. r=…
Browse files Browse the repository at this point in the history
…nical
  • Loading branch information
ChiajungHung committed May 1, 2014
1 parent 81e92dc commit 098a829
Show file tree
Hide file tree
Showing 38 changed files with 259 additions and 666 deletions.
8 changes: 8 additions & 0 deletions dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions dom/ipc/ContentChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1595,6 +1596,10 @@ 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();
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/ContentParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class PJavaScriptParent;

namespace layers {
class PCompositorParent;
class PSharedBufferManagerParent;
} // namespace layers

namespace dom {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions dom/ipc/PContent.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -263,6 +264,7 @@ struct PrefSetting {
intr protocol PContent
{
parent opens PCompositor;
parent opens PSharedBufferManager;
parent opens PImageBridge;
child opens PBackground;

Expand Down
9 changes: 9 additions & 0 deletions gfx/layers/GrallocImages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;

android::sp<android::GraphicBuffer> GetGraphicBuffer() const;
Expand All @@ -98,6 +102,11 @@ class GrallocImage : public PlanarYCbCrImage
return static_cast<uint8_t*>(GetNativeBuffer());
}

int GetUsage()
{
return (static_cast<ANativeWindowBuffer*>(GetNativeBuffer()))->usage;
}

private:
RefPtr<GrallocTextureClientOGL> mTextureClient;
};
Expand Down
1 change: 1 addition & 0 deletions gfx/layers/ipc/CompositableTransactionParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions gfx/layers/ipc/ISurfaceAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 5 additions & 12 deletions gfx/layers/ipc/ISurfaceAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class DataSourceSurface;

namespace layers {

class PGrallocBufferChild;
class MaybeMagicGrallocBufferHandle;
class MemoryTextureClient;
class MemoryTextureHost;
Expand Down Expand Up @@ -155,18 +154,12 @@ class ISurfaceAllocator : public AtomicRefCountedWithFinalize<ISurfaceAllocator>
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;
Expand Down
156 changes: 0 additions & 156 deletions gfx/layers/ipc/ImageBridgeChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Shmem;

namespace layers {

class PGrallocBufferChild;
typedef std::vector<CompositableOperation> OpVector;

struct CompositableTransaction
Expand Down Expand Up @@ -204,44 +203,6 @@ 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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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&)
Expand Down
Loading

0 comments on commit 098a829

Please sign in to comment.