From fdec0cf55eca18486eb3136897d721e69a9e6137 Mon Sep 17 00:00:00 2001 From: Ethan Lin Date: Wed, 29 Apr 2015 19:34:00 +0200 Subject: [PATCH] Bug 1053563 - Use a static create function to replace InitWith for TextureClient. r=nical --- gfx/layers/D3D11ShareHandleImage.cpp | 11 ++--- gfx/layers/D3D9SurfaceImage.cpp | 12 ++--- gfx/layers/IMFYCbCrImage.cpp | 34 +++++++++----- gfx/layers/MacIOSurfaceImage.cpp | 7 ++- gfx/layers/d3d11/TextureD3D11.cpp | 44 +++++++++++++++++ gfx/layers/d3d11/TextureD3D11.h | 47 +++++++++---------- gfx/layers/d3d9/TextureD3D9.cpp | 23 +++++++++ gfx/layers/d3d9/TextureD3D9.h | 20 ++++---- gfx/layers/opengl/GrallocTextureClient.cpp | 10 ---- gfx/layers/opengl/GrallocTextureClient.h | 2 - .../opengl/MacIOSurfaceTextureClientOGL.cpp | 16 +++++-- .../opengl/MacIOSurfaceTextureClientOGL.h | 6 ++- 12 files changed, 149 insertions(+), 83 deletions(-) diff --git a/gfx/layers/D3D11ShareHandleImage.cpp b/gfx/layers/D3D11ShareHandleImage.cpp index 94b890651d9..fc8e6945391 100644 --- a/gfx/layers/D3D11ShareHandleImage.cpp +++ b/gfx/layers/D3D11ShareHandleImage.cpp @@ -43,12 +43,11 @@ TextureClient* D3D11ShareHandleImage::GetTextureClient(CompositableClient* aClient) { if (!mTextureClient) { - RefPtr textureClient = - new TextureClientD3D11(aClient->GetForwarder(), - mFormat, - TextureFlags::DEFAULT); - textureClient->InitWith(mTexture, mSize); - mTextureClient = textureClient; + mTextureClient = TextureClientD3D11::Create(aClient->GetForwarder(), + mFormat, + TextureFlags::DEFAULT, + mTexture, + mSize); } return mTextureClient; } diff --git a/gfx/layers/D3D9SurfaceImage.cpp b/gfx/layers/D3D9SurfaceImage.cpp index cc601033259..f5b2f744ee1 100644 --- a/gfx/layers/D3D9SurfaceImage.cpp +++ b/gfx/layers/D3D9SurfaceImage.cpp @@ -202,12 +202,12 @@ D3D9SurfaceImage::GetTextureClient(CompositableClient* aClient) { EnsureSynchronized(); if (!mTextureClient) { - RefPtr textureClient = - new SharedTextureClientD3D9(aClient->GetForwarder(), - gfx::SurfaceFormat::B8G8R8X8, - TextureFlags::DEFAULT); - textureClient->InitWith(mTexture, mShareHandle, mDesc); - mTextureClient = textureClient; + mTextureClient = SharedTextureClientD3D9::Create(aClient->GetForwarder(), + gfx::SurfaceFormat::B8G8R8X8, + TextureFlags::DEFAULT, + mTexture, + mShareHandle, + mDesc); } return mTextureClient; } diff --git a/gfx/layers/IMFYCbCrImage.cpp b/gfx/layers/IMFYCbCrImage.cpp index 33d6279035d..848ac055b1c 100644 --- a/gfx/layers/IMFYCbCrImage.cpp +++ b/gfx/layers/IMFYCbCrImage.cpp @@ -190,12 +190,17 @@ IMFYCbCrImage::GetD3D9TextureClient(CompositableClient* aClient) return nullptr; } - RefPtr texClient = - new DXGIYCbCrTextureClient(aClient->GetForwarder(), TextureFlags::DEFAULT); - texClient->InitWith(textureY, textureCb, textureCr, - shareHandleY, shareHandleCb, shareHandleCr, - GetSize(), mData.mYSize, mData.mCbCrSize); - mTextureClient = texClient; + mTextureClient = DXGIYCbCrTextureClient::Create(aClient->GetForwarder(), + TextureFlags::DEFAULT, + textureY, + textureCb, + textureCr, + shareHandleY, + shareHandleCb, + shareHandleCr, + GetSize(), + mData.mYSize, + mData.mCbCrSize); return mTextureClient; } @@ -268,12 +273,17 @@ IMFYCbCrImage::GetTextureClient(CompositableClient* aClient) textureCr->QueryInterface((IDXGIResource**)byRef(resource)); hr = resource->GetSharedHandle(&shareHandleCr); - RefPtr texClient = - new DXGIYCbCrTextureClient(aClient->GetForwarder(), TextureFlags::DEFAULT); - texClient->InitWith(textureY, textureCb, textureCr, - shareHandleY, shareHandleCb, shareHandleCr, - GetSize(), mData.mYSize, mData.mCbCrSize); - mTextureClient = texClient; + mTextureClient = DXGIYCbCrTextureClient::Create(aClient->GetForwarder(), + TextureFlags::DEFAULT, + textureY, + textureCb, + textureCr, + shareHandleY, + shareHandleCb, + shareHandleCr, + GetSize(), + mData.mYSize, + mData.mCbCrSize); return mTextureClient; } diff --git a/gfx/layers/MacIOSurfaceImage.cpp b/gfx/layers/MacIOSurfaceImage.cpp index 000a308686c..ce8c095da68 100644 --- a/gfx/layers/MacIOSurfaceImage.cpp +++ b/gfx/layers/MacIOSurfaceImage.cpp @@ -15,10 +15,9 @@ TextureClient* MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient) { if (!mTextureClient) { - RefPtr buffer = - new MacIOSurfaceTextureClientOGL(aClient->GetForwarder(), TextureFlags::DEFAULT); - buffer->InitWith(mSurface); - mTextureClient = buffer; + mTextureClient = MacIOSurfaceTextureClientOGL::Create(aClient->GetForwarder(), + TextureFlags::DEFAULT, + mSurface); } return mTextureClient; } diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 95e7bd9cac4..1d4e0dce1a1 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -212,6 +212,22 @@ TextureClientD3D11::~TextureClientD3D11() #endif } +// static +TemporaryRef +TextureClientD3D11::Create(ISurfaceAllocator* aAllocator, + gfx::SurfaceFormat aFormat, + TextureFlags aFlags, + ID3D11Texture2D* aTexture, + gfx::IntSize aSize) +{ + RefPtr texture = new TextureClientD3D11(aAllocator, + aFormat, + aFlags); + texture->mTexture = aTexture; + texture->mSize = aSize; + return texture; +} + TemporaryRef TextureClientD3D11::CreateSimilar(TextureFlags aFlags, TextureAllocationFlags aAllocFlags) const @@ -534,6 +550,34 @@ DXGIYCbCrTextureClient::~DXGIYCbCrTextureClient() MOZ_COUNT_DTOR(DXGIYCbCrTextureClient); } +// static +TemporaryRef +DXGIYCbCrTextureClient::Create(ISurfaceAllocator* aAllocator, + TextureFlags aFlags, + IUnknown* aTextureY, + IUnknown* aTextureCb, + IUnknown* aTextureCr, + HANDLE aHandleY, + HANDLE aHandleCb, + HANDLE aHandleCr, + const gfx::IntSize& aSize, + const gfx::IntSize& aSizeY, + const gfx::IntSize& aSizeCbCr) +{ + RefPtr texture = + new DXGIYCbCrTextureClient(aAllocator, aFlags); + texture->mHandles[0] = aHandleY; + texture->mHandles[1] = aHandleCb; + texture->mHandles[2] = aHandleCr; + texture->mHoldRefs[0] = aTextureY; + texture->mHoldRefs[1] = aTextureCb; + texture->mHoldRefs[2] = aTextureCr; + texture->mSize = aSize; + texture->mSizeY = aSizeY; + texture->mSizeCbCr = aSizeCbCr; + return texture; +} + bool DXGIYCbCrTextureClient::Lock(OpenMode) { diff --git a/gfx/layers/d3d11/TextureD3D11.h b/gfx/layers/d3d11/TextureD3D11.h index c47830dc5b4..f54e829f40c 100644 --- a/gfx/layers/d3d11/TextureD3D11.h +++ b/gfx/layers/d3d11/TextureD3D11.h @@ -32,11 +32,13 @@ public: virtual ~TextureClientD3D11(); - void InitWith(ID3D11Texture2D* aTexture, const gfx::IntSize& aSize) - { - mTexture = aTexture; - mSize = aSize; - } + // Creates a TextureClient and init width. + static TemporaryRef + Create(ISurfaceAllocator* aAllocator, + gfx::SurfaceFormat aFormat, + TextureFlags aFlags, + ID3D11Texture2D* aTexture, + gfx::IntSize aSize); // TextureClient @@ -90,6 +92,20 @@ public: virtual ~DXGIYCbCrTextureClient(); + // Creates a TextureClient and init width. + static TemporaryRef + Create(ISurfaceAllocator* aAllocator, + TextureFlags aFlags, + IUnknown* aTextureY, + IUnknown* aTextureCb, + IUnknown* aTextureCr, + HANDLE aHandleY, + HANDLE aHandleCb, + HANDLE aHandleCr, + const gfx::IntSize& aSize, + const gfx::IntSize& aSizeY, + const gfx::IntSize& aSizeCbCr); + // TextureClient virtual bool IsAllocated() const override{ return !!mHoldRefs[0]; } @@ -102,27 +118,6 @@ public: virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override; - void InitWith(IUnknown* aTextureY, - IUnknown* aTextureCb, - IUnknown* aTextureCr, - HANDLE aHandleY, - HANDLE aHandleCb, - HANDLE aHandleCr, - const gfx::IntSize& aSize, - const gfx::IntSize& aSizeY, - const gfx::IntSize& aSizeCbCr) - { - mHandles[0] = aHandleY; - mHandles[1] = aHandleCb; - mHandles[2] = aHandleCr; - mHoldRefs[0] = aTextureY; - mHoldRefs[1] = aTextureCb; - mHoldRefs[2] = aTextureCr; - mSize = aSize; - mSizeY = aSizeY; - mSizeCbCr = aSizeCbCr; - } - virtual gfx::IntSize GetSize() const { return mSize; diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index e630f22b914..a77065c447e 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -762,6 +762,29 @@ SharedTextureClientD3D9::~SharedTextureClientD3D9() MOZ_COUNT_DTOR(SharedTextureClientD3D9); } +// static +TemporaryRef +SharedTextureClientD3D9::Create(ISurfaceAllocator* aAllocator, + gfx::SurfaceFormat aFormat, + TextureFlags aFlags, + IDirect3DTexture9* aTexture, + HANDLE aSharedHandle, + D3DSURFACE_DESC aDesc) +{ + RefPtr texture = + new SharedTextureClientD3D9(aAllocator, + aFormat, + aFlags); + MOZ_ASSERT(!texture->mTexture); + texture->mTexture = aTexture; + texture->mHandle = aSharedHandle; + texture->mDesc = aDesc; + if (texture->mTexture) { + gfxWindowsPlatform::sD3D9SharedTextureUsed += texture->mDesc.Width * texture->mDesc.Height * 4; + } + return texture; +} + bool SharedTextureClientD3D9::Lock(OpenMode) { diff --git a/gfx/layers/d3d9/TextureD3D9.h b/gfx/layers/d3d9/TextureD3D9.h index 92779a63257..b41e82b8f53 100644 --- a/gfx/layers/d3d9/TextureD3D9.h +++ b/gfx/layers/d3d9/TextureD3D9.h @@ -248,6 +248,15 @@ public: virtual ~SharedTextureClientD3D9(); + // Creates a TextureClient and init width. + static TemporaryRef + Create(ISurfaceAllocator* aAllocator, + gfx::SurfaceFormat aFormat, + TextureFlags aFlags, + IDirect3DTexture9* aTexture, + HANDLE aSharedHandle, + D3DSURFACE_DESC aDesc); + // TextureClient virtual bool IsAllocated() const override { return !!mTexture; } @@ -260,17 +269,6 @@ public: virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override; - void InitWith(IDirect3DTexture9* aTexture, HANDLE aSharedHandle, D3DSURFACE_DESC aDesc) - { - MOZ_ASSERT(!mTexture); - mTexture = aTexture; - mHandle = aSharedHandle; - mDesc = aDesc; - if (mTexture) { - gfxWindowsPlatform::sD3D9SharedTextureUsed += mDesc.Width * mDesc.Height * 4; - } - } - virtual gfx::IntSize GetSize() const { return gfx::IntSize(mDesc.Width, mDesc.Height); diff --git a/gfx/layers/opengl/GrallocTextureClient.cpp b/gfx/layers/opengl/GrallocTextureClient.cpp index f86df1fbc93..8d3cae28f56 100644 --- a/gfx/layers/opengl/GrallocTextureClient.cpp +++ b/gfx/layers/opengl/GrallocTextureClient.cpp @@ -59,16 +59,6 @@ GrallocTextureClientOGL::CreateSimilar(TextureFlags aFlags, return tex; } -void -GrallocTextureClientOGL::InitWith(MaybeMagicGrallocBufferHandle aHandle, gfx::IntSize aSize) -{ - MOZ_ASSERT(!IsAllocated()); - MOZ_ASSERT(IsValid()); - mGrallocHandle = aHandle; - mGraphicBuffer = GetGraphicBufferFrom(aHandle); - mSize = aSize; -} - bool GrallocTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) { diff --git a/gfx/layers/opengl/GrallocTextureClient.h b/gfx/layers/opengl/GrallocTextureClient.h index b031766e0af..a352d51d48f 100644 --- a/gfx/layers/opengl/GrallocTextureClient.h +++ b/gfx/layers/opengl/GrallocTextureClient.h @@ -60,8 +60,6 @@ public: virtual void WaitForBufferOwnership(bool aWaitReleaseFence = true) override; - void InitWith(MaybeMagicGrallocBufferHandle aDesc, gfx::IntSize aSize); - void SetTextureFlags(TextureFlags aFlags) { AddFlags(aFlags); } gfx::IntSize GetSize() const override { return mSize; } diff --git a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp index aad857671c2..c3898b5534a 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp +++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp @@ -22,12 +22,18 @@ MacIOSurfaceTextureClientOGL::~MacIOSurfaceTextureClientOGL() } } -void -MacIOSurfaceTextureClientOGL::InitWith(MacIOSurface* aSurface) +// static +TemporaryRef +MacIOSurfaceTextureClientOGL::Create(ISurfaceAllocator* aAllocator, + TextureFlags aFlags, + MacIOSurface* aSurface) { - MOZ_ASSERT(IsValid()); - MOZ_ASSERT(!IsAllocated()); - mSurface = aSurface; + RefPtr texture = + new MacIOSurfaceTextureClientOGL(aAllocator, aFlags); + MOZ_ASSERT(texture->IsValid()); + MOZ_ASSERT(!texture->IsAllocated()); + texture->mSurface = aSurface; + return texture; } bool diff --git a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h index 80d5135cd63..b7e2fa0550a 100644 --- a/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h +++ b/gfx/layers/opengl/MacIOSurfaceTextureClientOGL.h @@ -21,7 +21,11 @@ public: virtual ~MacIOSurfaceTextureClientOGL(); - void InitWith(MacIOSurface* aSurface); + // Creates a TextureClient and init width. + static TemporaryRef + Create(ISurfaceAllocator* aAllocator, + TextureFlags aFlags, + MacIOSurface* aSurface); virtual bool Lock(OpenMode aMode) override;