From e8ed9905f921a60b9bf8ca1bb930f5c66822f505 Mon Sep 17 00:00:00 2001 From: Jeff Gilbert Date: Tue, 11 Apr 2017 22:58:47 -0700 Subject: [PATCH] Bug 1322746 - Expose DXGI HANDLEs for GPU_VIDEO. - r=mattwoodrow MozReview-Commit-ID: Aea0xGesaQi --- dom/media/ipc/VideoDecoderManagerParent.cpp | 9 ++-- dom/media/ipc/VideoDecoderParent.cpp | 2 +- gfx/layers/client/TextureClient.cpp | 14 +++++- gfx/layers/client/TextureClient.h | 8 ++-- gfx/layers/d3d11/TextureD3D11.cpp | 49 ++++++++++++++++++--- gfx/layers/d3d11/TextureD3D11.h | 4 ++ gfx/layers/ipc/LayersSurfaces.ipdlh | 8 ++++ 7 files changed, 81 insertions(+), 13 deletions(-) diff --git a/dom/media/ipc/VideoDecoderManagerParent.cpp b/dom/media/ipc/VideoDecoderManagerParent.cpp index 70707fafdf80..c267383d0838 100644 --- a/dom/media/ipc/VideoDecoderManagerParent.cpp +++ b/dom/media/ipc/VideoDecoderManagerParent.cpp @@ -39,9 +39,12 @@ using namespace gfx; SurfaceDescriptorGPUVideo VideoDecoderManagerParent::StoreImage(Image* aImage, TextureClient* aTexture) { - mImageMap[aTexture->GetSerial()] = aImage; - mTextureMap[aTexture->GetSerial()] = aTexture; - return SurfaceDescriptorGPUVideo(aTexture->GetSerial()); + SurfaceDescriptorGPUVideo ret; + aTexture->GPUVideoDesc(&ret); + + mImageMap[ret.handle()] = aImage; + mTextureMap[ret.handle()] = aTexture; + return Move(ret); } StaticRefPtr sVideoDecoderManagerThread; diff --git a/dom/media/ipc/VideoDecoderParent.cpp b/dom/media/ipc/VideoDecoderParent.cpp index e5c31deb00fc..400b98b8fda2 100644 --- a/dom/media/ipc/VideoDecoderParent.cpp +++ b/dom/media/ipc/VideoDecoderParent.cpp @@ -199,7 +199,7 @@ VideoDecoderParent::ProcessDecodedData( video->mDisplay, texture ? texture->GetSize() : IntSize(), texture ? mParent->StoreImage(video->mImage, texture) - : SurfaceDescriptorGPUVideo(0), + : SurfaceDescriptorGPUVideo(0, null_t()), video->mFrameID); Unused << SendOutput(output); } diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index b939f1f6b99e..fd11ce9736f0 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -162,7 +162,7 @@ private: // Lock tile A // Lock tile B // Lock tile C - // Apply drawing commands to tiles A, B and C + // Apply drawing commands to tiles A, B and C // Unlock tile A // Unlock tile B // Unlock tile C @@ -1402,6 +1402,18 @@ TextureClient::PrintInfo(std::stringstream& aStream, const char* aPrefix) #endif } +void +TextureClient::GPUVideoDesc(SurfaceDescriptorGPUVideo* const aOutDesc) +{ + const auto handle = GetSerial(); + + GPUVideoSubDescriptor subDesc = null_t(); + MOZ_RELEASE_ASSERT(mData); + mData->GetSubDescriptor(&subDesc); + + *aOutDesc = SurfaceDescriptorGPUVideo(handle, Move(subDesc)); +} + class MemoryTextureReadLock : public NonBlockingTextureReadLock { public: MemoryTextureReadLock(); diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 0f48e02d48d1..df816bbf126c 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -266,6 +266,7 @@ public: virtual void Forget(LayersIPCChannel* aAllocator) {} virtual bool Serialize(SurfaceDescriptor& aDescriptor) = 0; + virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) { } virtual TextureData* CreateSimilar(LayersIPCChannel* aAllocator, @@ -598,12 +599,13 @@ public: const TextureData* GetInternalData() const { return mData; } uint64_t GetSerial() const { return mSerial; } + void GPUVideoDesc(SurfaceDescriptorGPUVideo* aOutDesc); void CancelWaitForRecycle(); /** * Set last transaction id of CompositableForwarder. - * + * * Called when TextureClient has TextureFlags::RECYCLE flag. * When CompositableForwarder forwards the TextureClient with * TextureFlags::RECYCLE, it holds TextureClient's ref until host side @@ -642,7 +644,7 @@ public: private: static void TextureClientRecycleCallback(TextureClient* aClient, void* aClosure); - + // Internal helpers for creating texture clients using the actual forwarder instead // of KnowsCompositor. TextureClientPool uses these to let it cache texture clients // per-process instead of per ShadowLayerForwarder, but everyone else should @@ -657,7 +659,7 @@ private: BackendSelector aSelector, TextureFlags aTextureFlags, TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT); - + static already_AddRefed CreateForRawBufferAccess(LayersIPCChannel* aAllocator, gfx::SurfaceFormat aFormat, diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index a8f627cb3213..5ff976dffafd 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -373,7 +373,7 @@ D3D11TextureData::SyncWithObject(SyncObjectClient* aSyncObject) } bool -DXGITextureData::Serialize(SurfaceDescriptor& aOutDescriptor) +DXGITextureData::SerializeSpecific(SurfaceDescriptorD3D10* const aOutDesc) { RefPtr resource; GetDXGIResource((IDXGIResource**)getter_AddRefs(resource)); @@ -387,10 +387,31 @@ DXGITextureData::Serialize(SurfaceDescriptor& aOutDescriptor) return false; } - aOutDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle, mFormat, mSize); + *aOutDesc = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle, mFormat, mSize); return true; } +bool +DXGITextureData::Serialize(SurfaceDescriptor& aOutDescriptor) +{ + SurfaceDescriptorD3D10 desc; + if (!SerializeSpecific(&desc)) + return false; + + aOutDescriptor = Move(desc); + return true; +} + +void +DXGITextureData::GetSubDescriptor(GPUVideoSubDescriptor* const aOutDesc) +{ + SurfaceDescriptorD3D10 ret; + if (!SerializeSpecific(&ret)) + return; + + *aOutDesc = Move(ret); +} + DXGITextureData* DXGITextureData::Create(IntSize aSize, SurfaceFormat aFormat, TextureAllocationFlags aFlags) { @@ -659,16 +680,34 @@ DXGIYCbCrTextureData::FillInfo(TextureData::Info& aInfo) const aInfo.hasSynchronization = false; } -bool -DXGIYCbCrTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) +void +DXGIYCbCrTextureData::SerializeSpecific(SurfaceDescriptorDXGIYCbCr* const aOutDesc) { - aOutDescriptor = SurfaceDescriptorDXGIYCbCr( + *aOutDesc = SurfaceDescriptorDXGIYCbCr( (WindowsHandle)mHandles[0], (WindowsHandle)mHandles[1], (WindowsHandle)mHandles[2], mSize, mSizeY, mSizeCbCr ); +} + +bool +DXGIYCbCrTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) +{ + SurfaceDescriptorDXGIYCbCr desc; + SerializeSpecific(&desc); + + aOutDescriptor = Move(desc); return true; } +void +DXGIYCbCrTextureData::GetSubDescriptor(GPUVideoSubDescriptor* const aOutDesc) +{ + SurfaceDescriptorDXGIYCbCr desc; + SerializeSpecific(&desc); + + *aOutDesc = Move(desc); +} + void DXGIYCbCrTextureData::Deallocate(LayersIPCChannel*) { diff --git a/gfx/layers/d3d11/TextureD3D11.h b/gfx/layers/d3d11/TextureD3D11.h index 946a9d7e4e3c..42bc55ac7fbf 100644 --- a/gfx/layers/d3d11/TextureD3D11.h +++ b/gfx/layers/d3d11/TextureD3D11.h @@ -39,7 +39,9 @@ class DXGITextureData : public TextureData public: virtual void FillInfo(TextureData::Info& aInfo) const override; + bool SerializeSpecific(SurfaceDescriptorD3D10* aOutDesc); virtual bool Serialize(SurfaceDescriptor& aOutDescrptor) override; + virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) override; static DXGITextureData* Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat, TextureAllocationFlags aFlags); @@ -152,7 +154,9 @@ public: virtual void FillInfo(TextureData::Info& aInfo) const override; + void SerializeSpecific(SurfaceDescriptorDXGIYCbCr* aOutDesc); virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override; + virtual void GetSubDescriptor(GPUVideoSubDescriptor* aOutDesc) override; virtual already_AddRefed BorrowDrawTarget() override { return nullptr; } diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index 9f1d6fd04337..59ffe46a5001 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -80,8 +80,16 @@ struct SurfaceDescriptorSharedGLTexture { bool hasAlpha; }; + +union GPUVideoSubDescriptor { + SurfaceDescriptorD3D10; + SurfaceDescriptorDXGIYCbCr; + null_t; +}; + struct SurfaceDescriptorGPUVideo { uint64_t handle; + GPUVideoSubDescriptor desc; }; struct RGBDescriptor {