Backed out changeset 9320c843aa7e (bug 1247775) for breaking win 8 reftests

This commit is contained in:
Carsten "Tomcat" Book 2016-02-12 08:49:50 +01:00
Родитель eebf5d68a5
Коммит 01b9f62513
3 изменённых файлов: 309 добавлений и 2 удалений

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

@ -73,7 +73,7 @@ ContentClient::CreateContentClient(CompositableForwarder* aForwarder)
#ifdef XP_WIN
if (backend == LayersBackend::LAYERS_D3D11) {
useDoubleBuffering = gfxWindowsPlatform::GetPlatform()->GetRenderMode() == gfxWindowsPlatform::RENDER_DIRECT2D;
useDoubleBuffering = !!gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
} else
#endif
#ifdef MOZ_WIDGET_GTK

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

@ -253,6 +253,31 @@ D3D11TextureData::~D3D11TextureData()
#endif
}
D3D10TextureData::D3D10TextureData(ID3D10Texture2D* aTexture,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
bool aNeedsClear, bool aNeedsClearWhite,
bool aIsForOutOfBandContent)
: DXGITextureData(aSize, aFormat, aNeedsClear, aNeedsClearWhite, aIsForOutOfBandContent)
, mTexture(aTexture)
{
MOZ_ASSERT(aTexture);
mHasSynchronization = HasKeyedMutex(aTexture);
}
D3D10TextureData::~D3D10TextureData()
{
#ifdef DEBUG
// 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.
if (mDrawTarget) {
Lock(OpenMode::OPEN_NONE, nullptr);
mDrawTarget = nullptr;
Unlock();
}
#endif
}
bool
D3D11TextureData::Lock(OpenMode aMode, FenceHandle*)
{
@ -270,6 +295,23 @@ D3D11TextureData::Lock(OpenMode aMode, FenceHandle*)
return true;
}
bool
D3D10TextureData::Lock(OpenMode aMode, FenceHandle*)
{
if (!LockD3DTexture(mTexture.get())) {
return false;
}
if (NS_IsMainThread() && !mIsForOutOfBandContent) {
if (!PrepareDrawTargetInLock(aMode)) {
Unlock();
return false;
}
}
return true;
}
bool
DXGITextureData::PrepareDrawTargetInLock(OpenMode aMode)
{
@ -300,6 +342,12 @@ D3D11TextureData::Unlock()
UnlockD3DTexture(mTexture.get());
}
void
D3D10TextureData::Unlock()
{
UnlockD3DTexture(mTexture.get());
}
void
D3D11TextureData::SyncWithObject(SyncObject* aSyncObject)
{
@ -313,6 +361,19 @@ D3D11TextureData::SyncWithObject(SyncObject* aSyncObject)
sync->RegisterTexture(mTexture);
}
void
D3D10TextureData::SyncWithObject(SyncObject* aSyncObject)
{
if (!aSyncObject || !NS_IsMainThread()) {
// When off the main thread we sync using a keyed mutex per texture.
return;
}
MOZ_ASSERT(aSyncObject->GetSyncType() == SyncObject::SyncType::D3D11);
SyncObjectD3D11* sync = static_cast<SyncObjectD3D11*>(aSyncObject);
sync->RegisterTexture(mTexture);
}
bool
DXGITextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
{
@ -332,6 +393,34 @@ DXGITextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
return true;
}
bool
D3D10TextureData::ReadBack(TextureReadbackSink* aReadbackSinc)
{
if (NS_IsMainThread() && aReadbackSinc && mTexture) {
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
D3D10_TEXTURE2D_DESC desc;
mTexture->GetDesc(&desc);
desc.BindFlags = 0;
desc.Usage = D3D10_USAGE_STAGING;
desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
desc.MiscFlags = 0;
RefPtr<ID3D10Texture2D> tex;
HRESULT hr = device->CreateTexture2D(&desc, nullptr, getter_AddRefs(tex));
if (SUCCEEDED(hr)) {
device->CopyResource(tex, mTexture);
gfxWindowsPlatform::GetPlatform()->GetReadbackManager()->PostTask(tex, aReadbackSinc);
} else {
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(mSize))) << "[D3D11] CreateTexture2D failure " << mSize << " Code: " << gfx::hexa(hr);
aReadbackSinc->ProcessReadback(nullptr);
}
}
return true;
}
DXGITextureData*
DXGITextureData::Create(IntSize aSize, SurfaceFormat aFormat, TextureAllocationFlags aFlags)
{
@ -340,7 +429,19 @@ DXGITextureData::Create(IntSize aSize, SurfaceFormat aFormat, TextureAllocationF
return nullptr;
}
return D3D11TextureData::Create(aSize, aFormat, aFlags);
gfxWindowsPlatform* windowsPlatform = gfxWindowsPlatform::GetPlatform();
// When we're not on the main thread we're not going to be using Direct2D
// to access the contents of this texture client so we will always use D3D11.
bool useD3D11 =
windowsPlatform->GetContentBackendFor(LayersBackend::LAYERS_D3D11) == BackendType::DIRECT2D1_1 ||
!NS_IsMainThread() ||
(aFlags & ALLOC_FOR_OUT_OF_BAND_CONTENT);
if (useD3D11) {
return D3D11TextureData::Create(aSize, aFormat, aFlags);
} else {
return D3D10TextureData::Create(aSize, aFormat, aFlags);
}
}
DXGITextureData*
@ -406,12 +507,59 @@ D3D11TextureData::CreateSimilar(ISurfaceAllocator* aAllocator,
return D3D11TextureData::Create(mSize, mFormat, aAllocFlags);
}
DXGITextureData*
D3D10TextureData::Create(IntSize aSize, SurfaceFormat aFormat, TextureAllocationFlags aFlags)
{
RefPtr<ID3D10Texture2D> texture10;
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;
HRESULT hr = device->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(texture10));
if (FAILED(hr)) {
gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(aSize)))
<< "[D3D10] 2 CreateTexture2D failure " << aSize << " Code: " << gfx::hexa(hr);
return nullptr;
}
texture10->SetPrivateDataInterface(sD3D11TextureUsage,
new TextureMemoryMeasurer(newDesc.Width * newDesc.Height * 4));
return new D3D10TextureData(texture10, aSize, aFormat,
aFlags & ALLOC_CLEAR_BUFFER,
aFlags & ALLOC_CLEAR_BUFFER_WHITE,
false /* aIsForOutOfBandContent */);
}
void
D3D10TextureData::Deallocate(ISurfaceAllocator* aAllocator)
{
mTexture = nullptr;
}
TextureData*
D3D10TextureData::CreateSimilar(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const
{
return D3D10TextureData::Create(mSize, mFormat, aAllocFlags);
}
void
D3D11TextureData::GetDXGIResource(IDXGIResource** aOutResource)
{
mTexture->QueryInterface(aOutResource);
}
void
D3D10TextureData::GetDXGIResource(IDXGIResource** aOutResource)
{
mTexture->QueryInterface(aOutResource);
}
DXGIYCbCrTextureData*
DXGIYCbCrTextureData::Create(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
@ -560,6 +708,23 @@ D3D11TextureData::BorrowDrawTarget()
return result.forget();
}
already_AddRefed<DrawTarget>
D3D10TextureData::BorrowDrawTarget()
{
MOZ_ASSERT(NS_IsMainThread());
if (!mDrawTarget && mTexture) {
// This may return a null DrawTarget
mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat);
if (!mDrawTarget) {
gfxCriticalNote << "Could not borrow DrawTarget (D3D10) " << (int)mFormat;
}
}
RefPtr<DrawTarget> result = mDrawTarget;
return result.forget();
}
bool
D3D11TextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
@ -593,6 +758,39 @@ D3D11TextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
return true;
}
bool
D3D10TextureData::UpdateFromSurface(gfx::SourceSurface* aSurface)
{
RefPtr<DataSourceSurface> srcSurf = aSurface->GetDataSurface();
if (!srcSurf) {
gfxCriticalError() << "Failed to GetDataSurface in UpdateFromSurface (D3D10).";
return false;
}
DataSourceSurface::MappedSurface sourceMap;
if (!srcSurf->Map(DataSourceSurface::READ, &sourceMap)) {
gfxCriticalError() << "Failed to map source surface for UpdateFromSurface (D3D10).";
return false;
}
RefPtr<ID3D10Device> device;
mTexture->GetDevice(getter_AddRefs(device));
D3D10_BOX box;
box.front = 0;
box.back = 1;
box.top = box.left = 0;
box.right = aSurface->GetSize().width;
box.bottom = aSurface->GetSize().height;
device->UpdateSubresource(mTexture, 0, &box, sourceMap.mData, sourceMap.mStride, 0);
srcSurf->Unmap();
return true;
}
DXGITextureHostD3D11::DXGITextureHostD3D11(TextureFlags aFlags,
const SurfaceDescriptorD3D10& aDescriptor)
: TextureHost(aFlags)
@ -1029,11 +1227,47 @@ SyncObjectD3D11::RegisterTexture(ID3D11Texture2D* aTexture)
mD3D11SyncedTextures.push_back(aTexture);
}
void
SyncObjectD3D11::RegisterTexture(ID3D10Texture2D* aTexture)
{
mD3D10SyncedTextures.push_back(aTexture);
}
void
SyncObjectD3D11::FinalizeFrame()
{
HRESULT hr;
if (!mD3D10Texture && mD3D10SyncedTextures.size()) {
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
if (!device) {
return;
}
hr = device->OpenSharedResource(mHandle, __uuidof(ID3D10Texture2D), (void**)(ID3D10Texture2D**)getter_AddRefs(mD3D10Texture));
if (FAILED(hr) || !mD3D10Texture) {
gfxCriticalError() << "Failed to D3D10 OpenSharedResource for frame finalization: " << hexa(hr);
if (gfxWindowsPlatform::GetPlatform()->DidRenderingDeviceReset()) {
return;
}
gfxDevCrash(LogReason::D3D10FinalizeFrame) << "Without device reset: " << hexa(hr);
}
// test QI
RefPtr<IDXGIKeyedMutex> mutex;
hr = mD3D10Texture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
if (FAILED(hr) || !mutex) {
// Leave both the critical error and MOZ_CRASH for now; the critical error lets
// us "save" the hr value. We will probably eventuall replace this with gfxDevCrash.
gfxCriticalError() << "Failed to get KeyedMutex (1): " << hexa(hr);
MOZ_CRASH("GFX: Cannot get D3D10 KeyedMutex");
}
}
if (!mD3D11Texture && mD3D11SyncedTextures.size()) {
ID3D11Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D11ContentDevice();
@ -1061,6 +1295,37 @@ SyncObjectD3D11::FinalizeFrame()
}
}
if (mD3D10SyncedTextures.size()) {
RefPtr<IDXGIKeyedMutex> mutex;
hr = mD3D10Texture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
hr = mutex->AcquireSync(0, 20000);
if (hr == WAIT_TIMEOUT) {
if (gfxWindowsPlatform::GetPlatform()->DidRenderingDeviceReset()) {
gfxWarning() << "AcquireSync timed out because of device reset.";
return;
}
gfxDevCrash(LogReason::D3D10SyncLock) << "Timeout on the D3D10 sync lock";
}
D3D10_BOX box;
box.front = box.top = box.left = 0;
box.back = box.bottom = box.right = 1;
ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
if (!device) {
return;
}
for (auto iter = mD3D10SyncedTextures.begin(); iter != mD3D10SyncedTextures.end(); iter++) {
device->CopySubresourceRegion(mD3D10Texture, 0, 0, 0, 0, *iter, 0, &box);
}
mutex->ReleaseSync(0);
mD3D10SyncedTextures.clear();
}
if (mD3D11SyncedTextures.size()) {
RefPtr<IDXGIKeyedMutex> mutex;
hr = mD3D11Texture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));

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

