Bug 989904 - Remove deprecated d3d textures. r=mattwoodrow

This commit is contained in:
Nicolas Silva 2014-04-01 14:28:14 +08:00
parent 93524a4fe4
commit c0c75c9a81
5 changed files with 6 additions and 1666 deletions

View File

@ -124,16 +124,6 @@ TemporaryRef<DeprecatedTextureHost> CreateBasicDeprecatedTextureHost(SurfaceDesc
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags);
#ifdef XP_WIN
TemporaryRef<DeprecatedTextureHost> CreateDeprecatedTextureHostD3D9(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags);
TemporaryRef<DeprecatedTextureHost> CreateDeprecatedTextureHostD3D11(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags);
#endif
/* static */ TemporaryRef<DeprecatedTextureHost>
DeprecatedTextureHost::CreateDeprecatedTextureHost(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
@ -152,16 +142,6 @@ DeprecatedTextureHost::CreateDeprecatedTextureHost(SurfaceDescriptorType aDescri
}
return result;
}
#ifdef XP_WIN
case LayersBackend::LAYERS_D3D9:
return CreateDeprecatedTextureHostD3D9(aDescriptorType,
aDeprecatedTextureHostFlags,
aTextureFlags);
case LayersBackend::LAYERS_D3D11:
return CreateDeprecatedTextureHostD3D11(aDescriptorType,
aDeprecatedTextureHostFlags,
aTextureFlags);
#endif
case LayersBackend::LAYERS_BASIC:
return CreateBasicDeprecatedTextureHost(aDescriptorType,
aDeprecatedTextureHostFlags,

View File

@ -432,32 +432,12 @@ DataTextureSourceD3D11::SetCompositor(Compositor* aCompositor)
mCompositor = d3dCompositor;
}
TemporaryRef<DeprecatedTextureHost>
CreateDeprecatedTextureHostD3D11(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags)
{
RefPtr<DeprecatedTextureHost> result;
if (aDescriptorType == SurfaceDescriptor::TYCbCrImage) {
result = new DeprecatedTextureHostYCbCrD3D11();
} else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorD3D10) {
result = new DeprecatedTextureHostDXGID3D11();
} else {
result = new DeprecatedTextureHostShmemD3D11();
}
result->SetFlags(aTextureFlags);
return result;
}
CompositingRenderTargetD3D11::CompositingRenderTargetD3D11(ID3D11Texture2D* aTexture,
const gfx::IntPoint& aOrigin)
: CompositingRenderTarget(aOrigin)
{
MOZ_ASSERT(aTexture);
mTexture = aTexture;
RefPtr<ID3D11Device> device;
@ -476,483 +456,5 @@ CompositingRenderTargetD3D11::GetSize() const
return TextureSourceD3D11::GetSize();
}
DeprecatedTextureClientD3D11::DeprecatedTextureClientD3D11(
CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo)
: DeprecatedTextureClient(aCompositableForwarder, aTextureInfo)
, mIsLocked(false)
{
mTextureInfo = aTextureInfo;
}
DeprecatedTextureClientD3D11::~DeprecatedTextureClientD3D11()
{
mDescriptor = SurfaceDescriptor();
ClearDT();
}
bool
DeprecatedTextureClientD3D11::EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType)
{
D3D10_TEXTURE2D_DESC desc;
if (mTexture) {
mTexture->GetDesc(&desc);
if (desc.Width == aSize.width && desc.Height == aSize.height) {
return true;
}
mTexture = nullptr;
mSurface = nullptr;
ClearDT();
}
mSize = aSize;
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
aSize.width, aSize.height, 1, 1,
D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX;
HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, byRef(mTexture));
if (FAILED(hr)) {
LOGD3D11("Error creating texture for client!");
return false;
}
RefPtr<IDXGIResource> resource;
mTexture->QueryInterface((IDXGIResource**)byRef(resource));
HANDLE sharedHandle;
hr = resource->GetSharedHandle(&sharedHandle);
if (FAILED(hr)) {
LOGD3D11("Error getting shared handle for texture.");
return false;
}
mDescriptor = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle,
gfxPlatform::GetPlatform()->Optimal2DFormatForContent(aType));
mContentType = aType;
return true;
}
gfxASurface*
DeprecatedTextureClientD3D11::LockSurface()
{
EnsureSurface();
LockTexture();
return mSurface.get();
}
DrawTarget*
DeprecatedTextureClientD3D11::LockDrawTarget()
{
EnsureDrawTarget();
LockTexture();
return mDrawTarget.get();
}
void
DeprecatedTextureClientD3D11::Unlock()
{
// TODO - Things seem to believe they can hold on to our surface... well...
// They shouldn't!!
ReleaseTexture();
}
void
DeprecatedTextureClientD3D11::SetDescriptor(const SurfaceDescriptor& aDescriptor)
{
if (aDescriptor.type() == SurfaceDescriptor::Tnull_t) {
EnsureAllocated(mSize, mContentType);
return;
}
mDescriptor = aDescriptor;
mSurface = nullptr;
ClearDT();
if (aDescriptor.type() == SurfaceDescriptor::T__None) {
return;
}
MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
HRESULT hr = device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(),
__uuidof(ID3D10Texture2D),
(void**)(ID3D10Texture2D**)byRef(mTexture));
NS_WARN_IF_FALSE(mTexture && SUCCEEDED(hr), "Could not open shared resource");
}
void
DeprecatedTextureClientD3D11::EnsureSurface()
{
if (mSurface) {
return;
}
LockTexture();
mSurface = new gfxD2DSurface(mTexture, mContentType);
ReleaseTexture();
}
void
DeprecatedTextureClientD3D11::EnsureDrawTarget()
{
if (mDrawTarget) {
return;
}
LockTexture();
SurfaceFormat format;
switch (mContentType) {
case gfxContentType::ALPHA:
format = SurfaceFormat::A8;
break;
case gfxContentType::COLOR:
format = SurfaceFormat::B8G8R8X8;
break;
case gfxContentType::COLOR_ALPHA:
format = SurfaceFormat::B8G8R8A8;
break;
default:
format = SurfaceFormat::B8G8R8A8;
}
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, format);
ReleaseTexture();
}
void
DeprecatedTextureClientD3D11::LockTexture()
{
RefPtr<IDXGIKeyedMutex> mutex;
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
mutex->AcquireSync(0, INFINITE);
mIsLocked = true;
}
void
DeprecatedTextureClientD3D11::ReleaseTexture()
{
// TODO - Bas - We seem to have places that unlock without ever having locked,
// that's kind of bad.
if (!mIsLocked) {
return;
}
if (mDrawTarget) {
mDrawTarget->Flush();
}
RefPtr<IDXGIKeyedMutex> mutex;
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
mutex->ReleaseSync(0);
mIsLocked = false;
}
void
DeprecatedTextureClientD3D11::ClearDT()
{
// An Azure DrawTarget needs to be locked when it gets nullptr'ed as this is
// when it calls EndDraw. This EndDraw should not execute anything so it
// shouldn't -really- need the lock but the debug layer chokes on this.
//
// Perhaps this should be debug only.
if (mDrawTarget) {
LockTexture();
mDrawTarget = nullptr;
ReleaseTexture();
}
}
IntSize
DeprecatedTextureHostShmemD3D11::GetSize() const
{
if (mIterating) {
gfx::IntRect rect = GetTileRect(mCurrentTile);
return gfx::IntSize(rect.width, rect.height);
}
return TextureSourceD3D11::GetSize();
}
nsIntRect
DeprecatedTextureHostShmemD3D11::GetTileRect()
{
IntRect rect = GetTileRect(mCurrentTile);
return nsIntRect(rect.x, rect.y, rect.width, rect.height);
}
void
DeprecatedTextureHostShmemD3D11::SetCompositor(Compositor* aCompositor)
{
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
mDevice = d3dCompositor ? d3dCompositor->GetDevice() : nullptr;
}
void
DeprecatedTextureHostShmemD3D11::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion* aRegion,
nsIntPoint* aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TShmem ||
aImage.type() == SurfaceDescriptor::TMemoryImage);
AutoOpenSurface openSurf(OPEN_READ_ONLY, aImage);
nsRefPtr<gfxImageSurface> surf = openSurf.GetAsImage();
gfx::IntSize size = gfx::ToIntSize(surf->GetSize());
uint32_t bpp = 0;
DXGI_FORMAT dxgiFormat;
switch (surf->Format()) {
case gfxImageFormat::RGB24:
mFormat = SurfaceFormat::B8G8R8X8;
dxgiFormat = DXGI_FORMAT_B8G8R8X8_UNORM;
bpp = 4;
break;
case gfxImageFormat::ARGB32:
mFormat = SurfaceFormat::B8G8R8A8;
dxgiFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
bpp = 4;
break;
case gfxImageFormat::A8:
mFormat = SurfaceFormat::A8;
dxgiFormat = DXGI_FORMAT_A8_UNORM;
bpp = 1;
break;
default:
NS_ERROR("Bad image format");
}
mSize = size;
CD3D11_TEXTURE2D_DESC desc(dxgiFormat, size.width, size.height,
1, 1, D3D11_BIND_SHADER_RESOURCE,
D3D11_USAGE_IMMUTABLE);
int32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
if (size.width <= maxSize && size.height <= maxSize) {
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = surf->Data();
initData.SysMemPitch = surf->Stride();
mDevice->CreateTexture2D(&desc, &initData, byRef(mTexture));
mIsTiled = false;
} else {
mIsTiled = true;
uint32_t tileCount = GetRequiredTilesD3D11(size.width, maxSize) *
GetRequiredTilesD3D11(size.height, maxSize);
mTileTextures.resize(tileCount);
for (uint32_t i = 0; i < tileCount; i++) {
IntRect tileRect = GetTileRect(i);
desc.Width = tileRect.width;
desc.Height = tileRect.height;
D3D11_SUBRESOURCE_DATA initData;
initData.pSysMem = surf->Data() +
tileRect.y * surf->Stride() +
tileRect.x * bpp;
initData.SysMemPitch = surf->Stride();
mDevice->CreateTexture2D(&desc, &initData, byRef(mTileTextures[i]));
}
}
}
IntRect
DeprecatedTextureHostShmemD3D11::GetTileRect(uint32_t aID) const
{
uint32_t maxSize = GetMaxTextureSizeForFeatureLevel(mDevice->GetFeatureLevel());
return GetTileRectD3D11(aID, mSize, maxSize);
}
void
DeprecatedTextureHostDXGID3D11::SetCompositor(Compositor* aCompositor)
{
CompositorD3D11* d3dCompositor = static_cast<CompositorD3D11*>(aCompositor);
mDevice = d3dCompositor ? d3dCompositor->GetDevice() : nullptr;
}
IntSize
DeprecatedTextureHostDXGID3D11::GetSize() const
{
return TextureSourceD3D11::GetSize();
}
bool
DeprecatedTextureHostDXGID3D11::Lock()
{
LockTexture();
return true;
}
void
DeprecatedTextureHostDXGID3D11::Unlock()
{
ReleaseTexture();
}
void
DeprecatedTextureHostDXGID3D11::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion* aRegion,
nsIntPoint* aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorD3D10);
HRESULT hr =mDevice->OpenSharedResource((HANDLE)aImage.get_SurfaceDescriptorD3D10().handle(),
__uuidof(ID3D11Texture2D),
(void**)(ID3D11Texture2D**)byRef(mTexture));
if (!mTexture || FAILED(hr)) {
NS_WARNING("Could not open shared resource");
mSize = IntSize(0, 0);
return;
}
mFormat = aImage.get_SurfaceDescriptorD3D10().format();
D3D11_TEXTURE2D_DESC desc;
mTexture->GetDesc(&desc);
mSize = IntSize(desc.Width, desc.Height);
}
void
DeprecatedTextureHostDXGID3D11::LockTexture()
{
if (!mTexture) {
return;
}
RefPtr<IDXGIKeyedMutex> mutex;
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
mutex->AcquireSync(0, INFINITE);
}
void
DeprecatedTextureHostDXGID3D11::ReleaseTexture()
{
if (!mTexture) {
return;
}
RefPtr<IDXGIKeyedMutex> mutex;
mTexture->QueryInterface((IDXGIKeyedMutex**)byRef(mutex));
mutex->ReleaseSync(0);
}
DeprecatedTextureHostYCbCrD3D11::DeprecatedTextureHostYCbCrD3D11()
: mCompositor(nullptr)
{
mFormat = SurfaceFormat::YUV;
}
DeprecatedTextureHostYCbCrD3D11::~DeprecatedTextureHostYCbCrD3D11()
{
}
ID3D11Device*
DeprecatedTextureHostYCbCrD3D11::GetDevice()
{
return mCompositor ? mCompositor->GetDevice() : nullptr;
NewTextureSource* source = mFirstSource.get();
while (source) {
static_cast<DataTextureSourceD3D11*>(source)->SetCompositor(mCompositor);
source = source->GetNextSibling();
}
}
void
DeprecatedTextureHostYCbCrD3D11::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<CompositorD3D11*>(aCompositor);
NewTextureSource* source = mFirstSource.get();
while (source) {
static_cast<DataTextureSourceD3D11*>(source)->SetCompositor(mCompositor);
source = source->GetNextSibling();
}
}
void
DeprecatedTextureHostYCbCrD3D11::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion* aRegion,
nsIntPoint* aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TYCbCrImage);
YCbCrImageDataDeserializer yuvDeserializer(aImage.get_YCbCrImage().data().get<uint8_t>(),
aImage.get_YCbCrImage().data().Size<uint8_t>());
gfx::IntSize gfxCbCrSize = yuvDeserializer.GetCbCrSize();
gfx::IntSize size = yuvDeserializer.GetYSize();
RefPtr<DataTextureSource> srcY;
RefPtr<DataTextureSource> srcCb;
RefPtr<DataTextureSource> srcCr;
if (!mFirstSource) {
srcY = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, TEXTURE_DISALLOW_BIGIMAGE);
srcCb = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, TEXTURE_DISALLOW_BIGIMAGE);
srcCr = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, TEXTURE_DISALLOW_BIGIMAGE);
mFirstSource = srcY;
srcY->SetNextSibling(srcCb);
srcCb->SetNextSibling(srcCr);
} else {
MOZ_ASSERT(mFirstSource->GetNextSibling());
MOZ_ASSERT(mFirstSource->GetNextSibling()->GetNextSibling());
srcY = mFirstSource;
srcCb = mFirstSource->GetNextSibling()->AsDataTextureSource();
srcCr = mFirstSource->GetNextSibling()->GetNextSibling()->AsDataTextureSource();
}
RefPtr<gfx::DataSourceSurface> wrapperY =
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetYData(),
yuvDeserializer.GetYStride(),
yuvDeserializer.GetYSize(),
SurfaceFormat::A8);
RefPtr<gfx::DataSourceSurface> wrapperCb =
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCbData(),
yuvDeserializer.GetCbCrStride(),
yuvDeserializer.GetCbCrSize(),
SurfaceFormat::A8);
RefPtr<gfx::DataSourceSurface> wrapperCr =
gfx::Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCrData(),
yuvDeserializer.GetCbCrStride(),
yuvDeserializer.GetCbCrSize(),
SurfaceFormat::A8);
// We don't support partial updates for YCbCr textures
NS_ASSERTION(!aRegion, "Unsupported partial updates for YCbCr textures");
if (!srcY->Update(wrapperY) ||
!srcCb->Update(wrapperCb) ||
!srcCr->Update(wrapperCr)) {
NS_WARNING("failed to update the DataTextureSource");
mFirstSource = nullptr;
mSize.width = 0;
mSize.height = 0;
return;
}
mSize = IntSize(size.width, size.height);
}
}
}

