Bug 1300676 - Part 1: Allow asynchronous deletion of Shmem for VideoDecoderManagerChild. r=dvander

This commit is contained in:
Matt Woodrow 2016-11-04 13:28:28 +13:00
Родитель 65e7cb7fab
Коммит 4f998dbe2b
11 изменённых файлов: 63 добавлений и 28 удалений

Просмотреть файл

@ -9,6 +9,7 @@
#include "MediaPrefs.h"
#include "nsThreadUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/layers/ISurfaceAllocator.h"
namespace mozilla {
namespace dom {
@ -153,6 +154,23 @@ VideoDecoderManagerChild::DeallocPVideoDecoderManagerChild()
Release();
}
bool
VideoDecoderManagerChild::DeallocShmem(mozilla::ipc::Shmem& aShmem)
{
if (NS_GetCurrentThread() != sVideoDecoderChildThread) {
RefPtr<VideoDecoderManagerChild> self = this;
mozilla::ipc::Shmem shmem = aShmem;
sVideoDecoderChildThread->Dispatch(NS_NewRunnableFunction([self, shmem]() {
if (self->mCanSend) {
mozilla::ipc::Shmem shmemCopy = shmem;
self->DeallocShmem(shmemCopy);
}
}), NS_DISPATCH_NORMAL);
return true;
}
return PVideoDecoderManagerChild::DeallocShmem(aShmem);
}
void
VideoDecoderManagerChild::DeallocateSurfaceDescriptorGPUVideo(const SurfaceDescriptorGPUVideo& aSD)
{

Просмотреть файл

@ -13,6 +13,7 @@ namespace mozilla {
namespace dom {
class VideoDecoderManagerChild final : public PVideoDecoderManagerChild
, public mozilla::ipc::IShmemAllocator
{
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VideoDecoderManagerChild)
@ -28,6 +29,23 @@ public:
// and will be ignored if the IPDL actor has been destroyed.
void DeallocateSurfaceDescriptorGPUVideo(const SurfaceDescriptorGPUVideo& aSD);
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override
{
return PVideoDecoderManagerChild::AllocShmem(aSize, aShmType, aShmem);
}
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override
{
return PVideoDecoderManagerChild::AllocUnsafeShmem(aSize, aShmType, aShmem);
}
// Can be called from any thread, dispatches the request to the IPDL thread internally
// and will be ignored if the IPDL actor has been destroyed.
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
// Main thread only
static void Initialize();
static void Shutdown();

Просмотреть файл

@ -1031,13 +1031,13 @@ CompositorBridgeChild::AllocShmem(size_t aSize,
return PCompositorBridgeChild::AllocShmem(aSize, aType, aShmem);
}
void
bool
CompositorBridgeChild::DeallocShmem(ipc::Shmem& aShmem)
{
if (!mCanSend) {
return;
return false;
}
PCompositorBridgeChild::DeallocShmem(aShmem);
return PCompositorBridgeChild::DeallocShmem(aShmem);
}
widget::PCompositorWidgetChild*

Просмотреть файл

@ -210,7 +210,7 @@ public:
virtual bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
virtual bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
PCompositorWidgetChild* AllocPCompositorWidgetChild(const CompositorWidgetInitData& aInitData) override;
bool DeallocPCompositorWidgetChild(PCompositorWidgetChild* aActor) override;

Просмотреть файл

@ -1073,37 +1073,40 @@ ImageBridgeChild::DispatchAllocShmemInternal(size_t aSize,
void
ImageBridgeChild::ProxyDeallocShmemNow(SynchronousTask* aTask,
ipc::Shmem* aShmem)
ipc::Shmem* aShmem,
bool* aResult)
{
AutoCompleteTask complete(aTask);
if (!CanSend()) {
return;
}
DeallocShmem(*aShmem);
*aResult = DeallocShmem(*aShmem);
}
void
bool
ImageBridgeChild::DeallocShmem(ipc::Shmem& aShmem)
{
if (InImageBridgeChildThread()) {
if (!CanSend()) {
return;
return false;
}
PImageBridgeChild::DeallocShmem(aShmem);
return;
return PImageBridgeChild::DeallocShmem(aShmem);
}
SynchronousTask task("AllocatorProxy Dealloc");
bool result = false;
RefPtr<Runnable> runnable = WrapRunnable(
RefPtr<ImageBridgeChild>(this),
&ImageBridgeChild::ProxyDeallocShmemNow,
&task,
&aShmem);
&aShmem,
&result);
GetMessageLoop()->PostTask(runnable.forget());
task.Wait();
return result;
}
PTextureChild*

Просмотреть файл

@ -258,7 +258,7 @@ private:
ImageContainer* aContainer);
void ProxyAllocShmemNow(SynchronousTask* aTask, AllocShmemParams* aParams);
void ProxyDeallocShmemNow(SynchronousTask* aTask, Shmem* aShmem);
void ProxyDeallocShmemNow(SynchronousTask* aTask, Shmem* aShmem, bool* aResult);
public:
// CompositableForwarder
@ -332,7 +332,7 @@ public:
* If used outside the ImageBridgeChild thread, it will proxy a synchronous
* call on the ImageBridgeChild thread.
*/
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
virtual bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData,
LayersBackend aLayersBackend,

Просмотреть файл

@ -14,6 +14,9 @@
#include "mozilla/layers/KnowsCompositor.h"
namespace mozilla {
namespace ipc {
class IShmemAllocator;
}
namespace layers {
/**
@ -31,7 +34,8 @@ public:
* Has their own MessageLoop for message dispatch, and can allocate
* shmem.
*/
class LayersIPCChannel : public LayersIPCActor {
class LayersIPCChannel : public LayersIPCActor
, public mozilla::ipc::IShmemAllocator {
public:
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
@ -48,14 +52,6 @@ public:
virtual void CancelWaitForRecycle(uint64_t aTextureId) = 0;
virtual bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) = 0;
protected:
virtual ~LayersIPCChannel() {}
};

Просмотреть файл

@ -66,10 +66,10 @@ VideoBridgeChild::AllocShmem(size_t aSize,
return PVideoBridgeChild::AllocShmem(aSize, aType, aShmem);
}
void
bool
VideoBridgeChild::DeallocShmem(ipc::Shmem& aShmem)
{
PVideoBridgeChild::DeallocShmem(aShmem);
return PVideoBridgeChild::DeallocShmem(aShmem);
}
PTextureChild*

Просмотреть файл

@ -38,7 +38,7 @@ public:
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) override;
void DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
// TextureForwarder
PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData,

Просмотреть файл

@ -377,10 +377,10 @@ VRManagerChild::AllocUnsafeShmem(size_t aSize,
return PVRManagerChild::AllocUnsafeShmem(aSize, aType, aShmem);
}
void
bool
VRManagerChild::DeallocShmem(ipc::Shmem& aShmem)
{
PVRManagerChild::DeallocShmem(aShmem);
return PVRManagerChild::DeallocShmem(aShmem);
}
PVRLayerChild*

Просмотреть файл

@ -130,7 +130,7 @@ protected:
ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
virtual void DeallocShmem(ipc::Shmem& aShmem) override;
virtual bool DeallocShmem(ipc::Shmem& aShmem) override;
virtual bool IsSameProcess() const override
{