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, aType == GFX_CONTENT_COLOR_ALPHA); mContentType = aType; return true; }
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(); device->OpenSharedResource((HANDLE)aDescriptor.get_SurfaceDescriptorD3D10().handle(), __uuidof(ID3D10Texture2D), (void**)(ID3D10Texture2D**)byRef(mTexture)); }
DeprecatedTextureClientD3D11::~DeprecatedTextureClientD3D11() { mDescriptor = SurfaceDescriptor(); ClearDT(); }