View File

@ -224,207 +224,6 @@ private:
RefPtr<ID3D11RenderTargetView> mRTView;
};
class DeprecatedTextureClientD3D11 : public DeprecatedTextureClient
{
public:
DeprecatedTextureClientD3D11(CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo);
virtual ~DeprecatedTextureClientD3D11();
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE
{
return aType == TEXTURE_CONTENT;
}
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType) MOZ_OVERRIDE;
virtual gfxASurface* LockSurface() MOZ_OVERRIDE;
virtual gfx::DrawTarget* LockDrawTarget() MOZ_OVERRIDE;
virtual gfx::BackendType BackendType() MOZ_OVERRIDE
{
return gfx::BackendType::DIRECT2D;
}
virtual void Unlock() MOZ_OVERRIDE;
virtual void SetDescriptor(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
virtual gfxContentType GetContentType() MOZ_OVERRIDE
{
return mContentType;
}
private:
void EnsureSurface();
void EnsureDrawTarget();
void LockTexture();
void ReleaseTexture();
void ClearDT();
RefPtr<ID3D10Texture2D> mTexture;
nsRefPtr<gfxD2DSurface> mSurface;
RefPtr<gfx::DrawTarget> mDrawTarget;
gfx::IntSize mSize;
bool mIsLocked;
gfxContentType mContentType;
};
class DeprecatedTextureHostShmemD3D11 : public DeprecatedTextureHost
, public TextureSourceD3D11
, public TileIterator
{
public:
DeprecatedTextureHostShmemD3D11()
: mDevice(nullptr)
, mIsTiled(false)
, mCurrentTile(0)
, mIterating(false)
{
}
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
virtual ID3D11Texture2D* GetD3D11Texture() const MOZ_OVERRIDE
{
return mIsTiled ? mTileTextures[mCurrentTile].get()
: TextureSourceD3D11::GetD3D11Texture();
}
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual LayerRenderState GetRenderState() MOZ_OVERRIDE
{
return LayerRenderState();
}
virtual bool Lock() MOZ_OVERRIDE { return true; }
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr;
}
virtual const char* Name() MOZ_OVERRIDE
{
return "DeprecatedTextureHostShmemD3D11";
}
virtual void BeginTileIteration() MOZ_OVERRIDE
{
mIterating = true;
mCurrentTile = 0;
}
virtual void EndTileIteration() MOZ_OVERRIDE
{
mIterating = false;
}
virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
virtual size_t GetTileCount() MOZ_OVERRIDE { return mTileTextures.size(); }
virtual bool NextTile() MOZ_OVERRIDE
{
return (++mCurrentTile < mTileTextures.size());
}
virtual TileIterator* AsTileIterator() MOZ_OVERRIDE
{
return mIsTiled ? this : nullptr;
}
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint *aOffset = nullptr) MOZ_OVERRIDE;
private:
gfx::IntRect GetTileRect(uint32_t aID) const;
RefPtr<ID3D11Device> mDevice;
bool mIsTiled;
std::vector< RefPtr<ID3D11Texture2D> > mTileTextures;
uint32_t mCurrentTile;
bool mIterating;
};
class DeprecatedTextureHostDXGID3D11 : public DeprecatedTextureHost
, public TextureSourceD3D11
{
public:
DeprecatedTextureHostDXGID3D11()
: mDevice(nullptr)
{
}
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE { return this; }
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual bool Lock() MOZ_OVERRIDE;
virtual void Unlock() MOZ_OVERRIDE;
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // TODO: cf bug 872568
}
virtual const char* Name() { return "DeprecatedTextureHostDXGID3D11"; }
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint* aOffset = nullptr) MOZ_OVERRIDE;
private:
void LockTexture();
void ReleaseTexture();
RefPtr<ID3D11Device> mDevice;
};
class DeprecatedTextureHostYCbCrD3D11 : public DeprecatedTextureHost
{
public:
DeprecatedTextureHostYCbCrD3D11();
~DeprecatedTextureHostYCbCrD3D11();
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual TextureSourceD3D11* AsSourceD3D11() MOZ_OVERRIDE
{
return mFirstSource->AsSourceD3D11();
}
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
TextureSource* GetSubSource(int index) MOZ_OVERRIDE
{
return mFirstSource ? mFirstSource->GetSubSource(index) : nullptr;
}
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // TODO: cf bug 872568
}
virtual const char* Name() MOZ_OVERRIDE
{
return "TextureImageDeprecatedTextureHostD3D11";
}
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint* aOffset = nullptr) MOZ_OVERRIDE;
ID3D11Device* GetDevice();
private:
gfx::IntSize mSize;
RefPtr<DataTextureSource> mFirstSource;
RefPtr<CompositorD3D11> mCompositor;
};
inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel)
{
int32_t maxTextureSize;

View File

@ -20,24 +20,13 @@ using namespace mozilla::gfx;
namespace mozilla {
namespace layers {
TemporaryRef<DeprecatedTextureHost>
CreateDeprecatedTextureHostD3D9(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags)
static uint32_t GetRequiredTilesD3D9(uint32_t aSize, uint32_t aMaxSize)
{
RefPtr<DeprecatedTextureHost> result;
if (aDescriptorType == SurfaceDescriptor::TYCbCrImage) {
result = new DeprecatedTextureHostYCbCrD3D9();
} else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorD3D9) {
result = new DeprecatedTextureHostSystemMemD3D9();
} else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorDIB) {
result = new DeprecatedTextureHostDIB();
} else {
result = new DeprecatedTextureHostShmemD3D9();
uint32_t requiredTiles = aSize / aMaxSize;
if (aSize % aMaxSize) {
requiredTiles++;
}
result->SetFlags(aTextureFlags);
return result;
return requiredTiles;
}
TextureSourceD3D9::~TextureSourceD3D9()
@ -168,51 +157,6 @@ CompositingRenderTargetD3D9::GetSize() const
return TextureSourceD3D9::GetSize();
}
DeprecatedTextureHostD3D9::DeprecatedTextureHostD3D9()
: mIsTiled(false)
, mCurrentTile(0)
, mIterating(false)
{
MOZ_COUNT_CTOR(DeprecatedTextureHostD3D9);
}
DeprecatedTextureHostD3D9::~DeprecatedTextureHostD3D9()
{
MOZ_COUNT_DTOR(DeprecatedTextureHostD3D9);
}
IntSize
DeprecatedTextureHostD3D9::GetSize() const
{
if (mIterating) {
IntRect rect = GetTileRect(mCurrentTile);
return rect.Size();
}
return TextureSourceD3D9::GetSize();
}
nsIntRect
DeprecatedTextureHostD3D9::GetTileRect()
{
IntRect rect = GetTileRect(mCurrentTile);
return nsIntRect(rect.x, rect.y, rect.width, rect.height);
}
static uint32_t GetRequiredTilesD3D9(uint32_t aSize, uint32_t aMaxSize)
{
uint32_t requiredTiles = aSize / aMaxSize;
if (aSize % aMaxSize) {
requiredTiles++;
}
return requiredTiles;
}
void
DeprecatedTextureHostD3D9::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<CompositorD3D9*>(aCompositor);
}
/**
* Helper method for DataToTexture and SurfaceToTexture.
* The last three params are out params.
@ -302,203 +246,6 @@ TextureSourceD3D9::DataToTexture(DeviceManagerD3D9* aDeviceManager,
return texture;
}
void
DeprecatedTextureHostD3D9::Reset()
{
mSize.width = 0;
mSize.height = 0;
mTexture = nullptr;
mIsTiled = false;
}
void
DeprecatedTextureHostShmemD3D9::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion *aRegion,
nsIntPoint *aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TShmem ||
aImage.type() == SurfaceDescriptor::TMemoryImage);
MOZ_ASSERT(mCompositor, "Must have compositor to update.");
if (!mCompositor->device()) {
return;
}
AutoOpenSurface openSurf(OPEN_READ_ONLY, aImage);
nsRefPtr<gfxImageSurface> surf = openSurf.GetAsImage();
mSize = ToIntSize(surf->GetSize());
uint32_t bpp = 0;
_D3DFORMAT format = D3DFMT_A8R8G8B8;
switch (surf->Format()) {
case gfxImageFormat::RGB24:
mFormat = SurfaceFormat::B8G8R8X8;
format = D3DFMT_X8R8G8B8;
bpp = 4;
break;
case gfxImageFormat::ARGB32:
mFormat = SurfaceFormat::B8G8R8A8;
format = D3DFMT_A8R8G8B8;
bpp = 4;
break;
case gfxImageFormat::A8:
mFormat = SurfaceFormat::A8;
format = D3DFMT_A8;
bpp = 1;
break;
default:
NS_ERROR("Bad image format");
}
int32_t maxSize = mCompositor->GetMaxTextureSize();
if (mSize.width <= maxSize && mSize.height <= maxSize) {
mTexture = DataToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
surf->Data(), surf->Stride(),
mSize, format, bpp);
if (!mTexture) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
mIsTiled = false;
} else {
mIsTiled = true;
uint32_t tileCount = GetRequiredTilesD3D9(mSize.width, maxSize) *
GetRequiredTilesD3D9(mSize.height, maxSize);
mTileTextures.resize(tileCount);
for (uint32_t i = 0; i < tileCount; i++) {
IntRect tileRect = GetTileRect(i);
unsigned char* data = surf->Data() +
tileRect.y * surf->Stride() +
tileRect.x * bpp;
mTileTextures[i] = DataToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
data,
surf->Stride(),
tileRect.Size(),
format,
bpp);
if (!mTileTextures[i]) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
}
}
}
IntRect
DeprecatedTextureHostD3D9::GetTileRect(uint32_t aID) const
{
uint32_t maxSize = mCompositor->GetMaxTextureSize();
uint32_t horizontalTiles = GetRequiredTilesD3D9(mSize.width, maxSize);
uint32_t verticalTiles = GetRequiredTilesD3D9(mSize.height, maxSize);
uint32_t verticalTile = aID / horizontalTiles;
uint32_t horizontalTile = aID % horizontalTiles;
return IntRect(horizontalTile * maxSize,
verticalTile * maxSize,
horizontalTile < (horizontalTiles - 1) ? maxSize : mSize.width % maxSize,
verticalTile < (verticalTiles - 1) ? maxSize : mSize.height % maxSize);
}
DeprecatedTextureHostYCbCrD3D9::DeprecatedTextureHostYCbCrD3D9()
: mCompositor(nullptr)
{
mFormat = SurfaceFormat::YUV;
MOZ_COUNT_CTOR(DeprecatedTextureHostYCbCrD3D9);
}
DeprecatedTextureHostYCbCrD3D9::~DeprecatedTextureHostYCbCrD3D9()
{
MOZ_COUNT_DTOR(DeprecatedTextureHostYCbCrD3D9);
}
void
DeprecatedTextureHostYCbCrD3D9::SetCompositor(Compositor* aCompositor)
{
mCompositor = static_cast<CompositorD3D9*>(aCompositor);
}
IntSize
DeprecatedTextureHostYCbCrD3D9::GetSize() const
{
return mSize;
}
void
DeprecatedTextureHostYCbCrD3D9::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion *aRegion,
nsIntPoint *aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TYCbCrImage);
if (!mCompositor->device()) {
return;
}
YCbCrImageDataDeserializer yuvDeserializer(aImage.get_YCbCrImage().data().get<uint8_t>(),
aImage.get_YCbCrImage().data().Size<uint8_t>());
mSize = yuvDeserializer.GetYSize();
IntSize cbCrSize = yuvDeserializer.GetCbCrSize();
mStereoMode = yuvDeserializer.GetStereoMode();
DeviceManagerD3D9* deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
RefPtr<DataTextureSource> srcY;
RefPtr<DataTextureSource> srcCb;
RefPtr<DataTextureSource> srcCr;
if (!mFirstSource) {
srcY = new DataTextureSourceD3D9(SurfaceFormat::A8, mCompositor,
TEXTURE_DISALLOW_BIGIMAGE, mStereoMode);
srcCb = new DataTextureSourceD3D9(SurfaceFormat::A8, mCompositor,
TEXTURE_DISALLOW_BIGIMAGE, mStereoMode);
srcCr = new DataTextureSourceD3D9(SurfaceFormat::A8, mCompositor,
TEXTURE_DISALLOW_BIGIMAGE, mStereoMode);
mFirstSource = srcY;
srcY->SetNextSibling(srcCb);
srcCb->SetNextSibling(srcCr);
} else {
MOZ_ASSERT(mFirstSource->GetNextSibling());
MOZ_ASSERT(mFirstSource->GetNextSibling()->GetNextSibling());
srcY = mFirstSource;
srcCb = mFirstSource->GetNextSibling()->AsDataTextureSource();
srcCr = mFirstSource->GetNextSibling()->GetNextSibling()->AsDataTextureSource();
}
RefPtr<DataSourceSurface> wrapperY =
Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetYData(),
yuvDeserializer.GetYStride(),
yuvDeserializer.GetYSize(),
SurfaceFormat::A8);
RefPtr<DataSourceSurface> wrapperCb =
Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCbData(),
yuvDeserializer.GetCbCrStride(),
yuvDeserializer.GetCbCrSize(),
SurfaceFormat::A8);
RefPtr<DataSourceSurface> wrapperCr =
Factory::CreateWrappingDataSourceSurface(yuvDeserializer.GetCrData(),
yuvDeserializer.GetCbCrStride(),
yuvDeserializer.GetCbCrSize(),
SurfaceFormat::A8);
// We don't support partial updates for YCbCr textures
NS_ASSERTION(!aRegion, "Unsupported partial updates for YCbCr textures");
if (!srcY->Update(wrapperY) ||
!srcCb->Update(wrapperCb) ||
!srcCr->Update(wrapperCr)) {
NS_WARNING("failed to update the DataTextureSource");
mSize.width = 0;
mSize.height = 0;
mFirstSource = nullptr;
return;
}
}
TemporaryRef<IDirect3DTexture9>
TextureSourceD3D9::TextureToTexture(DeviceManagerD3D9* aDeviceManager,
IDirect3DTexture9* aTexture,
@ -523,99 +270,6 @@ TextureSourceD3D9::TextureToTexture(DeviceManagerD3D9* aDeviceManager,
return texture;
}
void
DeprecatedTextureHostSystemMemD3D9::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion *aRegion,
nsIntPoint *aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorD3D9);
MOZ_ASSERT(mCompositor, "Must have compositor to update.");
if (!mCompositor->device()) {
return;
}
IDirect3DTexture9* texture =
reinterpret_cast<IDirect3DTexture9*>(aImage.get_SurfaceDescriptorD3D9().texture());
if (!texture) {
Reset();
return;
}
D3DSURFACE_DESC desc;
texture->GetLevelDesc(0, &desc);
HRESULT hr = texture->GetLevelDesc(0, &desc);
if (FAILED(hr)) {
Reset();
return;
}
mSize.width = desc.Width;
mSize.height = desc.Height;
_D3DFORMAT format = desc.Format;
uint32_t bpp = 0;
switch (format) {
case D3DFMT_X8R8G8B8:
mFormat = SurfaceFormat::B8G8R8X8;
bpp = 4;
break;
case D3DFMT_A8R8G8B8:
mFormat = SurfaceFormat::B8G8R8A8;
bpp = 4;
break;
case D3DFMT_A8:
mFormat = SurfaceFormat::A8;
bpp = 1;
break;
default:
NS_ERROR("Bad image format");
}
int32_t maxSize = mCompositor->GetMaxTextureSize();
if (mSize.width <= maxSize && mSize.height <= maxSize) {
mIsTiled = false;
mTexture = TextureToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
texture, mSize, format);
if (!mTexture) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
} else {
mIsTiled = true;
uint32_t tileCount = GetRequiredTilesD3D9(mSize.width, maxSize) *
GetRequiredTilesD3D9(mSize.height, maxSize);
mTileTextures.resize(tileCount);
for (uint32_t i = 0; i < tileCount; i++) {
IntRect tileRect = GetTileRect(i);
RECT d3dTileRect;
d3dTileRect.left = tileRect.x;
d3dTileRect.top = tileRect.y;
d3dTileRect.right = tileRect.XMost();
d3dTileRect.bottom = tileRect.YMost();
D3DLOCKED_RECT lockedRect;
texture->LockRect(0, &lockedRect, &d3dTileRect, 0);
mTileTextures[i] = DataToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
reinterpret_cast<unsigned char*>(lockedRect.pBits),
lockedRect.Pitch,
tileRect.Size(),
format,
bpp);
texture->UnlockRect(0);
if (!mTileTextures[i]) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
}
}
}
TemporaryRef<IDirect3DTexture9>
TextureSourceD3D9::SurfaceToTexture(DeviceManagerD3D9* aDeviceManager,
gfxWindowsSurface* aSurface,
@ -647,348 +301,6 @@ TextureSourceD3D9::SurfaceToTexture(DeviceManagerD3D9* aDeviceManager,
return texture;
}
void
DeprecatedTextureHostDIB::UpdateImpl(const SurfaceDescriptor& aImage,
nsIntRegion *aRegion,
nsIntPoint *aOffset)
{
MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorDIB);
MOZ_ASSERT(mCompositor, "Must have compositor to update.");
if (!mCompositor->device()) {
return;
}
// We added an extra ref for transport, so we shouldn't AddRef now.
nsRefPtr<gfxWindowsSurface> surf =
dont_AddRef(reinterpret_cast<gfxWindowsSurface*>(aImage.get_SurfaceDescriptorDIB().surface()));
mSize = ToIntSize(surf->GetSize());
uint32_t bpp = 0;
_D3DFORMAT format = D3DFMT_A8R8G8B8;
switch (gfxPlatform::GetPlatform()->OptimalFormatForContent(surf->GetContentType())) {
case gfxImageFormat::RGB24:
mFormat = SurfaceFormat::B8G8R8X8;
format = D3DFMT_X8R8G8B8;
bpp = 4;
break;
case gfxImageFormat::ARGB32:
mFormat = SurfaceFormat::B8G8R8A8;
format = D3DFMT_A8R8G8B8;
bpp = 4;
break;
case gfxImageFormat::A8:
mFormat = SurfaceFormat::A8;
format = D3DFMT_A8;
bpp = 1;
break;
default:
NS_ERROR("Bad image format");
}
int32_t maxSize = mCompositor->GetMaxTextureSize();
if (mSize.width <= maxSize && mSize.height <= maxSize) {
mTexture = SurfaceToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
surf, mSize, format);
if (!mTexture) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
mIsTiled = false;
} else {
mIsTiled = true;
uint32_t tileCount = GetRequiredTilesD3D9(mSize.width, maxSize) *
GetRequiredTilesD3D9(mSize.height, maxSize);
mTileTextures.resize(tileCount);
for (uint32_t i = 0; i < tileCount; i++) {
IntRect tileRect = GetTileRect(i);
nsRefPtr<gfxImageSurface> imgSurface = surf->GetAsImageSurface();
unsigned char* data = imgSurface->Data() +
tileRect.y * imgSurface->Stride() +
tileRect.x * bpp;
mTileTextures[i] = DataToTexture(gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager(),
data,
imgSurface->Stride(),
tileRect.Size(),
format,
bpp);
if (!mTileTextures[i]) {
NS_WARNING("Could not upload texture");
Reset();
return;
}
}
}
}
DeprecatedTextureClientD3D9::DeprecatedTextureClientD3D9(CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo)
: DeprecatedTextureClient(aCompositableForwarder, aTextureInfo)
{
MOZ_COUNT_CTOR(DeprecatedTextureClientD3D9);
}
DeprecatedTextureClientD3D9::~DeprecatedTextureClientD3D9()
{
MOZ_COUNT_DTOR(DeprecatedTextureClientD3D9);
Unlock();
mDescriptor = SurfaceDescriptor();
mDrawTarget = nullptr;
}
bool
DeprecatedTextureClientD3D9::EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType)
{
if (mTexture) {
D3DSURFACE_DESC desc;
mTexture->GetLevelDesc(0, &desc);
if (desc.Width == aSize.width &&
desc.Height == aSize.height) {
return true;
}
Unlock();
mD3D9Surface = nullptr;
mTexture = nullptr;
}
mSize = aSize;
_D3DFORMAT format = D3DFMT_A8R8G8B8;
switch (aType) {
case gfxContentType::COLOR:
format = D3DFMT_X8R8G8B8;
break;
case gfxContentType::COLOR_ALPHA:
// fallback to DIB texture client
return false;
case gfxContentType::ALPHA:
format = D3DFMT_A8;
break;
default:
NS_ERROR("Bad image type");
}
DeviceManagerD3D9* deviceManager = gfxWindowsPlatform::GetPlatform()->GetD3D9DeviceManager();
if (!deviceManager ||
!(mTexture = deviceManager->CreateTexture(aSize, format, D3DPOOL_SYSTEMMEM, nullptr))) {
NS_WARNING("Could not create texture");
return false;
}
MOZ_ASSERT(mTexture);
mDescriptor = SurfaceDescriptorD3D9(reinterpret_cast<uintptr_t>(mTexture.get()));
mContentType = aType;
return true;
}
gfxASurface*
DeprecatedTextureClientD3D9::LockSurface()
{
if (!gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) {
// If the device has failed then we should not lock the surface,
// even if we could.
Unlock();
mD3D9Surface = nullptr;
mTexture = nullptr;
return nullptr;
}
if (mSurface) {
return mSurface.get();
}
if (!mTexture) {
NS_WARNING("No texture to lock");
return nullptr;
}
if (!mD3D9Surface) {
HRESULT hr = mTexture->GetSurfaceLevel(0, getter_AddRefs(mD3D9Surface));
if (FAILED(hr)) {
NS_WARNING("Failed to get texture surface level.");
return nullptr;
}
}
mSurface = new gfxWindowsSurface(mD3D9Surface);
if (!mSurface || mSurface->CairoStatus()) {
NS_WARNING("Could not create surface for d3d9 surface");
mSurface = nullptr;
return nullptr;
}
return mSurface.get();
}
DrawTarget*
DeprecatedTextureClientD3D9::LockDrawTarget()
{
if (!mDrawTarget) {
if (gfxASurface* surface = LockSurface()) {
mDrawTarget =
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(LockSurface(), mSize);
}
}
return mDrawTarget.get();
}
void
DeprecatedTextureClientD3D9::Unlock()
{
if (mDrawTarget) {
mDrawTarget->Flush();
mDrawTarget = nullptr;
}
if (mSurface) {
mSurface = nullptr;
}
}
void
DeprecatedTextureClientD3D9::SetDescriptor(const SurfaceDescriptor& aDescriptor)
{
if (aDescriptor.type() == SurfaceDescriptor::Tnull_t) {
EnsureAllocated(mSize, mContentType);
return;
}
mDescriptor = aDescriptor;
mSurface = nullptr;
mDrawTarget = nullptr;
if (aDescriptor.type() == SurfaceDescriptor::T__None) {
return;
}
MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorD3D9);
Unlock();
mD3D9Surface = nullptr;
mTexture = reinterpret_cast<IDirect3DTexture9*>(
mDescriptor.get_SurfaceDescriptorD3D9().texture());
}
DeprecatedTextureClientDIB::DeprecatedTextureClientDIB(CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo)
: DeprecatedTextureClient(aCompositableForwarder, aTextureInfo)
{
MOZ_COUNT_CTOR(DeprecatedTextureClientDIB);
}
DeprecatedTextureClientDIB::~DeprecatedTextureClientDIB()
{
MOZ_COUNT_DTOR(DeprecatedTextureClientDIB);
Unlock();
// It is OK not to dealloc the surface descriptor because it is only a pointer
// to mSurface and we will release our strong reference to that automatically.
mDescriptor = SurfaceDescriptor();
mDrawTarget = nullptr;
}
bool
DeprecatedTextureClientDIB::EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType)
{
if (mSurface) {
gfx::IntSize size = gfx::ToIntSize(mSurface->GetSize());
if (size.width == aSize.width &&
size.height == aSize.height) {
return true;
}
Unlock();
mSurface = nullptr;
}
mSurface = new gfxWindowsSurface(gfxIntSize(aSize.width, aSize.height),
gfxPlatform::GetPlatform()->OptimalFormatForContent(aType));
if (!mSurface || mSurface->CairoStatus())
{
NS_WARNING("Could not create surface");
mSurface = nullptr;
mDescriptor = SurfaceDescriptor();
return false;
}
mSize = aSize;
mContentType = aType;
mDescriptor = SurfaceDescriptorDIB(reinterpret_cast<uintptr_t>(mSurface.get()));
return true;
}
SurfaceDescriptor*
DeprecatedTextureClientDIB::LockSurfaceDescriptor()
{
// The host will release this ref when it receives the surface descriptor.
// We AddRef in case we die before the host receives the pointer.
NS_ASSERTION(mSurface == reinterpret_cast<gfxWindowsSurface*>(mDescriptor.get_SurfaceDescriptorDIB().surface()),
"SurfaceDescriptor is not up to date");
mSurface->AddRef();
return GetDescriptor();
}
gfxASurface*
DeprecatedTextureClientDIB::LockSurface()
{
if (mSurface) {
return mSurface.get();
}
return nullptr;
}
DrawTarget*
DeprecatedTextureClientDIB::LockDrawTarget()
{
if (!mDrawTarget) {
if (gfxASurface* surface = LockSurface()) {
mDrawTarget =
gfxPlatform::GetPlatform()->CreateDrawTargetForSurface(LockSurface(), mSize);
}
}
return mDrawTarget.get();
}
void
DeprecatedTextureClientDIB::Unlock()
{
if (mDrawTarget) {
mDrawTarget->Flush();
mDrawTarget = nullptr;
}
}
void
DeprecatedTextureClientDIB::SetDescriptor(const SurfaceDescriptor& aDescriptor)
{
mDescriptor = aDescriptor;
mDrawTarget = nullptr;
if (aDescriptor.type() == SurfaceDescriptor::T__None) {
mSurface = nullptr;
return;
}
MOZ_ASSERT(aDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorDIB);
Unlock();
mSurface = reinterpret_cast<gfxWindowsSurface*>(
mDescriptor.get_SurfaceDescriptorDIB().surface());
}
class D3D9TextureClientData : public TextureClientData
{
public:

View File

@ -441,259 +441,6 @@ private:
bool mInitialized;
};
// Shared functionality for non-YCbCr texture hosts
class DeprecatedTextureHostD3D9 : public DeprecatedTextureHost
, public TextureSourceD3D9
, public TileIterator
{
public:
DeprecatedTextureHostD3D9();
virtual ~DeprecatedTextureHostD3D9();
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual TextureSourceD3D9* AsSourceD3D9() MOZ_OVERRIDE { return this; }
virtual IDirect3DTexture9 *GetD3D9Texture() MOZ_OVERRIDE {
return mIsTiled ? mTileTextures[mCurrentTile].get()
: TextureSourceD3D9::GetD3D9Texture();
}
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual LayerRenderState GetRenderState() { return LayerRenderState(); }
virtual bool Lock() MOZ_OVERRIDE { return true; }
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // TODO: cf bug 872568
}
virtual void BeginTileIteration() MOZ_OVERRIDE
{
mIterating = true;
mCurrentTile = 0;
}
virtual void EndTileIteration() MOZ_OVERRIDE
{
mIterating = false;
}
virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
virtual size_t GetTileCount() MOZ_OVERRIDE { return mTileTextures.size(); }
virtual bool NextTile() MOZ_OVERRIDE
{
return (++mCurrentTile < mTileTextures.size());
}
virtual TileIterator* AsTileIterator() MOZ_OVERRIDE
{
return mIsTiled ? this : nullptr;
}
virtual void ReleaseTextureResources() MOZ_OVERRIDE
{
TextureSourceD3D9::ReleaseTextureResources();
if (mIsTiled) {
mTileTextures.clear();
}
}
protected:
gfx::IntRect GetTileRect(uint32_t aID) const;
void Reset();
RefPtr<CompositorD3D9> mCompositor;
bool mIsTiled;
std::vector< RefPtr<IDirect3DTexture9> > mTileTextures;
uint32_t mCurrentTile;
bool mIterating;
};
class DeprecatedTextureHostShmemD3D9 : public DeprecatedTextureHostD3D9
{
public:
virtual const char* Name() { return "DeprecatedTextureHostShmemD3D9"; }
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint *aOffset = nullptr) MOZ_OVERRIDE;
};
class DeprecatedTextureHostSystemMemD3D9 : public DeprecatedTextureHostD3D9
{
public:
virtual const char* Name() { return "DeprecatedTextureHostSystemMemD3D9"; }
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint *aOffset = nullptr) MOZ_OVERRIDE;
};
class DeprecatedTextureHostYCbCrD3D9 : public DeprecatedTextureHost
, public TextureSourceD3D9
{
public:
DeprecatedTextureHostYCbCrD3D9();
virtual ~DeprecatedTextureHostYCbCrD3D9();
virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE;
virtual gfx::IntSize GetSize() const MOZ_OVERRIDE;
virtual TextureSourceD3D9* AsSourceD3D9() MOZ_OVERRIDE
{
return mFirstSource->AsSourceD3D9();
}
virtual TextureSource* GetSubSource(int index) MOZ_OVERRIDE
{
return mFirstSource ? mFirstSource->GetSubSource(index) : nullptr;
}
virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE
{
return nullptr; // TODO: cf bug 872568
}
virtual const char* Name() MOZ_OVERRIDE
{
return "DeprecatedTextureHostYCbCrD3D9";
}
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint* aOffset = nullptr) MOZ_OVERRIDE;
private:
gfx::IntSize mSize;
RefPtr<DataTextureSource> mFirstSource;
RefPtr<CompositorD3D9> mCompositor;
};
class DeprecatedTextureHostDIB : public DeprecatedTextureHostD3D9
{
public:
virtual const char* Name() { return "DeprecatedTextureHostDIB"; }
virtual void SetBuffer(SurfaceDescriptor* aBuffer, ISurfaceAllocator* aAllocator) MOZ_OVERRIDE
{
MOZ_ASSERT(aBuffer->type() == SurfaceDescriptor::TSurfaceDescriptorDIB);
// We are responsible for keeping the surface alive. But the client will have AddRefed it
// for transport to the host. So we don't need to AddRef here.
mSurface = dont_AddRef(reinterpret_cast<gfxWindowsSurface*>(aBuffer->get_SurfaceDescriptorDIB().surface()));
DeprecatedTextureHost::SetBuffer(aBuffer, aAllocator);
}
virtual SurfaceDescriptor* LockSurfaceDescriptor() const MOZ_OVERRIDE
{
NS_ASSERTION(!mBuffer ||
(mBuffer->type() == SurfaceDescriptor::TSurfaceDescriptorDIB &&
mSurface == reinterpret_cast<gfxWindowsSurface*>(mBuffer->get_SurfaceDescriptorDIB().surface())),
"SurfaceDescriptor is not up to date");
// We are either going to pass the surface descriptor to the content thread
// or we are going to give the our surface descriptor to a compositable host,
// pretending that it is from the client thread. In either case it is going to
// get released, so we need to AddRef here.
if (mBuffer) {
mSurface->AddRef();
}
return DeprecatedTextureHost::LockSurfaceDescriptor();
}
protected:
virtual void UpdateImpl(const SurfaceDescriptor& aSurface,
nsIntRegion* aRegion,
nsIntPoint *aOffset = nullptr) MOZ_OVERRIDE;
// Used to keep the surface alive if the host has responsibility for the
// lifetime of the surface.
nsRefPtr<gfxWindowsSurface> mSurface;
};
// If we want to use d3d9 textures for transport, use this class.
// If we are using shmem, then use DeprecatedTextureClientShmem with DeprecatedTextureHostShmemD3D9
// Since we pass a raw pointer, you should not use this texture client for
// multi-process compositing.
class DeprecatedTextureClientD3D9 : public DeprecatedTextureClient
{
public:
DeprecatedTextureClientD3D9(CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo);
virtual ~DeprecatedTextureClientD3D9();
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE
{
return aType == TEXTURE_CONTENT;
}
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType) MOZ_OVERRIDE;
virtual gfxASurface* LockSurface() MOZ_OVERRIDE;
virtual gfx::DrawTarget* LockDrawTarget() MOZ_OVERRIDE;
virtual gfx::BackendType BackendType() MOZ_OVERRIDE
{
return gfx::BackendType::CAIRO;
}
virtual void Unlock() MOZ_OVERRIDE;
virtual void SetDescriptor(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
virtual gfxContentType GetContentType() MOZ_OVERRIDE
{
return mContentType;
}
private:
RefPtr<IDirect3DTexture9> mTexture;
nsRefPtr<gfxASurface> mSurface;
nsRefPtr<IDirect3DSurface9> mD3D9Surface;
RefPtr<gfx::DrawTarget> mDrawTarget;
gfx::IntSize mSize;
gfxContentType mContentType;
};
// Retains a DIB and uses it for transport.
// Used where we can't efficently use a gfxWindowsSurface wrapped around
// a DC from a IDirect3DSurface9, which is for surfaces with alpha.
class DeprecatedTextureClientDIB : public DeprecatedTextureClient
{
public:
DeprecatedTextureClientDIB(CompositableForwarder* aCompositableForwarder,
const TextureInfo& aTextureInfo);
virtual ~DeprecatedTextureClientDIB();
virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE
{
return aType == TEXTURE_CONTENT;
}
virtual bool EnsureAllocated(gfx::IntSize aSize,
gfxContentType aType) MOZ_OVERRIDE;
virtual gfxASurface* LockSurface() MOZ_OVERRIDE;
virtual gfx::DrawTarget* LockDrawTarget() MOZ_OVERRIDE;
virtual gfx::BackendType BackendType() MOZ_OVERRIDE
{
return gfx::BackendType::CAIRO;
}
virtual void Unlock() MOZ_OVERRIDE;
virtual SurfaceDescriptor* LockSurfaceDescriptor() MOZ_OVERRIDE;
virtual void SetDescriptor(const SurfaceDescriptor& aDescriptor) MOZ_OVERRIDE;
virtual gfxContentType GetContentType() MOZ_OVERRIDE
{
return mContentType;
}
private:
nsRefPtr<gfxWindowsSurface> mSurface;
RefPtr<gfx::DrawTarget> mDrawTarget;
gfx::IntSize mSize;
gfxContentType mContentType;
};
}
}