@ -109,6 +109,45 @@ CreateD3D11extureClientWithDevice(gfx::IntSize aSize, gfx::SurfaceFormat aFormat
ID3D11Device* aDevice,
ISurfaceAllocator* aAllocator);
class D3D10TextureData : public DXGITextureData
{
public:
static DXGITextureData*
Create(gfx::IntSize aSize, gfx::SurfaceFormat aFormat, TextureAllocationFlags aFlags);
virtual bool Lock(OpenMode aMode, FenceHandle*) override;
virtual void Unlock() override;
virtual bool UpdateFromSurface(gfx::SourceSurface* aSurface) override;
virtual already_AddRefed<gfx::DrawTarget> BorrowDrawTarget() override;
virtual TextureData*
CreateSimilar(ISurfaceAllocator* aAllocator,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags) const override;
// TODO - merge this with the FenceHandle API!
virtual void SyncWithObject(SyncObject* aSync) override;
virtual bool ReadBack(TextureReadbackSink* aReadbackSinc) override;
virtual void Deallocate(ISurfaceAllocator* aAllocator) override;
~D3D10TextureData();
protected:
D3D10TextureData(ID3D10Texture2D* aTexture,
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
bool aNeedsClear, bool aNeedsClearWhite,
bool aIsForOutOfBandContent);
virtual void GetDXGIResource(IDXGIResource** aOutResource) override;
RefPtr<ID3D10Texture2D> mTexture;
};
class DXGIYCbCrTextureData : public TextureData
{
public:
@ -392,9 +431,12 @@ public:
virtual SyncType GetSyncType() { return SyncType::D3D11; }
void RegisterTexture(ID3D11Texture2D* aTexture);
void RegisterTexture(ID3D10Texture2D* aTexture);
private:
RefPtr<ID3D11Texture2D> mD3D11Texture;
RefPtr<ID3D10Texture2D> mD3D10Texture;
std::vector<ID3D10Texture2D*> mD3D10SyncedTextures;
std::vector<ID3D11Texture2D*> mD3D11SyncedTextures;
SyncHandle mHandle;
};